<?php
/**
 * @version $Id: js.php v2.0 $
 * @package PBDigg
 * @copyright Copyright (C) 2007 - 2008 PBDigg.com. All Rights Reserved.
 * @license PBDigg is free software and use is subject to license terms
 */

define('PB_CSCRIPT', 'js');
require_once('include/common.inc.php');

if (!$pb_jstransfer)
{
	exit('document.write("'.$u_message['js_transfer_closed'].'")');
}
if ($pb_jsurl && !in_array($_SERVER['HTTP_HOST'], explode('|', $pb_jsurl)))
{
	exit('document.write("'.$u_message['js_transfer_denied'].'")');
}
if (!$action || !in_array($action, array('digg','views','postdate','comments')))
{
	exit('document.write("'.$u_message['js_illegal_param'].'")');
}
$TPL->caching = TRUE;
$TPL->cache_lifetime = intval($pb_jstime);
if (!$TPL->is_cached('js.html', $action))
{
	$DB->db_query("SELECT tid, cid, author, subject, digg, bury, views, comments FROM {$db_prefix}threads WHERE ifcheck = 1 ORDER BY $action DESC LIMIT 0, 10");
	$rs = $js = array();
	if ($DB->db_num())
	{
		while ($rs = $DB->db_fetch_array())
		{
			$rs['subject'] = addcslashes($rs['subject'], '"');
			if (!$rs['author'])
			{
				if ($pb_anonnick)
				{
					$rs['author'] = $pb_anonnick;
				}
				else
				{
					$rs['author'] = $pb_sitename.$u_message['net_friend'];
				}
			}
			$rs['cate'] = $categories[$rs['cid']]['name'];
			$js[] = $rs;
		}
	}
	$TPL->assign('js', $js);
	echo $TPL->fetch('js.html', $action);
	@ob_end_flush();
	exit;
}
PBOutPut('js.html', $action);
?>