<?php
/*
	网站公告模板解析文件
	更新: 2012-02-01 16:08
*/

function parse_notice_template($str)
{
	$str=preg_replace('/\{dir:notice\s+([^\}]+)\}/ie',"dc_call_user_func('get_notice_tag','\\1')",$str);
	$str=preg_replace('/\{\/dir:notice\}/i',"<?php }\$dir_page=\$_DATA['pagestring'];unset(\$_DATA); ?>",$str); 
	return $str;
}

function get_notice_tag($para)
{
	/*
		设置区块默认参数
	*/
	$args=array('row'=>'10',
				'orderby'=>'orderby',
				'orderbyway'=>'asc');
	foreach($para as $key => $arg)
	{
		if(isset($args[$key]))
		{
			$args[$key]=$arg;
		}
	}
	extract($args);

	$row=$row?$row:10;
	$orderby=$orderby?$orderby:"orderby";
	$orderbyway=$orderbyway?$orderbyway:"asc";
	$sql="SELECT * FROM `\".DB_PRE.\"notice` WHERE `\".DB_PRE.\"notice`.`siteid`=".SITEID." ORDER BY ".$orderby." ".$orderbyway;
	return '<?php $_DATA=get_sql_tag_data("'.$sql.'",'.$row.',$page);foreach($_DATA as $no => $r)if(is_array($r)){?>';
}
?>