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

$isoLastModifiedSite = "";
$newLine = "\n";
$ident = "	";
if (!$rootUrl) $rootUrl = "http://www.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>soft82.com - Most downloaded</title>$newLine";
$channelHeader .= "$ident$ident<link>$rootUrl</link>$newLine";
$channelHeader .= "$ident$ident<description>Most downloaded software on 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.soft82.com/images/sigla_rss.gif</url>$newLine";	
$channelHeader .= "$ident$ident$ident<title>soft82.com - Free download</title>$newLine";	
$channelHeader .= "$ident$ident$ident<link>$rootUrl</link>$newLine";
$channelHeader .= "$ident$ident</image>$newLine";

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



    

$sql="select * from produse, most_downloaded_all_time, pages, licences where most_downloaded_all_time.id_produs=produse.id_produs and produse.id_page=pages.id_page and produse.id_licence=licences.id_licence order by produse.downloads 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." ".$row['version'];
$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.soft82.com/rss/new_additions.xml\">soft82.com - Free download</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";
?>