inc_archives_view.php

来自「强大的PHP内容管理系统尽量不要让站长把时间都花费在为您修正说明上。压缩包解压」· PHP 代码 · 共 677 行 · 第 1/2 页

PHP
677
字号
<?php
require_once(dirname(__FILE__)."/inc_arcpart_view.php");
require_once(dirname(__FILE__)."/inc_downclass.php");
require_once(dirname(__FILE__)."/inc_channel_unit.php");
require_once(dirname(__FILE__)."/inc_pubtag_make.php");
/******************************************************
//Copyright 2004-2008 by DedeCms.com itprato
//本类的用途是用于浏览文档或对文档生成HTML
******************************************************/
@set_time_limit(0);
class Archives
{
	var $TypeLink;
	var $ChannelUnit;
	var $dsql;
	var $Fields;
	var $dtp;
	var $ArcID;
	var $SplitPageField;
	var $SplitFields;
	var $NowPage;
	var $TotalPage;
	var $NameFirst;
	var $ShortName;
	var $FixedValues;
	var $PartView;
	var $TempSource;
	var $IsError;
	var $SplitTitles;
	var $MemberInfos;
	var $MainTable;
	var $AddTable;
	var $PreNext;
	var $TempletsFile;
	var $fullurl;
	//-------------------------------
	//php5构造函数
	//-------------------------------
	function __construct($aid)
 	{
 		global $PubFields;
 		$t1 = ExecTime();
 		$this->IsError = false;
 		$this->dsql = new DedeSql(false);
 		$this->ArcID = $aid;
 		$this->MemberInfos = array();
 		$this->PreNext = array();
 		$this->TempletsFile = '';
 		$this->MainTable = '';
 		$this->fullurl = '';
 		
    //获取文档表信息
    $fullsearchs = $this->dsql->GetOne("select c.ID as channelid,c.maintable,c.addtable,a.keywords,a.url from `#@__full_search` a left join  #@__channeltype c on  c.ID = a.channelid where a.aid='$aid'",MYSQL_ASSOC);
    if($fullsearchs['channelid']==-1)
    {
       $this->MainTable = '#@__archivesspec';
 		   $this->AddTable = '#@__addonspec';
 		}else
 		{
 		   if($fullsearchs['maintable']=='') $fullsearchs['maintable']='#@__archives';
 		   $this->MainTable = $fullsearchs['maintable'];
 		   $this->AddTable = $fullsearchs['addtable'];
 		}

 		$query = "Select arc.*,sm.name as smalltypename,tp.reID,tp.typedir,tp.typename,am.uname from `{$this->MainTable}` arc
 		          left join #@__arctype tp on tp.ID=arc.typeid
 		          left join #@__smalltypes sm on sm.id=arc.smalltypeid
 		          left join #@__admin am on arc.adminID = am.ID 
 		          where arc.ID='$aid'";
 		$row = $this->dsql->GetOne($query,MYSQL_ASSOC);

 		//无法获取记录
 		if(!is_array($row)){
 			$this->IsError = true;
 			return;
 	  }
 		//把主表记录转换为Field
 		foreach($row as $k=>$v) $this->Fields[$k] = $v;
 		$this->Fields['keywords'] = $fullsearchs['keywords'];
 		$this->fullurl = $fullsearchs['url'];
 		unset($row);
 		unset($fullsearchs);
 		if($this->Fields['redirecturl']!="") return;

 		//模板引擎与页面环境初始化
 		$this->ChannelUnit = new ChannelUnit($this->Fields['channel'],$aid);
 		$this->TypeLink = new TypeLink($this->Fields['typeid']);
 		$this->dtp = new DedeTagParse();
 		$this->SplitPageField = $this->ChannelUnit->SplitPageField;
 		$this->SplitFields = "";
 		$this->TotalPage = 1;
 		$this->NameFirst = "";
 		$this->ShortName = "html";
 		$this->FixedValues = "";
 		$this->TempSource = "";
 		$this->PartView = new PartView($this->Fields['typeid']);

 		if(empty($GLOBALS["pageno"])) $this->NowPage = 1;
 		else $this->NowPage = intval($GLOBALS["pageno"]);

 		//特殊的字段Field数据处理
 		$this->Fields['aid'] = $aid;
 		$this->Fields['id'] = $aid;
 		$this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
 		//设置一些全局参数的值
 		foreach($PubFields as $k=>$v) $this->Fields[$k] = $v;
 		if($this->Fields['litpic']=="") $this->Fields['litpic'] = $this->Fields["phpurl"]."/img/dfpic.gif";

 		//读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在
 		//模板中用 {dede:field name='fieldname' /} 标记统一调用
 		if($this->AddTable!="")
 		{
 		  $row = $this->dsql->GetOne("select * from ".trim($this->ChannelUnit->ChannelInfos["addtable"])." where aid=$aid ");
 		  if(is_array($row)) foreach($row as $k=>$v){ if(ereg("[A-Z]",$k)) $row[strtolower($k)] = $v; }
 		  foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
 		  {
 		  	if(isset($row[$k]))
 		  	{
 		  		 if($arr["rename"]!="") $nk = $arr["rename"];
 		  		 else $nk = $k;
 		  		 $this->Fields[$nk] = $this->ChannelUnit->MakeField($k,$row[$k]);
 		  		 if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y'){
 		  			 $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'],$this->Fields[$nk]);
 		  		 }
 		  	}
 		  }//End foreach
 		}
 		unset($row);

