diff --git a/feed.php b/feed.php index 40697b6..a2d51b9 100644 --- a/feed.php +++ b/feed.php @@ -36,19 +36,30 @@ echo 'http://xxx.org.za/'."\n"; echo ''."\n"; +/* + * Text for an XML element: decode any HTML entities (… is not an + * XML entity), drop characters XML does not allow, then escape. + */ +function xml_text($string) { + $string = mb_scrub(html_entity_decode_full((string)$string), 'UTF-8'); + $string = preg_replace('/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', '', $string); + return htmlspecialchars((string)$string, ENT_XML1 | ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); +} + $result = get_query(); foreach ($result as $entry) { + $id = (int)$entry['id']; echo ''."\n"; - echo ''.$entry['title'].''."\n"; - echo 'http://xxx.org.za/article?id='.$entry['id'].''."\n"; + echo ''.xml_text($entry['title']).''."\n"; + echo 'http://xxx.org.za/article?id='.$id.''."\n"; echo ''.date("D, d M Y H:i:s O", strtotime($entry['date'])).''."\n"; if ($entry['img']) - echo 'Image: '.$entry['title'].''."\n"; + echo 'Image: '.xml_text($entry['title']).''."\n"; else - echo ''.strip_tags(html_entity_decode_full($entry['story'])).''."\n"; - echo ''.$entry['author'].''."\n"; - echo 'http://xxx.org.za/article?id='.$entry['id'].''."\n"; + echo ''.xml_text(strip_tags($entry['story'])).''."\n"; + echo ''.xml_text($entry['author']).''."\n"; + echo 'http://xxx.org.za/article?id='.$id.''."\n"; echo ''."\n"; }