<?php
include('../conectare_db.php');
include ('../format_meta_description.php');

$isoLastModifiedSite = "";
$newLine = "\n";
$ident = "	";
if (!$rootUrl) $rootUrl = "http://www.games.soft82.com/";

$xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>$newLine";

$rssOpen = "<rss version=\"2.0\">$newLine";
$rssClose = "</rss>$newLine";

$rssValue = "";

function makeIso8601TimeStamp ($dateTime) {
    if (!$dateTime) {
        $dateTime = date('Y-m-d H:i:s');
    }
    if (is_numeric(substr($dateTime, 11, 1))) {
        $isoTS = substr($dateTime, 0, 10) ."T"
                 .substr($dateTime, 11, 8) ."+00:00";
    }
    else {
        $isoTS = substr($dateTime, 0, 10);
    }
    return $isoTS;
}

function makeRFC822date($mysqlDate)
{
$rawdate=strtotime($mysqlDate);
if ($rawdate == -1) {
$convertedDate = 'conversion failed';
} else {
$convertedDate = date('r', $rawdate);
return $convertedDate;
}
}


$channelHeader = "$ident<channel>$newLine";
$channelHeader .= "$ident$ident<title>games.soft82.com - Last 7 Days Top</title>$newLine";
$channelHeader .= "$ident$ident<link>$rootUrl</link>$newLine";
$channelHeader .= "$ident$ident<description>Top games on games.soft82.com</description>$newLine";
$channelHeader .= "$ident$ident<generator>soft82.com automated administration system</generator>$newLine";
$channelHeader .= "$ident$ident<language>en-us</language>$newLine";
$channelHeader .= "$ident$ident<copyright>2006 SOLUTIONS AND CONSULTING S.R.L. - All rights reserved.</copyright>$newLine";
$date = makeRFC822date(date('Y-m-d H:i:s'));
$channelHeader .= "$ident$ident<pubDate>$date</pubDate>$newLine";
$channelHeader .= "$ident$ident<lastBuildDate>$date</lastBuildDate>$newLine";
$channelHeader .= "$ident$ident<category>Software</category>$newLine";
$channelHeader .= "$ident$ident<docs>http://blogs.law.harvard.edu/tech/rss</docs>$newLine";
$channelHeader .= "$ident$ident<ttl>30</ttl>$newLine";				
		
$channelHeader .= "$ident$ident<image>$newLine";
$channelHeader .= "$ident$ident$ident<url>http://www.games.soft82.com/images/sigla_rss.gif</url>$newLine";	
$channelHeader .= "$ident$ident$ident<title>games.soft82.com - Free online games</title>$newLine";	
$channelHeader .= "$ident$ident$ident<link>$rootUrl</link>$newLine";
$channelHeader .= "$ident$ident</image>$newLine";

$channelClose = "$ident</channel>$newLine";		
		



    

$sql="select * from games_produse, games_pages where games_produse.id_page=games_pages.id_page order by 7_days_hits desc limit 0,30";
$resursa=mysql_query($sql);
while($row=mysql_fetch_array($resursa))
{


$rssValue .= "$ident$ident<item>$newLine";

$nume_produs = str_replace("&", "and", $row['nume_produs']);
$title=$nume_produs;
$rssValue .= "$ident$ident$ident<title>$title</title>$newLine";

$pageUrl = $rootUrl.$row['pageUrl'];
$rssValue .= "$ident$ident$ident<link>$pageUrl</link>$newLine";

if($row['meta_description']!='') {$description = $row['meta_description'];}
else {$description = FormatMetaDescription($row['description']);}
$description = str_replace("&", "and", $description);
$rssValue .= "$ident$ident$ident<description>$description</description>$newLine";


$pubDate = makeRFC822date($row['date_added']);
$rssValue .= "$ident$ident$ident<pubDate>$pubDate</pubDate>$newLine";
$rssValue .= "$ident$ident$ident<source url=\"http://www.games.soft82.com/rss/top_games.xml\">Play free online games - games.soft82.com</source>$newLine";
$rssValue .= "$ident$ident$ident<guid  isPermaLink=\"true\">$pageUrl</guid>$newLine";
$rssValue .= "$ident$ident</item>$newLine";
}

header('Content-type: application/xml; charset="utf-8"',true);
print "$xmlHeader$rssOpen$channelHeader$rssValue$channelClose$rssClose";
?>