<?php
header("Content-Type: application/xml");

$fid = intval($_REQUEST["fid"]);

if (!$fid) exit("Unsufficient data provided");
$www_dir = realpath(dirname(__FILE__));
include ("$www_dir/functions.php");
include ("$www_dir/conf.php");

if (!$board_config->en_guest_viewing && !$_SESSION["SBBauth"]) exit("Permission denied"); 

//xml replace
function hex($str) {
  return $str = preg_replace('([^\w\.\-_\n ])', '', $str);
  $find = array("<",">","&","'",".");
  $replace = array("&lt;","&gt;","&amp;","&apos;","&quot;");
  return str_replace($find,$replace,$str);
}

include ("$www_dir/classes/topics.class.php");
$SBBTopics = new SBBTopics();
$SBBTopics->fid = $fid;

$SBBTopics->GetTopics(false);

for ($i=0;$i<$SBBTopics->count;$i++) {
  $row = $SBBTopics->topics[$i];
  $this_user = forum_user($row->uid);
  $this_a_user = ($row->a_uid ? forum_user($row->a_uid) : $this_user);
  
  $output .= '<entry>
    <author><name><![CDATA[' . hex($this_user->user) . ']]></name></author>
    <updated>' . date("c",strtotime($row->a_datetime ? $row->a_datetime : $row->datetime)) . '</updated>
    <link href="' . "http://" . $base_url . ($board_config->seo ? $board_config->main_path . "/sbbt" . $row->id . adddescr2link($row->topic) . ".html" : $board_config->main_script . "?todo=viewtopic&amp;tid=" . $row->id) . '"/>
    <id>' . "http://" . $base_url . ($board_config->seo ? $board_config->main_path . "/sbbt" . $row->id . adddescr2link($row->topic) . ".html" :  $board_config->main_script . "?todo=viewtopic&amp;tid=" . $row->id) . '</id>
    <title type="text"><![CDATA[' . hex($row->topic) . ']]></title>
    <content type="text"><![CDATA[' . hex(substr(strip_tags(strip_bbcodes($row->detail)),0,155) . "...") . ']]></content>
</entry>
    ';
}

echo '<?xml version="1.0" encoding="UTF-8"?'.'>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . '" />
<id>http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . '</id>
<updated>' . date("c") . '</updated>


<title>' . hex($board_config->title) . '</title>
' . $output . '</feed>';
exit();
?>
