<?php
error_reporting(E_ALL ^ E_NOTICE);
define('InEmpireCMS',TRUE);
@header('Content-Type: text/html; charset=utf-8');
require('../dongpo/itag/cache_config.php');
if($cache_r['open']){
	require('../dongpo/itag/dp_cache.php');
	$cachestr=dp_LoadCache('tagcache',$cache_r['tag_cache_time']);
	if($cachestr!=false){
		echo $cachestr;
		exit;
	}
	ob_start();
}
require('../class/connect.php');
require('../class/db_sql.php');
require('../class/functions.php');
require('../class/t_functions.php');
require('../data/dbcache/class.php');
require LoadLang('pub/fun.php');
require('../dongpo/itag/dp_funs.php');
$link=db_connect();
$empire=new mysqlquery();
if(!$public_r['opentags']){
	printerror2('CloseTags','');
}

$tagid=(int)$_GET['tagid'];
$py=RepPostVar($_GET['py']);

if(!$tagid && empty($py)){
	exit("error #1");
	printerror2('ErrorUrl','');
}

$sr=$empire->fetch1("select * from {$dbtbpre}dp_itag_set where k='all'");
$dp_itag=json_decode($sr['v'],true);

if(empty($dp_itag)){
	exit("error #2");
	printerror2('ErrorUrl','');
}

$url0=$dp_itag['thisurl'];
$url_page=$dp_itag['thispurl'];

if(empty($url0)){
	exit("error #3");
}

/*
if(strpos($url0,'[!--tagpy--]')!==false && empty($py)){
	exit("error #4.1");
}

if(strpos($url0,'[!--tagid--]')!==false && !$tagid){
	exit("error #4.2");
}*/

$page=(int)$_GET['page'];
$add='';
$search='';

if($tagid){
	$tagr=$empire->fetch1("select * from {$dbtbpre}enewstags where tagid='$tagid'");
	if(!$tagr['tagname']){
		exit("error #5.1");
	}
	$tagradd=$empire->fetch1("select * from {$dbtbpre}dp_itag where tagid='$tagid'");
	$tagname=$tagr['tagname'];
	$py=$tagradd['py'];
	$search.="&tagid=$tagid";
}else{
	$tagradd=$empire->fetch1("select * from {$dbtbpre}dp_itag where py='$py' limit 1");
	if(!$tagradd['tagid']){
		exit("error #5.2");
	}
	$tagid=$tagradd['tagid'];
	$tagr=$empire->fetch1("select * from {$dbtbpre}enewstags where tagid='$tagid' limit 1");
	if(!$tagr['tagname']){
		exit("error #5.3");
	}
	$tagname=$tagr['tagname'];
	$search.="&py=$py";
}

//$url0="/".str_replace("[!--tagpy--]",$py,$url0);
//$url_page="/".str_replace("[!--tagpy--]",$py,$url_page);

$url0="/".str_replace(array('[!--tagid--]','[!--tagpy--]'),array($tagid,$py),$url0);
$url_page="/".str_replace(array('[!--tagid--]','[!--tagpy--]'),array($tagid,$py),$url_page);

$this_link=str_replace(array('[!--tagid--]','[!--tagpy--]'),array($tagid,$py),$url0);


$this_link=str_replace(array('[!--tagid--]','[!--tagpy--]'),array($tagid,$py),$url0);

$tagr=array_merge($tagr,$tagradd);

$num=$tagr['num'];
$classid=$tagr['cid'];
$classname=$htag_r[$tagr['cid']]['classname'];

$tagr['tagurl']=$this_link;

$GLOBALS['navtagid']=$tagid;
$GLOBALS['navpy']=$py;
$GLOBALS['navinfor']=$tagr;

$tagname=ehtmlspecialchars($tagr['tagname']);
$pagetitle=ehtmlspecialchars($tagr['tagtitle']);
$pagetitle=$pagetitle?$pagetitle:$tagname;
$pagekey=ehtmlspecialchars($tagr['tagkey']);
$pagedes=eaddslashes(RepPhpAspJspcode($tagr['tagdes']));
$tagpic=$tagr['tagpic'];
$tagtext=$tagr['tagtext'];

$classimg=$public_r[newsurl].'e/data/images/notimg.gif';

$pageecms=1;
$pageclassid=0;
$have_class=1;

$url='<a href="'.$public_r['newsurl'].'">首页</a> > <a href="'.$this_link.'">'.$tagname.'</a>';

if($tagr['cid']){
	$cr=$empire->fetch1("select * from {$dbtbpre}dp_itag_class where classid='$tagr[cid]' limit 1");
	$cr0=$empire->fetch1("select * from {$dbtbpre}enewstagsclass where classid='$tagr[cid]' limit 1");
	$url='<a href="'.$public_r['newsurl'].'">首页</a> > <a href="'.dp_itag_curl($tagr['cid']).'">'.$cr0['classname'].'</a> > <a href="'.$this_link.'">'.$tagname.'</a>';
}

