<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* 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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (is_file("mainfile.php")) {
include_once("mainfile.php");}
global $prefix, $db, $nukeurl;
header("Content-Type: text/xml");

$gmtdiff = date("O", time());
$gmtstr = substr($gmtdiff, 0, 3) . ":" . substr($gmtdiff, 3, 9);
$now = date("Y-m-d\TH:i:s", time());
$now = $now . $gmtstr;

$cat = $db->XMFnum($cat);
if ($cat != "") {
	$sql = "SELECT catid FROM ".TABLE_STORIES_CAT." WHERE title LIKE '%$cat%' LIMIT 1";
if ( !($resultat = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _stories_cat', '', __LINE__, __FILE__, $sql);}
	$catid = $db->sql_fetchrow($resultat);
	if ($catid == "") {
		$sql = "SELECT sid, title, time, hometext FROM ".TABLE_STORIES." ORDER BY sid DESC LIMIT 10";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _stories', '', __LINE__, __FILE__, $sql);}
	} else {
		$catid = $db->XMFnum($catid);
		$sql = "SELECT sid, title, time, hometext FROM ".TABLE_STORIES." WHERE catid='$catid' ORDER BY sid DESC LIMIT 10";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _stories', '', __LINE__, __FILE__, $sql);}
	}
} else {
	$sql = "SELECT sid, title, time, hometext FROM ".TABLE_STORIES." ORDER BY sid DESC LIMIT 10";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _stories', '', __LINE__, __FILE__, $sql);}
}

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
    ."<rss version=\"2.0\" \n"
    ."  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
    ."  xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\"\n"
    ."  xmlns:admin=\"http://webns.net/mvcb/\"\n"
    ."  xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n\n"
    ."<channel>\n"
    ."<title>".htmlspecialchars($sitename)."</title>\n"
    ."<link>".htmlspecialchars($nukeurl)."</link>\n"
    ."<description>".$slogan."</description>\n"
    ."<dc:language>".$backend_language."</dc:language>\n"
    ."<dc:creator>".$adminmail."</dc:creator>\n"
    ."<dc:date>".$now."</dc:date>\n\n"
    ."<sy:updatePeriod>hourly</sy:updatePeriod>\n"
    ."<sy:updateFrequency>1</sy:updateFrequency>\n"
    ."<sy:updateBase>".$now."</sy:updateBase>\n\n";

while ($row = $db->sql_fetchrow($result)) {
	$rsid = $db->XMFnum($row['sid']);
	$rtitle = stripslashes($row['title']);
	$rtext = stripslashes($row['hometext']);
        $hometext = stripslashes($row['hometext']);
        $time = stripslashes($row['time']);
    // format: 2004-08-02T12:15:23-06:00
    $date = date("d-m-Y H:i:s", strtotime($time));
    $date = $date . $gmtstr;

    echo "<item>\n"
        ."<title>".$title."</title>\n"
        ."<link>$nukeurl/modules.php?name=News&amp;file=article&amp;sid=$rsid.html</link>\n"
        ."<description>".htmlspecialchars($hometext)."</description>\n"
        ."<guid isPermaLink=\"false\">".$nukeurl."</guid>\n"
        ."<dc:subject>".$topicname."</dc:subject>\n"
        ."<dc:date>".$date."</dc:date>\n"
        ."</item>\n\n";
}

echo "</channel>\n"
    ."</rss>\n";

?>