<?php

require_once 'config.php';

// Which subject id to start our display on
$start = isset($_GET['start']) ? max(0,intval($_GET['start'])) : 0;

// Set a default sort if a valid one isn't provided
// $sorts is set in include.php
if (! (isset($_GET['sort']) && isset(Config::$sortNames[$_GET['sort']]))) {
    // The value in $_GET is altered so that buildLinkList() works
    $_GET['sort'] = 'added';
}

$query = XN_Query::create('Content')
     ->filter('owner','=')
    ->filter('type','eic',Config::$subjectType)
     ->begin($start)
     ->end($start + Config::$pageSize)
     ->order(Config::$sortFields[$_GET['sort']][0],
	     Config::$sortFields[$_GET['sort']][1])
     ->alwaysReturnTotalCount(true);
     
$stats = XN_Query::create('Content_Count')
    ->filter('owner')
    ->rollup('type')
    ->execute();


// Retrieve appropriate content
$subjects = $query->execute();
$style = 'index';

// _index.php uses $subjects, $style, $query, $start, $sort
if ($_GET['mode'] == "rss") {
    XN_Application::includeFile('alphacomponents','/Alpha/Format/RSS.php');
    header("Content-Type: text/xml");
    $app = XN_Application::load();
    $feed = new XNC_Alpha_Format_RSS();
    
    $feed->title($app->name)
         ->description("")
         ->link("http://".$_SERVER['HTTP_HOST']."/");
    
    include 'html/index_rss.php';
    if (!is_array($feed->items)) {
        $feed->items = array();
    }
    print $feed->toXML();
} else {
    include 'html/index.php';
}
?>