if($tagr['tempid']){
	$listtempid=(int)$tagr['tempid'];
}else{
	$listtempid=(int)$dp_itag['tempid'];
	if($cr['classid'] && $cr['tempid']){
		$listtempid=(int)$cr['tempid'];
	}
}

if(empty($listtempid)){
	exit("error #6");
}

$tempr=$empire->fetch1("select tempid,temptext,subnews,listvar,rownum,showdate,modid,subtitle,docode from ".GetTemptb("enewslisttemp")." where tempid='$listtempid'");
if(empty($tempr[tempid])){
	printerror('ErrorUrl','',1);
}
if(empty($mid)){
	$mid=$tempr['modid'];
}

//翻页
$page=intval($page);
$start=0;
$line=$dp_itag['tagslistnum'];//每页显示条数
$page_line=$public_r['listpagelistnum'];//每页显示链接数
$offset=$page*$line;//总偏移量
//系统模型
$ret_r=ReturnReplaceListF($mid);

if($num){
	$totalquery="select count(*) as total from {$dbtbpre}enewstagsdata where tagid='$tagid'".$add;
	$num=$empire->gettotal($totalquery);
}

$limitnum=$dp_itag['maxnum'];
if($limitnum&&$limitnum<$num){
	$num=$limitnum;
}

//排序
$addorder="newstime desc";
if($dp_itag['tagorder']){
	$addorder=$dp_itag['tagorder'];
}

$query="select classid,id from {$dbtbpre}enewstagsdata where tagid='$tagid'";
$query.=" order by ".$addorder." limit $offset,$line";
$sql=$empire->query($query);


//伪静态
$listpage=itag_page($num,$line,$page_line,$start,$page,$url0,$url_page);

//页面支持标签
if($public_r['dtcanbq'])
{
	$tempr[temptext]=DtNewsBq('list'.$listtempid,$tempr[temptext],0);
}
else
{
	if($public_r['searchtempvar'])
	{
		$tempr[temptext]=ReplaceTempvar($tempr[temptext]);
	}
}
$listtemp=$tempr[temptext];
$rownum=$tempr[rownum];
if(empty($rownum))
{$rownum=1;}
$formatdate=$tempr[showdate];
$subnews=$tempr[subnews];
$subtitle=$tempr[subtitle];
$docode=$tempr[docode];
$modid=$tempr[modid];
$listvar=str_replace('[!--news.url--]',$public_r[newsurl],$tempr[listvar]);
//公共
$pageno='';
if($page){
	$pageno=$page+1;
}
$listtemp=str_replace('[!--newsnav--]',$url,$listtemp);//位置导航
$listtemp=Class_ReplaceSvars($listtemp,$url,$pageclassid,$pagetitle,$pagekey,$pagedes,$classimg,$addr,$pageecms);
$listtemp=str_replace('[!--page.stats--]','',$listtemp);
$listtemp=str_replace('[!--show.page--]',$listpage,$listtemp);
$listtemp=str_replace('[!--show.listpage--]',$listpage,$listtemp);
$listtemp=str_replace('[!--list.pageno--]',$pageno,$listtemp);

$listtemp=str_replace('[!--tagtext--]',$tagtext,$listtemp);
$listtemp=str_replace('[!--tagname--]',$tagname,$listtemp);
$listtemp=str_replace('[!--tagpic--]',$tagpic,$listtemp);

//取得列表模板
$list_exp="[!--empirenews.listtemp--]";
$list_r=explode($list_exp,$listtemp);
$listtext=$list_r[1];
$no=$offset+1;
$changerow=1;
while($r=$empire->fetch($sql))
{
	if(empty($class_r[$r[classid]][tbname]))
	{
		continue;
	}
	$infor=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$r[classid]][tbname]." where id='$r[id]' limit 1");
	//替换列表变量
	$repvar=ReplaceListVars($no,$listvar,$subnews,$subtitle,$formatdate,$url,$have_class,$infor,$ret_r,$docode);
	$listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
	$changerow+=1;
	//超过行数
	if($changerow>$rownum)
	{
		$changerow=1;
		$string.=$listtext;
		$listtext=$list_r[1];
	}
	$no++;
}
//多余数据
if($changerow<=$rownum&&$listtext<>$list_r[1])
{
	$string.=$listtext;
}
if($num==0){
	$string='无任何信息';
}
$string=$list_r[0].$string.$list_r[2];
echo stripSlashes($string);
if($cache_r['open']){
	dp_HtmlCache(ob_get_contents(),'tagcache');
	ob_end_flush();
}
db_close();
$empire=null;
?>