Files
xxx/feed.php
T

69 lines
3.0 KiB
PHP

<?php
require_once('./open_db.lib.php');
open_db('open');
require_once('./get_data.lib.php');
include_once('./lib/convert_entities.inc.php');
if (!isset($num_stories) || !is_numeric($num_stories)) $num_stories = 10;
$start = get_start_num();
$show = get_show_num();
$table = "xxx";
header("Content-Type: application/rss+xml");
// Set up a RSS "header"
$query = "SELECT MAX(`date`) FROM $table;";
$result = $db->query($query) or die("Query failed : ".$db->error);
$most_recent = $result->fetch_row();
$now = date("D, d M Y H:i:s O");
echo '<?xml version="1.0"?>'."\n";
echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
echo '<channel>'."\n";
echo '<title>x.x.x</title>'."\n";
echo '<link>http://xxx.org.za/</link>'."\n";
echo '<description>Most recent articles from xxx.org.za</description>'."\n";
echo '<language>en-za</language>'."\n";
echo '<pubDate>'.$now.'</pubDate>'."\n";
echo '<lastBuildDate>'.date("D, d M Y H:i:s O", strtotime($most_recent[0])).'</lastBuildDate>'."\n";
echo '<managingEditor>&#101;&#100;&#105;&#116;&#111;&#114;&#64;&#120;&#120;&#120;&#46;&#111;&#114;&#103;&#46;&#122;&#97; (Editors)</managingEditor>'."\n";
echo '<webMaster>&#119;&#101;&#98;&#109;&#97;&#115;&#116;&#101;&#114;&#64;&#120;&#120;&#120;&#46;&#111;&#114;&#103;&#46;&#122;&#97; (Webmasters)</webMaster>'."\n";
echo '<atom:link href="http://xxx.org.za/feed" rel="self" type="application/rss+xml" />'."\n";
echo '<item>'."\n";
echo '<title>Front Page</title>'."\n";
echo '<link>http://xxx.org.za/</link>'."\n";
echo '<pubDate>'.date("D, d M Y H:i:s O", strtotime($most_recent[0])).'</pubDate>'."\n";
echo '<guid>http://xxx.org.za/</guid>'."\n";
echo '</item>'."\n";
/*
* Text for an XML element: decode any HTML entities (&hellip; 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 '<item>'."\n";
echo '<title>'.xml_text($entry['title']).'</title>'."\n";
echo '<link>http://xxx.org.za/article?id='.$id.'</link>'."\n";
echo '<pubDate>'.date("D, d M Y H:i:s O", strtotime($entry['date'])).'</pubDate>'."\n";
if ($entry['img'])
echo '<description>Image: '.xml_text($entry['title']).'</description>'."\n";
else
echo '<description>'.xml_text(strip_tags($entry['story'])).'</description>'."\n";
echo '<dc:creator>'.xml_text($entry['author']).'</dc:creator>'."\n";
echo '<guid>http://xxx.org.za/article?id='.$id.'</guid>'."\n";
echo '</item>'."\n";
}
echo '</channel>'."\n";
echo '</rss>'."\n";
open_db('close');