<?php 
//生成静态类
/*
  首先读出风格文件,替换全局标签后,自动缓存到cache/temp/stylename/目录下.
  然后生成静态时直接读取缓存风格,加速生成.优化对数据库的负载.
  
*/
class htmlstr{
  var $dbz;
  var $urls;
  var $config = array();
  var $newsconfig = array();
  
  function htmlstr($str,$url){
    $this->dbz=$str;
	$this->urls=$url;
    $configs=openfile($url.'cache/config.txt');
	$this->config=split(",,",$configs);
	$newsconfigs=openfile($url.'cache/newsconfig.txt');
    $this->newsconfig=split(",,",$newsconfigs);
  }
  
  function classnames($id){
    $sql=query("select * from ".$this->dbz."class where id=$id");
    if($row=fetch($sql)){
	  return $row["names"];
	}
  }

  function globals($str){
    
    $strs=str_replace("{[c9:global name=title]}",$this->config[0],$str);
    $strs=str_replace("{[c9:global name=site]}",$this->config[1],$strs);
    $strs=str_replace("{[c9:global name=keywords]}",$this->config[2],$strs);
    $strs=str_replace("{[c9:global name=dis]}",$this->config[3],$strs);
    $strs=str_replace("{[c9:global name=style]}",$this->config[4],$strs);
    $strs=str_replace("{[c9:global name=end]}",$this->config[8],$strs);
    $strs=str_replace("{[c9:global name=tong]}",$this->config[9],$strs);
  //自定义标签
    //网站公告
	$gao=openfile($this->urls."cache/sitegao.txt");
	$strs=str_replace("{[c9:global name=gao]}",$gao,$strs);
  //广告
    $sqlad=query("select * from ".$this->dbz."ad order by id asc");
	while($rowad=fetch($sqlad)){
	  $codes=str_replace("\\","",$rowad["codes"]);
	  $strs=str_replace("{[c9:global ad=".$rowad["tags"]."]}",$codes,$strs);
	}
  //友情连接
    $linkimg='';
	$sqlimg=query("select * from ".$this->dbz."link where imgs<>'' order by orders desc");
	while($rowimg=fetch($sqlimg)){
	  $linkimg.="<a href='".$rowimg["urls"]."' target=_blank><img src=\"".$rowimg["imgs"]."\"></a> ";
	}
	$strs=str_replace("{[c9:link img]}",$linkimg,$strs);
	$linkstr='';
	$sqllink=query("select * from ".$this->dbz."link where imgs='' order by orders desc");
	while($rowlink=fetch($sqllink)){
	  $linkstr.="<a href='".$rowlink["urls"]."' target=_blank>".$rowlink["names"]."</a> ";
	}
	$strs=str_replace("{[c9:link url]}",$linkstr,$strs);
	
  //导航
    $indexvs='';
	$sqlvs=query("select * from ".$this->dbz."class where toplists=1 order by orders asc");
    while($rowvs=fetch($sqlvs)){
	  if($this->config[5]==1){$indexvsurl=$this->config[1]."/newslist/".$rowvs["id"].".htm";}else{$indexvsurl=$this->config[1]."/class.php?id=".$rowvs["id"];}
	  $indexvs.="<li><a href='$indexvsurl'>".$rowvs["names"]."</a></li>";
	}
	$strs=str_replace("{[c9:news toplist]}",$indexvs,$strs);
	//底部导航
	$ends='';
	$sqlends=query("select * from ".$this->dbz."page where ends=1 order by times desc");
	while($rowends=fetch($sqlends)){
	  $ends.="<a href=\"".$this->config[1]."/".$rowends["files"]."\">".$rowends["names"]."</a> ";
	}
	$strs=str_replace("{[c9:endlist]}",$ends,$strs);
	
	//搜索关键字
	$sostr='';
	$sqlso=query("select * from ".$this->dbz."so where hots=1 order by counts desc limit 0,".$this->config[10]);
	while($rowso=fetch($sqlso)){
	  $sostr.=" <a href=\"".$this->config[1]."/so.php?keys=".urlencode($rowso["keywords"])."\">".$rowso["keywords"]."</a> ";
	}
	$strs=str_replace("{[c9:so keywords]}",$sostr,$strs);
    return $strs;
  }
  //////////////////////////////////////////////////////////////////
  function indexs(){
    $indexurl=$this->urls."temp/".$this->config[4]."/index.htm";
    $indexstr=openfile($indexurl);
    $indexstr=$this->globals($indexstr);
    
	//信息分类循环开始
	$indextop='';
	$indexmid='';
	$indexend='';
	
	$toparr=explode("{[c9:while newsclass]}",$indexstr);
    if(count($toparr)>1){
	  $indextop=$toparr[0];
	  
	  $midarr=explode("{[/c9:while newsclass]}",$toparr[1]);
	  if(count($midarr)>1){
	     $indexmid=$midarr[0];
		 $indexend=$midarr[1];
		 
		 $indexmids='';
		 $indexmidstr='';
		 $sql=query("select * from ".$this->dbz."class where cid=0 and indexvs=1 order by orders asc");
		 while($row=fetch($sql)){
		   if($this->config[5]==1){
		     $indexmids=str_replace("{[c9:while class url]}",$this->config[1]."/newslist/".$row["id"],$indexmid);
		   }
		   else{
		     $indexmids=str_replace("{[c9:while class url]}",$this->config[1]."/class.php?id=".$row["id"],$indexmid);
		   }
		   $indexmids=str_replace("{[c9:while class name]}",$row["names"],$indexmids);
		   
		   //分类下信息循环开始
		   $newslist='';
		   
		   //显示置顶
		   $sqlnewsding=query("select * from ".$this->dbz."news where trees like '%:".$row["id"].":%' and tops=1 order by id desc limit 0,".$this->newsconfig[0]);
		   $newsi=0;
		   while($rownewsding=fetch($sqlnewsding)){
		     if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rownewsding["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rownewsding["id"];}
			 if($this->newsconfig[8]==1){$newsstyle="[<a href=\"".$this->config[1]."/class.php?id=".$rownewsding["cid"]."\">".$this->classnames($rownewsding["cid"])."</a>]";}else{$newsstyle='';}
			 if($this->newsconfig[9]==1){
			   if(date("m-d",strtotime($rownewsding["times"]))==date("m-d")){
			     $newstime="<font color=red>".date("m-d",strtotime($rownewsding["times"]))."</font>";
			   }
			   else{
			     $newstime=date("m-d",strtotime($rownewsding["times"]));
			   }
			 }else{$newstime='';}
			 
			 //if(){}else{}
		     $newslist.="<li>[<font color=red>顶</font>]$newsstyle<a href=\"$newsurl\" target=\"_blank\">".utf_substr($rownewsding["titles"],$this->newsconfig[6])."</a> $newstime</li>";
			 $newsi+=1;
		   }
		   //置顶结束
		   $sqlnews=query("select * from ".$this->dbz."news where trees like '%:".$row["id"].":%' order by id desc limit 0,".($this->newsconfig[0]-$newsi));
		   while($rownews=fetch($sqlnews)){
		     if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rownews["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rownews["id"];}
			 if($this->newsconfig[8]==1){$newsstyle="[<a href=\"".$this->config[1]."/class.php?id=".$rownews["cid"]."\">".$this->classnames($rownews["cid"])."</a>]";}else{$newsstyle='';}
			 if($this->newsconfig[9]==1){
			   if(date("m-d",strtotime($rownews["times"]))==date("m-d")){
			     $newstime="<font color=red>".date("m-d",strtotime($rownews["times"]))."</font>";
			   }
			   else{
			     $newstime=date("m-d",strtotime($rownews["times"]));
			   }
			 }else{$newstime='';}
			 
			 //if(){}else{}
		     $newslist.="<li>$newsstyle<a href=\"$newsurl\" target=\"_blank\">".utf_substr($rownews["titles"],$this->newsconfig[6])."</a> $newstime</li>";
		   }
		   $indexmids=str_replace("{[c9:while news]}",$newslist,$indexmids);
		   //分类下信息循环结束
		   $indexmidstr.=$indexmids;
		 }
		 $indexstr=$indextop.$indexmidstr.$indexend;
	  }
	}
	//信息分类循环结束
	
	//最近更新开始
	$strupdate='';
	$sqlupdate=query("select * from ".$this->dbz."news order by id desc limit 0,".$this->newsconfig[3]);
	while($rowupdate=fetch($sqlupdate)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowupdate["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowupdate["id"];}
	  $strupdate.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowupdate["titles"],$this->newsconfig[6])."</a></li>";
	}
    $indexstr=str_replace("{[c9:news update]}",$strupdate,$indexstr);
	//最近更新结束
	//推荐开始
	$strvip='';
	$sqlvip=query("select * from ".$this->dbz."news where vips=1 order by id desc limit 0,".$this->newsconfig[5]);
	while($rowvip=fetch($sqlvip)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowvip["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowvip["id"];}
	  $strvip.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowvip["titles"],$this->newsconfig[6])."</a></li>";
	}
    $indexstr=str_replace("{[c9:news vip]}",$strvip,$indexstr);
	//推荐结束
	//推荐开始
	$strhot='';
	$sqlhot=query("select * from ".$this->dbz."news where counts<>0 order by id desc limit 0,".$this->newsconfig[4]);
	while($rowhot=fetch($sqlhot)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowhot["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowhot["id"];}
	  $strhot.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowhot["titles"],$this->newsconfig[6])."</a></li>";
	}
    $indexstr=str_replace("{[c9:news hot]}",$strhot,$indexstr);
	//推荐结束
	
	//头条开始
	$sqlhead=query("select * from ".$this->dbz."news where headlines=1 order by id desc limit 0,1");
	if($rowhead=fetch($sqlhead)){
	  if($this->config[5]==1){$url=$this->config[1]."/news/".$rowhead["id"].".htm";}else{$url=$this->config[1]."/news.php?id=".$rowhead["id"];}
	  $indexstr=str_replace("{[c9:headlines]}","<a href=$url>".$rowhead["titles"]."</a>",$indexstr);
	  $indexstr=str_replace("{[c9:headlines dis]}",$rowhead["dis"],$indexstr);
	}
	//头条结束
	
	//幻灯片开始
	$slides=1;
	$slidestr='';
	$sqlhuan=query("select * from ".$this->dbz."news where slides=1 order by id desc limit 0,8");
	while($rowhuan=fetch($sqlhuan)){
	  if($this->config[5]==1){$url=$this->config[1]."/news/".$rowhuan["id"].".htm";}else{$url=$this->config[1]."/news.php?id=".$rowhuan["id"];}
	  $slidestr.="linkarr[$slides] = \"$url\";";
	  $slidestr.="picarr[$slides] = \"".$rowhuan["imgs"]."\";";
	  $slidestr.="textarr[$slides] = \"".$rowhuan["titles"]."\";";
	  $slides+=1;
	} 
	$indexstr=str_replace("{[c9:slides]}",$slidestr,$indexstr);
	//幻灯片结束
    return $indexstr;
  }
  /////////////////////////////////////////////////////////////
  function classstr($id){
    $sql=query("select * from ".$this->dbz."class where id=$id");
	if($rows=fetch($sql)){
	  $classurl=$this->urls."temp/".$rows["styles"]."/newsclass.htm";
	  $classstr=openfile($classurl);
	  $classstr=$this->globals($classstr);
	  
	  //信息分类循环开始
	$indextop='';
	$indexmid='';
	$indexend='';
	
	$toparr=explode("{[c9:while newsclass]}",$classstr);
    if(count($toparr)>1){
	  $indextop=$toparr[0];
	  
	  $midarr=explode("{[/c9:while newsclass]}",$toparr[1]);
	  if(count($midarr)>1){
	     $indexmid=$midarr[0];
		 $indexend=$midarr[1];
		 
		 $indexmids='';
		 $indexmidstr='';
		 $sql=query("select * from ".$this->dbz."class where cid=".$rows["id"]." order by orders asc");
		 while($row=fetch($sql)){
		   if($this->config[5]==1){
		     $indexmids=str_replace("{[c9:while class url]}",$this->config[1]."/newslist/".$row["id"],$indexmid);
		   }
		   else{
		     $indexmids=str_replace("{[c9:while class url]}",$this->config[1]."/class.php?id=".$row["id"],$indexmid);
		   }
		   $indexmids=str_replace("{[c9:while class name]}",$row["names"],$indexmids);
		   
		   //分类下信息循环开始
		   $newslist='';
		   
		   
		   $sqlnews=query("select * from ".$this->dbz."news where trees like '%:".$row["id"].":%' order by id desc limit 0,".$this->newsconfig[1]);
		   while($rownews=fetch($sqlnews)){
		     if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rownews["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rownews["id"];}
			 if($this->newsconfig[8]==1){$newsstyle="[<a href=\"".$this->config[1]."/class.php?id=".$rownews["cid"]."\">".$this->classnames($rownews["cid"])."</a>]";}else{$newsstyle='';}
			 if($this->newsconfig[9]==1){
			   if(date("m-d",strtotime($rownews["times"]))==date("m-d")){
			     $newstime="<font color=red>".date("m-d",strtotime($rownews["times"]))."</font>";
			   }
			   else{
			     $newstime=date("m-d",strtotime($rownews["times"]));
			   }
			 }else{$newstime='';}
			 
			 //if(){}else{}
		     $newslist.="<li>$newsstyle<a href=\"$newsurl\" target=\"_blank\">".utf_substr($rownews["titles"],$this->newsconfig[6])."</a> $newstime</li>";
		   }
		   $indexmids=str_replace("{[c9:while news]}",$newslist,$indexmids);
		   //分类下信息循环结束
		   $indexmidstr.=$indexmids;
		 }
		 $classstr=$indextop.$indexmidstr.$indexend;
	  }
	}
	//信息分类循环结束
	  //最近更新开始
	$strupdate='';
	$sqlupdate=query("select * from ".$this->dbz."news where trees like '%:".$rows["id"].":%' order by id desc limit 0,".$this->newsconfig[3]);
	while($rowupdate=fetch($sqlupdate)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowupdate["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowupdate["id"];}
	  $strupdate.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowupdate["titles"],$this->newsconfig[6])."</a></li>";
	}
    $classstr=str_replace("{[c9:news update]}",$strupdate,$classstr);
	//最近更新结束
	//推荐开始
	$strvip='';
	$sqlvip=query("select * from ".$this->dbz."news where trees like '%:".$rows["id"].":%' and vips=1 order by id desc limit 0,".$this->newsconfig[5]);
	while($rowvip=fetch($sqlvip)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowvip["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowvip["id"];}
	  $strvip.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowvip["titles"],$this->newsconfig[6])."</a></li>";
	}
    $classstr=str_replace("{[c9:news vip]}",$strvip,$classstr);
	//推荐结束
	//推荐开始
	$strhot='';
	$sqlhot=query("select * from ".$this->dbz."news where trees like '%:".$rows["id"].":%' and counts<>0 order by id desc limit 0,".$this->newsconfig[4]);
	while($rowhot=fetch($sqlhot)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowhot["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowhot["id"];}
	  $strhot.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowhot["titles"],$this->newsconfig[6])."</a></li>";
	}
    $classstr=str_replace("{[c9:news hot]}",$strhot,$classstr);
	//推荐结束
	 
	//分类导航
	$classtree=$rows["trees"];
	$classtrees=explode(":",$classtree);
	$classtreei=1;
	$classtreestr='';
	while($classtreei<(count($classtrees)-1)){
	  $sqltree=query("select * from ".$this->dbz."class where id=".$classtrees[$classtreei]);
	  if($rowtree=fetch($sqltree)){
	    if($this->config[5]==1){$url=$this->config[1]."/newslist/".$rowtree["id"].".htm";}else{$url=$this->config[1]."/class.php?id=".$rowtree["id"];}
	    $classtreestr.="<a href=\"$url\">".$rowtree["names"]."</a> >";
	  }
	  $classtreei+=1;
	}
	$classstr=str_replace("{[c9:newsclass add]}",$classtreestr,$classstr);
	
	$classstr=str_replace("{[c9:newsclass name]}",$rows["names"],$classstr);
	$classstr=str_replace("{[c9:newsclass keywords]}",$rows["keywords"],$classstr);
	$classstr=str_replace("{[c9:newsclass dis]}",$rows["dis"],$classstr);
	$classstr=str_replace("{[c9:newsclass style]}",$rows["styles"],$classstr);
	
	  return $classstr;
	}
  }
  
  function liststr($id,$page){
    $sql=query("select * from ".$this->dbz."class where id=$id");
	if($rows=fetch($sql)){
	  $listurl=$this->urls."temp/".$rows["styles"]."/newsclasslist.htm";
	  $liststr=openfile($listurl);
	  $liststr=$this->globals($liststr);
	  
	  //信息分类循环开始
	$indextop='';
	$indexmid='';
	$indexend='';
	
	$toparr=explode("{[c9:while newsclass]}",$liststr);
    if(count($toparr)>1){
	  $indextop=$toparr[0];
	  
	  $midarr=explode("{[/c9:while newsclass]}",$toparr[1]);
	  if(count($midarr)>1){
	     $indexmid=$midarr[0];
		 $indexend=$midarr[1];

		   //分类下信息循环开始
		   $newslist='';
		   $indexmids='';
		   $indexmidstr='';

		   $sqlnews=query("select * from ".$this->dbz."news where cid=".$rows["id"]." order by id desc limit ".($page*$this->newsconfig[2]).",".$this->newsconfig[2]);
		   while($rownews=fetch($sqlnews)){
		     if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rownews["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rownews["id"];}
			 $indexmids=str_replace("{[c9:news url]}",$newsurl,$indexmid);
			 $indexmids=str_replace("{[c9:news name]}",$rownews["titles"],$indexmids);
			 $indexmids=str_replace("{[c9:news count]}",$rownews["counts"],$indexmids);
			 $indexmids=str_replace("{[c9:news dis]}",$rownews["dis"],$indexmids);
			 $indexmids=str_replace("{[c9:news time]}",$rownews["times"],$indexmids);
			 $indexmids=str_replace("{[c9:news user]}",$rownews["users"],$indexmids);
			 $indexmids=str_replace("{[c9:news source]}",$rownews["sources"],$indexmids);
			 $indexmids=str_replace("{[c9:news img]}",$rownews["imgs"],$indexmids);
			 
			 $indexmidstr.=$indexmids;
		   }
		   //分类下信息循环结束
		   

		 $liststr=$indextop.$indexmidstr.$indexend;
	  }
	}
	//信息分类循环结束
	//$this->config[1]."/news/".$rowupdate["id"].".htm"
	//列表分页
	$lists='';
	$listnum=rows(query("select * from ".$this->dbz."news where cid=".$rows["id"]));
	$listnums=ceil($listnum/$this->newsconfig[2]);
	$lists.="当前:<font color=red>".($page+1)."</font>页 总:".$listnums."页";
	$listsi=1;
	if($this->config[5]==1){$lists.=" <a href=\"".$this->config[1]."/newslist/".$rows["id"].".htm\">1</a>";}
	else{$lists.= " <a href=\"".$this->config[1]."/class.php?id=".$rows["id"]."\">1</a>";}
	while($listsi<$listnums){
	  if($this->config[5]==1){$lists.=" <a href=\"".$this->config[1]."/newslist/".$rows["id"]."_".($listsi+1).".htm\">".($listsi+1)."</a>";}
	  else{$lists.= " <a href=\"".$this->config[1]."/class.php?id=".$rows["id"]."&page=".$listsi."\">".($listsi+1)."</a>";}
	  $listsi+=1;
	}
	$liststr=str_replace("{[c9:newslist]}",$lists,$liststr);
	//列表分页结束
	  //最近更新开始
	$strupdate='';
	$sqlupdate=query("select * from ".$this->dbz."news where cid=".$rows["id"]." order by id desc limit 0,".$this->newsconfig[3]);
	while($rowupdate=fetch($sqlupdate)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowupdate["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowupdate["id"];}
	  $strupdate.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowupdate["titles"],$this->newsconfig[6])."</a></li>";
	}
    $liststr=str_replace("{[c9:news update]}",$strupdate,$liststr);
	//最近更新结束
	//推荐开始
	$strvip='';
	$sqlvip=query("select * from ".$this->dbz."news where cid=".$rows["id"]." and vips=1 order by id desc limit 0,".$this->newsconfig[5]);
	while($rowvip=fetch($sqlvip)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowvip["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowvip["id"];}
	  $strvip.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowvip["titles"],$this->newsconfig[6])."</a></li>";
	}
    $liststr=str_replace("{[c9:news vip]}",$strvip,$liststr);
	//推荐结束
	//推荐开始
	$strhot='';
	$sqlhot=query("select * from ".$this->dbz."news where cid=".$rows["id"]." and counts<>0 order by id desc limit 0,".$this->newsconfig[4]);
	while($rowhot=fetch($sqlhot)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowhot["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowhot["id"];}
	  $strhot.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowhot["titles"],$this->newsconfig[6])."</a></li>";
	}
    $liststr=str_replace("{[c9:news hot]}",$strhot,$liststr);
	//推荐结束
	  
	$classtree=$rows["trees"];
	$classtrees=explode(":",$classtree);
	$classtreei=1;
	$classtreestr='';
	while($classtreei<(count($classtrees)-1)){
	  $sqltree=query("select * from ".$this->dbz."class where id=".$classtrees[$classtreei]);
	  if($rowtree=fetch($sqltree)){
	    if($this->config[5]==1){$url=$this->config[1]."/newslist/".$rowtree["id"].".htm";}else{$url=$this->config[1]."/class.php?id=".$rowtree["id"];}
	    $classtreestr.="<a href=\"$url\">".$rowtree["names"]."</a> >";
	  }
	  $classtreei+=1;
	}
	$liststr=str_replace("{[c9:newsclass add]}",$classtreestr,$liststr);
	
	$liststr=str_replace("{[c9:newsclass name]}",$rows["names"],$liststr);
	$liststr=str_replace("{[c9:newsclass keywords]}",$rows["keywords"],$liststr);
	$liststr=str_replace("{[c9:newsclass dis]}",$rows["dis"],$liststr);
	$liststr=str_replace("{[c9:newsclass style]}",$rows["styles"],$liststr);
	  
	  return $liststr;
	}
  }
  
  function newstr($id,$page){
    $sql=query("select * from ".$this->dbz."news where id=$id");
	if($rows=fetch($sql)){
	  $newurl=$this->urls."temp/".$this->config[4]."/news.htm";
	  $newstr=openfile($newurl);
	  $newstr=$this->globals($newstr);
	  
	  //最近更新开始
	$strupdate='';
	$sqlupdate=query("select * from ".$this->dbz."news where cid=".$rows["cid"]." order by id desc limit 0,".$this->newsconfig[3]);
	while($rowupdate=fetch($sqlupdate)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowupdate["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowupdate["id"];}
	  $strupdate.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowupdate["titles"],$this->newsconfig[6])."</a></li>";
	}
    $newstr=str_replace("{[c9:news update]}",$strupdate,$newstr);
	//最近更新结束
	//推荐开始
	$strvip='';
	$sqlvip=query("select * from ".$this->dbz."news where cid=".$rows["cid"]." and vips=1 order by id desc limit 0,".$this->newsconfig[5]);
	while($rowvip=fetch($sqlvip)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowvip["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowvip["id"];}
	  $strvip.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowvip["titles"],$this->newsconfig[6])."</a></li>";
	}
    $newstr=str_replace("{[c9:news vip]}",$strvip,$newstr);
	//推荐结束
	//推荐开始
	$strhot='';
	$sqlhot=query("select * from ".$this->dbz."news where cid=".$rows["cid"]." and counts<>0 order by id desc limit 0,".$this->newsconfig[4]);
	while($rowhot=fetch($sqlhot)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowhot["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowhot["id"];}
	  $strhot.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowhot["titles"],$this->newsconfig[6])."</a></li>";
	}
    $newstr=str_replace("{[c9:news hot]}",$strhot,$newstr);
	//推荐结束
	  $newstr=str_replace("{[c9:news id]}",$rows["id"],$newstr);
	  $newstr=str_replace("{[c9:news name]}",$rows["titles"],$newstr);
	  $newstr=str_replace("{[c9:news keywords]}",$rows["keywords"],$newstr);
	  $newstr=str_replace("{[c9:news dis]}",$rows["dis"],$newstr);
	  $newstr=str_replace("{[c9:news user]}",$rows["users"],$newstr);
	  $newstr=str_replace("{[c9:news source]}",$rows["sources"],$newstr);
	  $newstr=str_replace("{[c9:news time]}",$rows["times"],$newstr);
	  $newstr=str_replace("{[c9:news img]}",$rows["imgs"],$newstr);
	  
	  $newsmg=explode("{[c9:pagelist]}",$rows["mg"]);
	  if(count($newsmg)==1){
	    $newsmgs=$newsmg[0];
	  }
	  else{
	    $newsmgs=$newsmg[$page];
	  }
	  
	  //上下篇
	  $sqlshang=query("select * from ".$this->dbz."news where id<$id order by id desc limit 0,1");
	  if($rowshang=fetch($sqlshang)){$newsmgs.="上一篇: <a href=\"news.php?id=".$rowshang["id"]."\">".$rowshang["titles"]."</a><br />";}else{$newsmgs.="上一篇: 没有了";}
	  $sqlxia=query("select * from ".$this->dbz."news where id>$id order by id asc limit 0,1");
	  if($rowxia=fetch($sqlxia)){$newsmgs.="下一篇: <a href=\"news.php?id=".$rowxia["id"]."\">".$rowxia["titles"]."</a><br />";}else{$newsmgs.="下一篇: 没有了";}
	 
	  //上下篇结束
	  
	  $newstr=str_replace("{[c9:news mg]}",$newsmgs,$newstr);
	  
	  if(count($newsmg)>1){
	    if($this->config[5]==1){$newslist="信息分页: <a href=\"".$this->config[1]."/news/".$id.".htm\">1</a>";}
		else{$newslist="信息分页: <a href=\"".$this->config[1]."/news.php?id=".$id."\">1</a>";}
		$newslisti=1;
		while($newslisti<count($newsmg)){
		  if($this->config[5]==1){$newslist.=" <a href=\"".$this->config[1]."/news/".$id."_".($newslisti+1).".htm\">".($newslisti+1)."</a>";}
		  else{$newslist.=" <a href=\"".$this->config[1]."/news.php?id=".$id."&page=".$newslisti."\">".($newslisti+1)."</a>";}
		  $newslisti+=1;
		}
		$newstr=str_replace("{[c9:news list]}",$newslist,$newstr);
	  }
	  else{$newstr=str_replace("{[c9:news list]}","",$newstr);}
	  
	$classtree=$rows["trees"];
	$classtrees=explode(":",$classtree);
	$classtreei=1;
	$classtreestr='';
	while($classtreei<(count($classtrees)-1)){
	  $sqltree=query("select * from ".$this->dbz."class where id=".$classtrees[$classtreei]);
	  if($rowtree=fetch($sqltree)){
	    if($this->config[5]==1){$url=$this->config[1]."/newslist/".$rowtree["id"].".htm";}else{$url=$this->config[1]."/class.php?id=".$rowtree["id"];}
	    $classtreestr.="<a href=\"$url\">".$rowtree["names"]."</a> >";
	  }
	  $classtreei+=1;
	}
	$newstr=str_replace("{[c9:news add]}",$classtreestr,$newstr);
	  
	  
	  return $newstr;
	}
  }
  
  function pagestr($id){
    $sql=query("select * from ".$this->dbz."page where id=$id");
	if($rows=fetch($sql)){
	  $pageurl=$this->urls."temp/".$this->config[4]."/page.htm";
	  $pagestr=openfile($pageurl);
	  $pagestr=$this->globals($pagestr);
	  
	  //最近更新开始
	$strupdate='';
	$sqlupdate=query("select * from ".$this->dbz."news order by id desc limit 0,".$this->newsconfig[3]);
	while($rowupdate=fetch($sqlupdate)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowupdate["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowupdate["id"];}
	  $strupdate.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowupdate["titles"],$this->newsconfig[6])."</a></li>";
	}
    $pagestr=str_replace("{[c9:news update]}",$strupdate,$pagestr);
	//最近更新结束
	//推荐开始
	$strvip='';
	$sqlvip=query("select * from ".$this->dbz."news where vips=1 order by id desc limit 0,".$this->newsconfig[5]);
	while($rowvip=fetch($sqlvip)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowvip["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowvip["id"];}
	  $strvip.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowvip["titles"],$this->newsconfig[6])."</a></li>";
	}
    $pagestr=str_replace("{[c9:news vip]}",$strvip,$pagestr);
	//推荐结束
	//推荐开始
	$strhot='';
	$sqlhot=query("select * from ".$this->dbz."news where counts<>0 order by id desc limit 0,".$this->newsconfig[4]);
	while($rowhot=fetch($sqlhot)){
	  if($this->config[5]==1){$newsurl=$this->config[1]."/news/".$rowhot["id"].".htm";}else{$newsurl=$this->config[1]."/news.php?id=".$rowhot["id"];}
	  $strhot.="<li><a href=\"$newsurl\" target=\"_blank\">".utf_substr($rowhot["titles"],$this->newsconfig[6])."</a></li>";
	}
    $pagestr=str_replace("{[c9:news hot]}",$strhot,$pagestr);
	//推荐结束
	  
	  $pagestr=str_replace("{[c9:page name]}",$rows["names"],$pagestr);
	  $pagestr=str_replace("{[c9:page file]}",$this->config[1]."/".$rows["files"],$pagestr);
	  $pagestr=str_replace("{[c9:page keywords]}",$rows["keywords"],$pagestr);
	  $pagestr=str_replace("{[c9:page dis]}",$rows["dis"],$pagestr);
	  $pagestr=str_replace("{[c9:page mg]}",$rows["mg"],$pagestr);
	  
	  return $pagestr;
	}
  }
  
}
?>