Topic: New RSS genereating script
I combined two scripts posted on this forum, one for generating googlemap and the other for generating RSS feed, and obtained a new script which works better for me than the old one.
Here it is:
<?
session_start();
include_once("admin/inc.php");
if ($validation == 1) { $val_string = " AND valid = 1"; } else { $val_string = ""; }
if ($validation == 1) { $val_string2 = " where valid = 1"; } else { $val_string2 = ""; }
$sql_links = "select $ads_tbl.siteid,$ads_tbl.sitetitle,$ads_tbl.sitedescription,$ads_tbl.datestamp, $cat_tbl.catname from $ads_tbl inner join $cat_tbl on $ads_tbl.sitecatid = $cat_tbl.catid $val_string2 order by datestamp desc, siteid desc limit 20";
$sql_result = mysql_query ($sql_links);
$num_links = mysql_num_rows($sql_result);
$fp = fopen("rss.xml","w");
fwrite($fp, "n<rss version="2.0">n");
fwrite($fp, "<channel>n");
fwrite($fp, "<title>Title</title>n");
fwrite($fp, "<link>http://".$url."/</link>n");
fwrite($fp, "<description>description</description>n");
fwrite($fp, "<language>en</language>n");
fwrite($fp, "<lastBuildDate>".strftime("%a, %d %b %Y %T %Z",time())."</lastBuildDate>n");
fclose($fp);
for ($i=0; $i<$num_links; $i++)
{
$sitetitle = "";
$row = mysql_fetch_array($sql_result);
$siteid = $row["siteid"];
$sitetitle = strip_tags($row["sitetitle"]);
// only displaying first 150 characters of the ad text
$sitedescription = substr($row["sitedescription"],0,250);
$catname = $row["catname"];
//$datestamp = strftime("%a, %d %b %Y %T %Z",$row["datestamp"]);
$datestamp = strftime("%a, %d %b %Y %T %Z",strtotime($row["datestamp"]));
$fp = fopen("rss.xml","a");
fwrite($fp, "<item>");
fwrite($fp, "<title>".$catname." : ".$sitetitle."</title>n");
fwrite($fp, "<link>http://".$url."/detail.php?siteid=".$siteid."</link>n");
fwrite($fp, "<description>".$sitedescription."</description>n");
fwrite($fp, "<pubDate>".$datestamp."</pubDate>n");
fwrite($fp, "</item>");
fclose($fp);
}
$fp = fopen("rss.xml","a");
fwrite($fp, "n</channel>n");
fwrite($fp, "n</rss>n");
fclose($fp);
?>You first need to create the file rss.xml and Chmod it to 666.
The above code can be put into a .php file and runed by a cron job (this is what I did so the feed updates regularly).
The script might have some code that does nothing (unfortunately I'm not that good in php to find it and delete it) so anyone who can improve it, is welcomed.