<?php

error_reporting
(0);

define('RSS_ITEMS'5);
define('RSS_TTL'180);

define('RSS_FILE''./slug2.xml');
define('RSS_SOURCE''./slug.xml');
define('RSS_GENERATOR''http://www.usrtriton.nl/slug/rss.php');
define('RSS_HEADER''Content-type: application/xml; charset=UTF-8');

define('RSS_HEADERSIZE'14);
define('RSS_FOOTERSIZE'2);

clearstatcache();
if ( 
file_exists(RSS_FILE) && file_exists(RSS_SOURCE) && filemtime(RSS_FILE) >= filemtime(RSS_SOURCE) )
{
    
header(RSS_HEADER);
    
readfile(RSS_FILE);
    exit();
}

if ( 
file_exists(RSS_SOURCE) && time() - filemtime(RSS_SOURCE) < RSS_TTL 60 )
    
$rss file(RSS_SOURCE);
else
    
$rss file(RSS_GENERATOR);

$header array_splice($rss0RSS_HEADERSIZE);
$footer array_splice($rss, -RSS_FOOTERSIZE);
$body array_values($rss);

$deleteheaderlines = array(56810111213);
foreach ( 
$deleteheaderlines as $linenumber )
    unset(
$header[$linenumber]);

$items 0;
$lines count($body);
for ( 
$i 0$i $lines; ++$i )
{
    if ( 
$items RSS_ITEMS )
    {
        
$s trim($body[$i]);
        if ( 
strpos($s'</item>') !== FALSE )
            ++
$items;
        elseif ( 
strpos($s'<item>') === FALSE
            
&& strpos($s'<title>') === FALSE
            
&& strpos($s'<link>') === FALSE )
            unset(
$body[$i]);
    }
    else
        unset(
$body[$i]);
}

$rss implode(''$header).implode(''$body).implode(''$footer);

if ( 
$fp fopen(RSS_FILE'wb') )
{
    
fwrite($fp$rss);
    
fclose($fp);
    
chmod(RSS_FILE0666);
}

header(RSS_HEADER);
echo 
$rss;

?>