<?php
require_once(dirname(dirname(__FILE__)) . "/global.php");
$pid = intval($_GET['pid']);
$ordering = trim($_GET['ordering']);
$format = strtolower(trim($_GET['format']));
$limit = min(100, max(1, intval($_GET['limit'])));
if(!in_array($ordering, array('asc', 'desc'))) $ordering = 'asc';
if(!$format) $format = 'xml';
$data = cmsPortal($pid, $ordering, $limit);
qbase::headerCache(300);
if($format == 'json'){
	echo AJAX ? qbase::xmlprint(qbase::jsonencode($data)) : qbase::jsonencode($data);
}else if($format == 'xml'){
	header("Content-Type: text/xml; charset={$_SET['def_charset']}");
	echo qbase::get_object('array2xml', $data, $_SET['def_charset'])->get();
}else if($format == 'jsonp'){
	$jsonp_call = trim($_GET['call']);
	if(!$jsonp_call) $jsonp_call = "_output_back";
	echo $jsonp_call .'('.  qbase::jsonencode($data)  .')'; 
}
?>