<?php
define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require_once PUN_ROOT.'include/common.php';
require_once PUN_ROOT.'include/parser.php';
require_once PUN_ROOT.'include/user/feed_functions.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/feed.php';
//------------------------------------------------------------//
// Make sure guests have permission to read the forums
$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
if ($db->result($result) == '0')
{
exit('No permission');
}
//------------------------------------------------------------//
// Turn off magic_quotes_runtime
set_magic_quotes_runtime(0);
$show = 'topic';
$postslimit = '25';
$maxchars = '250';
$forumuri = $pun_config['o_base_url'].'/';
$modsdir = $pun_config['o_base_url'].'/';
$imagedir = $pun_config['o_base_url'].'/img/icons/';
//------------------------------------------------------------//
if (isset($_GET['cid']) && trim($_GET['cid']) != '')
{
$feedreq = ' AND c.id='.intval($_GET['cid']);
$add = '?cid='.intval($_GET['cid']);
}
else if (isset($_GET['fid']) && trim($_GET['fid']) != '')
{
$feedreq = ' AND f.id='.intval($_GET['fid']);
$add = '?fid='.intval($_GET['fid']);
}
else if (isset($_GET['pfid']) && trim($_GET['pfid']) != '')
{
$feedreq = ' AND f.parent_forum_id='.intval($_GET['pfid']);
$add = '?pfid='.intval($_GET['pfid']);
}
else if (isset($_GET['tid']) && trim($_GET['tid']) != '')
{
$feedreq = ' AND t.id='.intval($_GET['tid']);
$add = '?tid='.intval($_GET['tid']);
}
else
{
$feedreq = '';
$add = '';
}
if ($show != 'post')
{
$result = $db->query('SELECT t.last_post, t.id, t.posted AS tposted, t.subject, t.poster, p.message, p.hide_smilies, p.posted AS pposted, f.forum_name AS forum, c.cat_name AS category FROM '.$db->prefix.'topics t LEFT JOIN '.$db->prefix.'posts p ON (p.topic_id=t.id AND t.posted=p.posted) INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'categories AS c ON f.cat_id=c.id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$feedreq.' ORDER BY last_post DESC LIMIT '.$postslimit) or error('Unable to fetch forum topics', __FILE__, __LINE__, $db->error());
}
else
{
$result = $db->query('SELECT t.last_post, p.id, p.message, p.poster, p.posted AS pposted, p.hide_smilies, t.posted AS tposted, t.subject, f.forum_name AS forum, c.cat_name AS category FROM '.$db->prefix.'posts p LEFT JOIN '.$db->prefix.'topics t ON p.topic_id=t.id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'categories AS c ON f.cat_id=c.id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$feedreq.' ORDER BY last_post DESC LIMIT '.$postslimit) or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());
}
//------------------------------------------------------------//
list($lastpost) = $db->fetch_row($result);
//pg_result_seek($result, 0);
mysql_data_seek($result, 0);
$x = '0';
$servertag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : '';
ob_start();
if (!$lastpost)
{
makeheader($none, $add);
noposts($none);
}
else if ($servertag != $lastpost)
{
while ($cur = $db->fetch_assoc($result))
{
if ($x == '0')
{
makeheader($cur, $add);
$x++;
$tag = $cur['last_post'];
}
makeposts($cur, $show, $maxchars);
}
echo '</channel>'."\n";
echo '</rss>'."\n";
}
$feed = ob_get_contents();
ob_end_clean();
//------------------------------------------------------------//
if ($x == '0')
{
header('HTTP/1.1 304 Not Modified');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $lastpost).' GMT');
header('Date: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Length: 0');
header('Etag: '.$lastpost);
}
else
{
header('Etag: '.$lastpost);
if (stristr($_SERVER["HTTP_ACCEPT"], "application/xml"))
{
header ('Content-Type: application/rss+xml; charset='.$lang_common['lang_encoding']);
}
else
{
header ('Content-type: text/xml; charset='.$lang_common['lang_encoding']);
}
echo $feed;
}
//------------------------------------------------------------//
function makeheader($cur, $add)
{
global $pun_config, $lang_common, $lang_feed, $modsdir, $imagedir, $forumuri;
$language = strtolower(substr($pun_config['o_default_lang'], 0, 2));
$script = basename($_SERVER['PHP_SELF']);
$board_title = pun_htmlspecialchars($pun_config['o_board_title']);
echo '<?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?>'."\n";
echo '<rss version="2.0" xmlns:atom="'.$lang_feed['Atom uri'].'">'."\n";
echo '<channel>'."\n";
echo '<title>'.$board_title.' '.$lang_feed['RSS feed'].'</title>'."\n";
echo '<link>'.$forumuri.'</link>'."\n";
echo '<generator>'.$lang_feed['RSS generator'].$lang_feed['Version'].'</generator>'."\n";
echo '<description>'.$board_title.'</description>'."\n";
echo '<language>'.$language.'</language>'."\n";
echo '<docs>'.$lang_feed['RSS uri'].'</docs>'."\n";
echo '<atom:link href="'.$modsdir.$script.$add.'" rel="self" type="application/rss+xml"/>'."\n";
echo '<copyright>'."\n";
echo "\t".$lang_feed['Copyright']."\n\t".$board_title."\n\t".$forumuri."\n";
echo '</copyright>'."\n";
echo '<ttl>60</ttl>'."\n";
}
function noposts($none)
{
global $pun_config, $lang_common, $lang_feed, $modsdir, $imagedir, $forumuri;
echo '<item>'."\n";
echo "\t".'<title>'.$lang_feed['No posts'].'</title>'."\n";
echo "\t".'<link>'.$forumuri.'</link>'."\n";
echo "\t".'<guid isPermaLink="false">'.$forumuri.'</guid>'."\n";
echo "\t".'<description>'."\n";
echo "\t\t".$lang_feed['No posts info']."\n";
echo "\t".'</description>'."\n";
echo '</item>'."\n";
echo '</channel>'."\n";
echo '</rss>'."\n";
}
function makeposts($cur, $show, $maxchars)
{
global $pun_config, $lang_common, $lang_feed, $modsdir, $imagedir, $forumuri;
if ($show != 'post')
{
$link = $forumuri.'viewtopic.php?id='.strval($cur['id']);
}
else
{
$link = $forumuri.'viewtopic.php?pid='.strval($cur['id']).'#p'.strval($cur['id']);
}
$author = pun_htmlspecialchars($cur['poster']);
if (strpos($cur['message'], '[video]') !== false || strpos($cur['message'], '[mp3]') !== false)
{
$message = str_replace(array('[video]', '[/video]', '[mp3]', '[/mp3]'), array('[url]', '[/url]', '[url]', '[/url]'), $cur['message']);
}
else
{
$message = $cur['message'];
}
$post = gmdate('d M Y H:i:s', $cur['last_post']);
$topic = gmdate('d M Y H:i:s', $cur['tposted']);
if (pun_strlen($message) > $maxchars)
{
$message = '<![CDATA[ '.$lang_feed['Author'].$author.'<br/>'."\n\t\t".parse_message(pun_htmlspecialchars($message), $cur['hide_smilies']).' ]]>';
}
else
{
$message = '<![CDATA[ '.$lang_feed['Author'].$author.'<br/>'."\n\t\t".parse_message(pun_htmlspecialchars($message), $cur['hide_smilies']).' ]]>';
}
echo '<item>'."\n";
echo "\t".'<title>'.pun_htmlspecialchars($cur['subject']).'</title>'."\n";
echo "\t".'<link>'.pun_htmlspecialchars($link).'</link>'."\n";
echo "\t".'<guid isPermaLink="false">'.strval($cur['id']).'@'.$forumuri.'</guid>'."\n";
echo "\t".'<pubDate>'.strval(date("r", $cur['tposted'])).'</pubDate>'."\n";
echo "\t".'<category>'.pun_htmlspecialchars($cur['category'].' : '.$cur['forum']).'</category>'."\n";
echo "\t".'<description>'."\n";
echo "\t\t".$message."\n";
echo "\t".'</description>'."\n";
echo '</item>'."\n";
}
//------------------------------------------------------------//
?>