 		//处理要分页显示的字段
 		//---------------------------
 		$this->SplitTitles = Array();
 		if($this->SplitPageField!="" && $GLOBALS['cfg_arcsptitle']='Y' &&
 		 isset($this->Fields[$this->SplitPageField]))
 	  {
 			$this->SplitFields = explode("#p#",$this->Fields[$this->SplitPageField]);
 			$i = 1;
 			foreach($this->SplitFields as $k=>$v)
 			{
 				$tmpv = cn_substr($v,50);
 				$pos = strpos($tmpv,'#e#');
 				if($pos>0)
 				{
 					 $st = trim(cn_substr($tmpv,$pos));
 					 if($st==""||$st=="副标题"||$st=="分页标题"){
 						 $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
 						 continue;
 					 }else{
 						 $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is","",$v);
 						 $this->SplitTitles[$k] = $st;
 				   }
 				}else{
 					continue;
 				}
 				$i++;
 			}
 			$this->TotalPage = count($this->SplitFields);
 		}
 		$this->Fields['totalpage'] = $this->TotalPage;
 	}
 	//php4构造函数
 	//---------------------------
 	function Archives($aid){
 		$this->__construct($aid);
 	}
 	//----------------------------
  //生成静态HTML
  //----------------------------
  function MakeHtml()
  {
  	//读取模型信息错误
  	if($this->IsError) return '';
  	
  	$this->Fields["displaytype"] = "st";
  	
  	//分析要创建的文件名称
  	//------------------------------------------------------
  	if(!is_object($this->TypeLink)) $this->TypeLink = new TypeLink($this->Fields["typeid"]);
  	$filename = $this->TypeLink->GetFileNewName(
  	  $this->ArcID,$this->Fields["typeid"],$this->Fields["senddate"],
  	  $this->Fields["title"],$this->Fields["ismake"],
  	  $this->Fields["arcrank"],$this->TypeLink->TypeInfos['namerule'],$this->TypeLink->TypeInfos['typedir'],$this->Fields["money"],
  	  $this->TypeLink->TypeInfos['siterefer'],
  	  $this->TypeLink->TypeInfos['sitepath']
  	);
  	$filenames  = explode(".",$filename);
  	$this->ShortName = $filenames[count($filenames)-1];
  	if($this->ShortName=="") $this->ShortName = "html";
  	$fileFirst = eregi_replace("\.".$this->ShortName."$","",$filename);
  	
  	//对于已设置不生成HTML的文章直接返回网址
  	//------------------------------------------------
  	if($this->Fields['ismake']==-1||$this->Fields['arcrank']!=0||
  	   $this->Fields['typeid']==0||$this->Fields['money']>0)
  	{
  		return $this->GetTrueUrl($filename);
  	}
  	//跳转网址
  	else if($this->Fields['redirecturl']!='')
  	{
  		$truefilename = $this->GetTruePath().$fileFirst.".".$this->ShortName;
  		$tffp = fopen(dirname(__FILE__)."/../include/jump.html","r");
  		$tmpfile = fread($tffp,filesize(dirname(__FILE__)."/../include/jump.html"));
  		fclose($tffp);
  		$tmpfile = str_replace('[title]',$this->Fields['title'],$tmpfile);
  		$tmpfile = str_replace('[aid]',$this->Fields['ID'],$tmpfile);
  		$tmpfile = str_replace('[description]',$this->Fields['description'],$tmpfile);
  		$tmpfile = str_replace('[redirecturl]',$this->Fields['redirecturl'],$tmpfile);
  		$fp = @fopen($truefilename,"w") or die("Create File False:$filename");
		  fwrite($fp,$tmpfile);
		  fclose($fp);
		  return $this->GetTrueUrl($filename);
  	}

  	$filenames  = explode("/",$filename);
  	$this->NameFirst = eregi_replace("\.".$this->ShortName."$","",$filenames[count($filenames)-1]);
  	if($this->NameFirst=="") $this->NameFirst = $this->arcID;
  	//获得当前文档的全名
  	$filenameFull = $filename;
  	if(!eregi('http://',$filenameFull)) $filenameFull = $GLOBALS['cfg_basehost'].$filenameFull;
  	$this->Fields['arcurl'] = $filenameFull;
  	$this->Fields['fullname'] = $this->Fields['arcurl'];
  	//载入模板
  	$this->LoadTemplet();
  	
  	//循环生成HTML文件
    for($i=1;$i<=$this->TotalPage;$i++){
  	     if($i>1){ $truefilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName; }
  	     else{ $truefilename = $this->GetTruePath().$filename; }
  	     $this->Fields['namehand'] = $fileFirst;
  	     $this->ParseDMFields($i,1);
  	     $this->dtp->SaveTo($truefilename);
    }
    $this->dsql->SetQuery("Update `{$this->MainTable}` set ismake=1 where ID='".$this->ArcID."'");
    $this->dsql->ExecuteNoneQuery();
  	return $this->GetTrueUrl($filename);
  }
  //----------------------------
 	//获得真实连接路径
 	//----------------------------
 	function GetTrueUrl($nurl)
 	{
 		
 		if($GLOBALS['cfg_multi_site']=='Y' && !eregi('php\?',$nurl)){
 			if($this->TypeLink->TypeInfos['siteurl']=="") $nsite = $GLOBALS["cfg_mainsite"];
 			else $nsite = $this->TypeLink->TypeInfos['siteurl'];
 			$nurl = ereg_replace("/$","",$nsite).$nurl;
 		}
 		if($nurl != $this->fullurl){
 			$this->dsql->SetQuery("update #@__full_search set url='$nurl' where aid='$this->ArcID'");
 			$this->dsql->ExecuteNoneQuery();
 		}
 		return $nurl;
 	}
 	//----------------------------
 	//获得站点的真实根路径
 	//----------------------------
 	function GetTruePath()
 	{
 		if($GLOBALS['cfg_multi_site']=='Y'){
 		   if($this->TypeLink->TypeInfos['siterefer']==1) $truepath = ereg_replace("/{1,}","/",$GLOBALS["cfg_basedir"]."/".$this->TypeLink->TypeInfos['sitepath']);
	     else if($this->TypeLink->TypeInfos['siterefer']==2) $truepath = $this->TypeLink->TypeInfos['sitepath'];
	     else $truepath = $GLOBALS["cfg_basedir"];
	  }else{
	  	$truepath = $GLOBALS["cfg_basedir"];
	  }
	  return $truepath;
 	}
  //----------------------------
  //获得指定键值的字段
  //----------------------------
  function GetField($fname)
  {
  	if(isset($this->Fields[$fname])) return $this->Fields[$fname];
  	else return "";
  }
  //-----------------------------
  //获得模板文件位置
  //-----------------------------
  function GetTempletFile()
  {
 	  global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
 	  $cid = $this->ChannelUnit->ChannelInfos["nid"];
 	  if($this->Fields['templet']!=''){ $filetag = MfTemplet($this->Fields['templet']); }
 	  else{ $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]); }
 	  $tid = $this->Fields["typeid"];
 	  $filetag = str_replace("{cid}",$cid,$filetag);
 	  $filetag = str_replace("{tid}",$tid,$filetag);
 	  $tmpfile = $cfg_basedir.$cfg_templets_dir."/".$filetag;
 	  if($cid=='spec'){
 	  	if($this->Fields['templet']!=''){ $tmpfile = $cfg_basedir.$cfg_templets_dir."/".MfTemplet($this->Fields['templet']); }
 	  	else $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
 	  }
 	  if(!file_exists($tmpfile)) $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_default.htm";
 	  return $tmpfile;
  }
  //----------------------------
 	//动态输出结果
 	//----------------------------
 	function display()
 	{

 		//读取模型信息错误
 		if($this->IsError) return '';
 		$this->LoadTemplet();
 		//跳转网址
  	if($this->Fields['redirecturl']!='')
  	{
  		$tffp = fopen(dirname(__FILE__)."/../include/jump.html","r");
  		$tmpfile = fread($tffp,filesize(dirname(__FILE__)."/../include/jump.html"));
  		fclose($tffp);
  		$tmpfile = str_replace('[title]',$this->Fields['title'],$tmpfile);
  		$tmpfile = str_replace('[aid]',$this->Fields['ID'],$tmpfile);
  		$tmpfile = str_replace('[description]',$this->Fields['description'],$tmpfile);
  		$tmpfile = str_replace('[redirecturl]',$this->Fields['redirecturl'],$tmpfile);
  		echo $tmpfile;
		  return '';
  	}
 		$this->Fields["displaytype"] = "dm";
 	  $this->Fields['arcurl'] = $GLOBALS['cfg_phpurl']."/plus.php?aid=".$this->Fields['ID'];
 	  $pageCount = $this->NowPage;
 	  $this->ParseDMFields($pageCount,0);
  	$this->dtp->display();
 	}
 	//--------------
 	//载入模板
 	//--------------
 	function LoadTemplet()
 	{
 		global $cfg_basedir;
 		if($this->TempSource=='')
 		{
 			$tempfile = $this->GetTempletFile();
 		  if(!file_exists($tempfile)||!is_file($tempfile)){
 			  return false;
 		  }
 		  $this->dtp->LoadTemplate($tempfile);
 		  $this->TempSource = $this->dtp->SourceString;
 		  $this->ParseTempletsFirst();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?