<?php 
// Let us first make sure the php file is 
// interpeted as xml information 

$products=$this->products;
$urlArray   =   explode('//',SITE_SECURE_URL);
$site_url   =   PROTOCOL.$urlArray[1];
header ("Content-Type: text/xml"); 
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
// First we print the overall xml information 
echo "<rss version=\"2.0\">\n";
echo "<channel>\n";
// Here comes the global title for you rss 
echo "<title>" . SITE_NAME . "</title>\n";
// Here comes the url for the page that the rss applies for 
//echo "<link>" . $site_url . "</link>\n";
// Here comes a short description of the page 
echo "<description>Latest listing feed</description>\n";

// Now over to the dynamic part 

if (count($products) == 0) {
    echo "<item>\n";
    echo "<title>Sorry, no records to display.</title>\n";
    //echo "<link>".$siteSettings['site_normal_url']."/index.php</link>\n";
    echo "<link>" . $site_url . "</link>\n";
    echo "<description>\n";
    echo "Sorry, no records to display.";
    echo "</description>\n";
    echo "</item>\n";
} else {
    $feedCount = 0;
    foreach ($products AS $product) {
        ++$feedCount;
        echo "<item>\n";
        echo "<title>" . preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', ucfirst($product->Title)) . "</title>\n";
        echo "<link>" . $site_url . "/index/pagelisting/" . preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', $product->alias) . "</link>\n";
        echo "<description>\n";
        echo preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', $product->Description);
        echo "</description>\n";
        echo "<pubDate>" . date("D, j M Y G:i:s", strtotime($product->dPostDate)) . " -5.00</pubDate>\n";
        echo "</item>\n";
        if($feedCount>=15) {
            break;
        }
    }
}
// And at last the closing tags for the overall info 
echo "</channel>\n";
echo "</rss>\n";
?>

