73 lines
2.9 KiB
PHP
73 lines
2.9 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");
|
|
$site = xml_text(site_url());
|
|
|
|
|
|
// Set up a RSS "header"
|
|
$query = "SELECT MAX(`date`) FROM $table;";
|
|
$result = $db->query($query) or db_fail();
|
|
$most_recent = $result->fetch_row();
|
|
$now = date("D, d M Y H:i:s O");
|
|
// The date of the newest story, or now if there is none
|
|
$last_date = $most_recent[0] ? date("D, d M Y H:i:s O", strtotime($most_recent[0])) : $now;
|
|
|
|
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>'.$site.'/</link>'."\n";
|
|
echo '<description>Most recent articles from '.xml_text(site_host()).'</description>'."\n";
|
|
echo '<language>en-za</language>'."\n";
|
|
echo '<pubDate>'.$now.'</pubDate>'."\n";
|
|
echo '<lastBuildDate>'.$last_date.'</lastBuildDate>'."\n";
|
|
echo '<managingEditor>'.hidden_email(site_email('editor')).' (Editors)</managingEditor>'."\n";
|
|
echo '<webMaster>'.hidden_email(site_email('webmaster')).' (Webmasters)</webMaster>'."\n";
|
|
echo '<atom:link href="'.$site.'/feed" rel="self" type="application/rss+xml" />'."\n";
|
|
echo '<item>'."\n";
|
|
echo '<title>Front Page</title>'."\n";
|
|
echo '<link>'.$site.'/</link>'."\n";
|
|
echo '<pubDate>'.$last_date.'</pubDate>'."\n";
|
|
echo '<guid>'.$site.'/</guid>'."\n";
|
|
echo '</item>'."\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 '<item>'."\n";
|
|
echo '<title>'.xml_text($entry['title']).'</title>'."\n";
|
|
echo '<link>'.$site.'/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>'.$site.'/article?id='.$id.'</guid>'."\n";
|
|
echo '</item>'."\n";
|
|
}
|
|
|
|
echo '</channel>'."\n";
|
|
echo '</rss>'."\n";
|
|
open_db('close');
|