<?php

/**
 * /rss2/unsifted.xml
 *
 * This generates RSS XML data the 10 most recently queued ("unsifted") videos.
 */

require_once('core.inc');

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

$cond = array();
$cond[] = "post_type = 'video'";
$cond[] = "post_status = 'queued'";

if ($channel_id = Channel::get_current_id()) {
  $subdomain = ucfirst(Subdomain::get_current());
  $cond[] = DB::create_set_search($channel_id, 'post_channels');
}
else
  $subdomain = '';

$cond = implode(' AND ', $cond);

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

core_tool('rss2video');

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

$settings_conf = LangConf::get_settings_instance();
$chan = new RSS2Channel("Latest Unsifted {$subdomain} Videos at {$settings_conf->SiteName}");
$chan->pubDate = DB::get_var("SELECT UNIX_TIMESTAMP(MAX(post_published)) FROM `Posts` WHERE {$cond}");
$chan->ttl = 15;

core_class('url');
$url = URL::get_instance();
$chan->link = $url->get_www_queue();

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

$feed = new RSS2VideoFeed($chan);

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

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

?>

