<?php
// Make us a RSS feed

header("Content-Type: application/xml");

// Connect to our MySQL database

@mysql_select_db("web01540", @mysql_connect("db.nederhost.nl", "web01540", "vQyUAwd"));

// General info about the feed
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>GothicInfo.net Newsfeed</title>
    <link>http://www.gothicinfo.net/site</link>
    <description>Daily news on the international gothic scene.</description>
    <language>en-gb</language>
';
// Get the date for the last update, and continue parsing
$update = mysql_fetch_assoc(mysql_query("SELECT time FROM news WHERE type != 'editorial' ORDER BY time DESC LIMIT 1"));
echo '
	<pubDate>' . date("r", $update['time']) . '</pubDate>
    <lastBuildDate>' . date("r", $update['time']) . '</lastBuildDate>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<copyright>Copyright ' . date("Y") . ', GothicInfo.net</copyright>
	<managingEditor>jurjen@gothicinfo.net (Jurjen)</managingEditor>
    <webMaster>jurjen@gothicinfo.net (Jurjen)</webMaster>
	<!-- <image> tag to be entered here -->
';
// Get the news items to be shown in the feed
$newsOverview = @mysql_query("SELECT id, time, headline, SUBSTRING_INDEX(message, ' ', 50) AS summary, type, discussion FROM news WHERE accept = '1' AND type != 'editorial' ORDER BY time DESC LIMIT 15");

function xmlentities($string, $quote_style=ENT_QUOTES)
{
   static $trans;
   if (!isset($trans)) {
       $trans = get_html_translation_table(HTML_ENTITIES, $quote_style);
       foreach ($trans as $key => $value)
           $trans[$key] = '&#'.ord($key).';';
       // dont translate the '&' in case it is part of &xxx;
       $trans[chr(38)] = '&';
   }
   // after the initial translation, _do_ map standalone '&' into '&#38;'
   return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/","&#38;" , strtr($string, $trans));
}
function cusq($text) {
	
       $badwordchars=array(
                           chr(145),
                           chr(146),
                           chr(147),
                           chr(148),
                           chr(151)
                           );
       $fixedwordchars=array(
                           "'",
                           "'",
                           '&quot;',
                           '&quot;',
                           '&mdash;'
                           );
       return str_replace($badwordchars,$fixedwordchars,$text);

   }

// 'Feed' the news items

while ($src = @mysql_fetch_assoc($newsOverview)) {
$size = getimagesize("http://www.gothicinfo.net/images/news/index.php?id=" . $src['id']);
echo '
<item>
<title>' . xmlentities($src['headline']) . '</title>
<link>http://www.gothicinfo.net/site/news/' . $src['id'] . '</link>
<description>' . xmlentities(cusq($src['summary'])) . '</description>
<comments>http://www.gothicinfo.net/undergothicwings/index.php/topic,' . $src['discussion'] . '.0.html</comments>
<guid>http://www.gothicinfo.net/site/news/' . $src['id'] . '</guid>
<pubDate>' . date("r", $src['time']) . '</pubDate>
<source url="http://www.gothicinfo.net/rss/news.xml">GothicInfo.net</source>
<enclosure url="http://www.gothicinfo.net/images/news/index.php?id=' . $src['id'] . '" length="' . strlen(file_get_contents("http://www.gothicinfo.net/images/news/index.php?id=" . $src['id'])) . '" type="' . $size['mime'] . '" />
</item>
';
}

// Bye bye!
echo '
	</channel>
</rss>
';
?>