Codice: Seleziona tutto
<?
header("Content-Type: text/xml");
//header("Content-Type: text/html; charset=US-ASCII");
require("config.php");
if (file_exists("/tmp/rss.xml")) {
$ora_file = filemtime("/tmp/rss.xml");
if (time() - $ora_file <= 60*5) {
readfile("/tmp/rss.xml");
exit;
}
}
function convertDate($date) {
$ts = strtotime($date);
$date = date("r",$ts);
return $date;
}
function prepare($text,$len=-1) {
$text = html_entity_decode($text);
$text = preg_replace("/\[img([^]]*)\]([^[]*)\[\/img([^]]*)\]/","",$text);
$text = preg_replace("/\[quote([^]]*)\]/","\"",$text);
$text = preg_replace("/\[\/quote([^]]*)\]/","\"",$text);
//$text = preg_replace("/\[([^]]+)\]/","",$text);
//$text = preg_replace("/\[\/([^]]+)\]/","",$text);
$text = preg_replace("/\[([^]]+)\]([^[]*)\[\/\\1\]/","\\2",$text);
if ($len > 0)
$text = substr($text,0,$len)."...";
$text = "<![CDATA[".utf8_encode($text)."]]>";
return $text;
}
$db = mysql_connect($dbhost,$dbuser,$dbpasswd);
if (!$db) die;
if (!mysql_select_db($dbname,$db)) die;
$rss_date = "0000-01-01";
$feed_rss = array();
$feed_order = array();
$tot_threads = 10;
$url_phpbb = "http://www.slacky.eu/forum/";
$sql = "SELECT b.post_id,a.topic_title,date_format(from_unixtime(b.post_time),'%Y-%m-%d %H:%i:%s'),a.topic_id,c.forum_name,a.topic_first_post_id,a.topic_last_post_id
FROM ".$table_prefix."topics a,".$table_prefix."posts b,".$table_prefix."forums c
WHERE a.forum_id=c.forum_id AND a.topic_id=b.topic_id AND c.forum_status=0 AND c.auth_read=0 AND c.auth_view=0 AND a.topic_last_post_id=b.post_id
ORDER BY b.post_time DESC LIMIT ".($tot_threads);
if ($res=mysql_query($sql)) {
while ($row = mysql_fetch_row($res)) {
$tmp = mysql_fetch_row(mysql_query("SELECT post_text FROM ".$table_prefix."posts_text WHERE post_id='$row[0]'"));
$row[7] = $tmp[0];
$link = $url_phpbb."/viewtopic.php?p=".$row[0]."#".$row[0];
$this_thread = array("title" => prepare($row[1]), "link"=> $link, "guid" => $link , "pubDate"=>convertDate($row[2]) ,
"category" => prepare($row[4]) , "description" => prepare($row[7],100));
$feed_rss[] = $this_thread;
$feed_order[] = $row[2];
if ($row[2] > $rss_date)
$rss_date = $row[2];
}
mysql_free_result($res);
}
$rss_date = convertDate($rss_date);
arsort($feed_order);
$tmp_feed = array();
foreach ($feed_order as $k=>$v)
$tmp_feed[] = $feed_rss[$k];
$feed_rss = $tmp_feed;
mysql_close($db);
ob_start();
?>
<rss version="2.0">
<channel>
<title>Slacky</title>
<link>http://www.slacky.eu/forum</link>
<description>Slacky - Italian Slackware Community.</description>
<language>it-it</language>
<managingEditor>info@slacky.it</managingEditor>
<webMaster>info@slacky.it</webMaster>
<image>
<url>http://www.slacky.eu/favicon.ico</url>
<title>Slacky: ultime news e discussioni</title>
<link>http://www.slacky.eu/forum</link>
</image>
<ttl>30</ttl>
<pubDate><?echo $rss_date;?></pubDate>
<lastBuildDate><?echo $rss_date;?></lastBuildDate>
<?
foreach ($feed_rss as $n) {
?>
<item>
<?
foreach ($n as $k=>$v)
echo "<$k>$v</$k>\n";
?>
</item>
<?
}
?>
</channel>
</rss>
<?
$rss_file = ob_get_contents();
$f = fopen("/tmp/rss.xml","w");
if ($f) {
fwrite($f,$rss_file);
fclose($f);
}
ob_end_flush();
clearstatcache();
?>


