<?php
if (!defined('R_P')) exit("access Die");
include_once(R_P . "/include/class.view.php");
@set_time_limit(180);
@ignore_user_abort();
class cron_js_update{
	var $view = null;
	function cron_js_update(){
		
	}
	
	function run(){
		$temp = qdb::fetchAll( "select * from ".TABLEPRE."js ");
		$ids = array();
		foreach($temp as $js){
			$ids[] = $js['id'];
			qbase::writetofile(A_P . "/templates/cache/" . substr($js['file_name'], 0, strpos($js['file_name'], '.')) . '.php', $js['tpl']);
			@extract( @unserialize( $js['args']));
			$order_type = $order_type ? " views desc " : " id desc ";
			$temp = cmsQuery("channelid={$js['channelid']}&cid={$cid}&is_comend={$is_comend}&order={$order_type}&filter={$filter}&thumb={$thumb}&pagesize={$num}");
			$_obj = $temp['data'];
			include qbase::template('cache/' . $js['file_name'] );
			$content =  ob_get_contents();
			ob_clean();
			$content = str_replace( "\"","\\\"", $content);
			if ( strpos( $content, "\n") !== false){
				$contents = explode("\n", $content);
			}else{
				$contents[] = $content;
			}
			$content = '';
			foreach($contents as $val){
				$content.= "document.write(\"".$val."\");\n"; 	
			}
			$file   = C_P."/js/{$channelid}/{$js['file_name']}";
			qbase::writetofile($file , $content);
		}
		qbase::get_object('event', 'js', array('action'=>'cache', 'data'=>$ids));
	}
}
?>