<?php

include "settings.php";
include "utilities.php";
// get your news items from somewhere, e.g. your database:
$myFile = $_SERVER['RSS_FILE'];
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo "<rss version='2.0'>";
echo "<channel>";
echo "<title>" . $_SERVER['WEBSITE_TITLE'] . "</title>";
echo "<link>" . currentURL() . "</link>";
echo "<description>" . $_SERVER['WEBSITE_DESCRIPTION'] . "</description>";
preg_match_all("/<album>.*<name>(.*)<\\/name>.*<link>(.*)<\\/link>.*<\\/album>/", $theData, $matches, PREG_SET_ORDER);
$reversedmatches = array_reverse($matches);
foreach ($reversedmatches as $val) {
    writeItem($val[1], $val[2], "from <a href='" . currentURL() . "'>" . $_SERVER['HTTP_HOST'] . "</a>");
}
echo "</channel>";
echo "</rss>";
function writeItem($title, $link, $description)
{
    echo "<item>";
    echo "<title>" . $title . "</title>";
    echo "<link>" . $link . "</link>";
    echo "<description>" . $description . "</description>";
    echo "</item>";
}
    writeUtf8("TWOHANDS=" . $DB->f('twohands'));
    //	writeUtf8("TEVENTS=".$DB->f('tevents'));
    writeMultiLine("TEVENTS", $DB->f('tevents'));
    writeUtf8("");
    writeUtf8("ON=@CREATE");
    writeUtf8("COLOR=" . $DB->f('color'));
    writeMultiLine("", $DB->f('create'));
    writeUtf8("");
}
require "mysql.php";
$DB = new cMySql();
$DB->Database = "mytserver";
$category = "";
$section = "";
$cnt = 0;
$fp = 0;
$DB->query("SELECT *, FORMAT(weight/10,1) AS weight FROM itemforge WHERE valid=1 ORDER BY category,subsection,name");
fileOpen();
writeFileHeader();
while ($DB->next_record()) {
    if ($DB->f('category') != $category || $DB->f('subsection') != $section) {
        $category = $DB->f('category');
        $section = $DB->f('subsection');
        writeSectionHeader($category, $section);
    }
    writeItem($DB);
    $cnt++;
}
writeln("[EOF]");
fileClose();
//echo "$cnt items exportados";
include "utilities.php";
// get your news items from somewhere, e.g. your database:
$myFile = $_SERVER['RSS_FILE'];
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo "<rss version='2.0'>";
echo "<channel>";
echo "<title>" . $_SERVER['WEBSITE_TITLE'] . "</title>";
echo "<link>" . currentURL() . "</link>";
echo "<description>" . $_SERVER['WEBSITE_DESCRIPTION'] . "</description>";
preg_match_all("/<album>.*<name>(.*)<\\/name>.*<link>(.*)<\\/link>.*<\\/album>/", $theData, $matches, PREG_SET_ORDER);
$reversedmatches = array_reverse($matches);
$count = 0;
foreach ($reversedmatches as $val) {
    writeItem($val[1], $val[2], "");
    $count = $count + 1;
    if ($count >= $_SERVER['MAX_FEED_ITEMS']) {
        break;
    }
}
echo "</channel>";
echo "</rss>";
function writeItem($title, $link, $description)
{
    echo "<item>";
    echo "<title>" . $title . "</title>";
    echo "<link>" . $link . "</link>";
    echo "<description>" . $description . "</description>";
    echo "</item>";
}