<?php
/**
* eXtreme Message Board
* XMB 1.9.11
*
* RSS Feed Add-On
* Version 0.1 BETA by Robert Chapin (miqrogroove)
* http://www.miqrogroove.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/
define('X_SCRIPT', 'feed.xml.php');
// Configurable, edit as you like!
define('MAX_RSS_ITEMS', 10);
require 'header.php';
$fid = getInt('fid');
$fids = loadFIDs();
if ($fid > 0) {
if (!in_array($fid, $fids)) {
header('HTTP/1.0 404 Not Found');
error('404 Not Found');
} else {
$fids = array($fid);
$forum = getForum($fid);
$link = "{$full_url}forumdisplay.php?fid=$fid";
$title = rss_cdata(fnameOut($forum['name']));
$desc = rss_cdata(html_entity_decode($forum['description']));
}
} else {
$link = $full_url;
$title = $SETTINGS['bbname'];
$desc = $lang['alttodayposts'];
}
if (count($fids) == 0) {
header('HTTP/1.0 403 Forbidden');
error('The forums have not been configured for guest access yet.');
}
$fids = implode(',', $fids);
$query = $db->query(
"SELECT t.*, MIN(p.dateline) AS firstpost
FROM ".X_PREFIX."threads AS t
LEFT JOIN ".X_PREFIX."posts AS p USING (tid)
WHERE t.fid IN ($fids) AND t.closed NOT LIKE 'moved%'
GROUP BY t.tid
ORDER BY tid DESC
LIMIT ".MAX_RSS_ITEMS
);
if ($row = $db->fetch_array($query)) {
$lastpost = explode('|', $row['lastpost']);
$build = '<lastBuildDate>'.date('r', $lastpost[0]).'</lastBuildDate>';
$db->data_seek($query, 0);
} else {
$build = '';
}
echo "<?xml version='1.0' encoding='{$lang['charset']}' ?>\n";
?>
<rss version="2.0">
<channel>
<title><?php echo $title; ?></title>
<link><?php echo $link; ?></link>
<description><?php echo $desc; ?></description>
<language><?php echo $lang['iso639']; ?></language>
<generator><?php echo $versionlong; ?></generator>
<?php echo "$build\n"; ?>
<?php
while ($thread = $db->fetch_array($query)) {
?>
<item>
<title><?php echo rawHTMLsubject(stripslashes($thread['subject'])); ?></title>
<link><?php echo "{$full_url}viewthread.php?tid={$thread['tid']}"; ?></link>
<guid><?php echo "{$full_url}viewthread.php?tid={$thread['tid']}"; ?></guid>
<pubDate><?php echo date('r', $thread['firstpost']); ?></pubDate>
</item>
<?php
} // wend
?>
</channel>
</rss>
<?php
//loadFIDs returns an array of forum and subforum IDs accessible by Guests.
function loadFIDs() {
$forums = permittedForums(forumCache(), 'thread', 'array', TRUE, 'Guest');
$fids = array();
foreach($forums as $forum) {
if ($forum['type'] != 'group') {
$fids[] = $forum['fid'];
}
}
return $fids;
}
function rss_cdata($input) {
return "<![CDATA[$input]]>";
}
?>
|