<?php

/**
 * /rss2/products.xml
 *
 * This generates RSS XML data the 10 most recently added products.
 */

require_once('core.inc');

////////////////////////////////////////////////////////////////////////////////

$cond = array();
$cond[] = "product_status = 'active'";
$cond = implode(' AND ', $cond);

////////////////////////////////////////////////////////////////////////////////

core_tool('rss2product');

$rss2cache = new RSS2Cache(5);
#if ($rss2cache->dump())
#  exit;

$chan = new RSS2Channel("Newest Viral T-Shirts at TeeVirus.com");
$chan->pubDate = DB::get_var("SELECT UNIX_TIMESTAMP(MAX(product_added)) FROM `Products` WHERE {$cond}");
$chan->ttl = 15;

////////////////////////////////////////////////////////////////////////////////

$feed = new RSS2ProductFeed($chan);

DB::query("SELECT product_id FROM `Products` WHERE {$cond} ORDER BY product_added DESC LIMIT 10");
$feed->populate(DB::get_result());

$xml_data = $feed->dump(TRUE);
$rss2cache->save($xml_data);
echo $xml_data;

?>
