Hi, i'm making an rss feed at work and am having a few issues with certain validators....
In one validator the feed is showing up as fine, the in another i'm getting this error..
Reference to undefined entity 'eacute'.
Line: 428 Character: 268”
I've attached the PHP code that outputs the RSS feed, i've been told that i need to make sure ALL HTML entities must be referenced as their numeric values.
Could one of you PHP guys take a look and tell me what i need to change/tweak.
Thanks,
Andrew
PHP:
<?php
$DO_BROWSER_SNIFF = false;
$STATIC_PAGE = false;
function htmlentities_to_utf8($text) {
$utf8_entities = array();
$html_entities = array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
$entities_decoded = array_keys(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
for ($x = 0; $x < sizeof($entities_decoded); $x++) {
$utf8_entities[$x] = '&#' . ord($entities_decoded[$x]) . ';';
}
return str_replace($html_entities, $utf8_entities, $text);
}
function fix_rss($text) {
/* $text = str_replace('£', '£', $text); //ffs */
$text = htmlentities($text);
$text = str_replace('£', '£', $text); //ffs
$text = str_replace('"', '"', $text); //ffs
$text = str_replace('ö', 'ö', $text); //ffs
$text = str_replace('<', '<', $text);
$text = str_replace('>', '>', $text);
# $text = htmlentities_to_utf8($text);
return $text;
}
$WHITESPACE_STRIP = false;
$COMMENTS_STRIP = false;
$DEBUG = false; // Stop debugging info breaking the XML
start_cp('Startup');
start(); init_skin(); $db = init_db();
end_cp();
$SKIN_PATH = '/data/sites/htdocs/rss/';
$tpl = make_template('blah.xml');
$type = $_GET['type'] + 0;
$filter = $_GET['filter'] + 0;
$limit = $_GET['limit'] + 0;
$priority = $_GET['priority'] + 0;
$target = trim($_GET['target']);
$href_self = "url";
if ($target != 'blah') {
die("Invalid target");
}
// Feed codes for HBX
$filter_check = '1';
$add_format = '';
$exclude_filter = str_replace('*', 'exclude_from', make_exclude_filter());
$include_filter = str_replace('*', 'blah', make_include_filter());
$site_name_rss = $CONFIG['site_name_rss'];
$feed_name = 'News';
$feed_title = "{$site_name_rss} - {$add_format}News";
$feed_link = 'https://www.site.com/news.php' . "?cid=OTC-RSS&attr=site-feed-RSS";
$feed_desc = "All the latest {$add_format} {$site_name_rss}";
$active_check = str_replace('*.', '', make_active_check('article'));
$ret = db_query("SELECT /*** Feeds ***/
*,
UNIX_TIMESTAMP(valid_from) AS item_date
FROM
portal.A_articles
WHERE
$type_check AND
valid_from > DATE_SUB(NOW(), INTERVAL 90 DAY) AND
$filter_check AND
$priority_check AND
on_listings = 'yes' AND
$active_check AND
$exclude_filter AND
$include_filter
ORDER BY
running_order DESC
LIMIT
$limit");
if (! $ret->numRows()) {
dlog('Found no suitable articles');
} else {
while ($row = $ret->fetchRow()) {
$aid = $row['id'] + 0;
$link = "https://www.site.com/article.php?id=$aid" . "?cid=OTC-RSS&attr=site-blah-RSS";
$pics = 0;
$ret_pic = db_query("SELECT id FROM portal.A_screenshots WHERE R_article_id = $aid ORDER BY running_order_article ASC, id ASC");
portal.A_screenshots.R_article_id = portal.A_articles.id ORDER BY running_order_product DESC LIMIT 1");
while ($row_pic = $ret_pic->fetchRow()) {
$pid = $row_pic['id'] + 0;
$pics ++;
$pic = "https://medialib.com/screens/screenshot_{$pid}_thumb93.jpg";
$pic_file = "/data/sites/htdocs/medialib/screens/screenshot_{$pid}_thumb93.jpg";
if ($pics == 1) {
$tpl->setCurrentBlock('item.enclosure');
$tpl->setVariable(array(
'item.enclosure.url' => $pic,
'item.enclosure.length' => @filesize($pic_file) + 0,
));
$tpl->parseCurrentBlock();
}
$tpl->setCurrentBlock('item.image');
$tpl->setVariable(array(
'item.image.src' => $pic,
'item.image.link' => $link,
));
$tpl->parseCurrentBlock();
}
if ($pics > 0) {
$tpl->touchBlock('item.images');
}
$headline = trim($row['R_headline']);
$subhead = trim($row['subheadline']);
$description = trim($row['intro_text'] . $row['body_copy']);
if ($subhead) {
if (substr($subhead, -1) != '.') {
$subhead .= '.';
}
$description = '' . $subhead . "<br />\n\n" . $description;
}
switch ($row['R_article_type']) {
case 1:
$category = 'News';
break;
}
$description = preg_replace("/(<!--([^-]*([^-]|-([^-]|-[^>])))*-->)/", '', $description);
$description = nl2br($description); # Covert line breaks to <br />
$tpl->setCurrentBlock('item');
$tpl->setVariable(array(
'item.title' => fix_rss($headline),
'item.description' => fix_rss($description),
'item.link' => $link,
'item.guid' => $link,
'item.category' => fix_rss($category),
'item.date' => str_replace(' ', ' ', date('r', $row['item_date'])),
));
$tpl->parseCurrentBlock();
}
}
header('Content-type: text/xml; charset="utf-8"');
$tpl->setVariable(array(
'rss_href_self' => $href_self,
'rss_title' => fix_rss($feed_title),
'rss_link' => $feed_link,
'rss_description' => fix_rss($feed_desc),
'rss_language' => 'en-gn',
'rss_date' => str_replace(' ', ' ', date('r')),
));
start_cp('Cleanup');
$pagecode = $tpl->get(); finish(); end_cp();
// Super paranoid replacments to make sure NO entities get through
$pagecode = str_replace('£', '£', $pagecode);
$pagecode = str_replace('"', '"', $pagecode);
$pagecode = str_replace('ö', 'ö', $pagecode);
$pagecode = str_replace('<b>', '<strong>', $pagecode);
$pagecode = str_replace('</b>', '</strong>', $pagecode);
$pagecode = draw_debug_info($pagecode); output_page($pagecode);
##########################################################
?> |