⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arc.archives.class.php

📁 这是matlab的一个小程序
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
if(!defined('DEDEINC'))
{
	exit("Request Error!");
}
require_once(DEDEINC."/typelink.class.php");
require_once(DEDEINC."/channelunit.class.php");
require_once(DEDEINC."/downmix.inc.php");

@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 $TempSource;
	var $IsError;
	var $SplitTitles;
	var $PreNext;
	var $addTableRow;

	//php5构造函数
	function __construct($aid)
	{
		global $dsql;
		$this->IsError = false;
		$this->ArcID = $aid;
		$this->PreNext = array();

		$this->dsql = $dsql;
		$query = "Select channel,typeid from `#@__arctiny` where id='$aid' ";
		$arr = $this->dsql->GetOne($query);
		if(!is_array($arr))
		{
			$this->IsError = true;
		}
		else
		{
			if($arr['channel']==0)
			{
				$arr['channel']=1;
			}
			$this->ChannelUnit = new ChannelUnit($arr['channel'],$aid);
			$this->TypeLink = new TypeLink($arr['typeid']);
			if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
			{
				$query = "Select arc.*,tp.reid,tp.typedir,ch.addtable
				from `#@__archives` arc
 		        		left join #@__arctype tp on tp.id=arc.typeid
 		         		left join #@__channeltype as ch on arc.channel = ch.id
 		         		where arc.id='$aid' ";
				$this->Fields = $this->dsql->GetOne($query);
			}
			else
			{
				$this->Fields['title'] = '';
				$this->Fields['money'] = $this->Fields['arcrank'] = 0;
				$this->Fields['senddate'] = $this->Fields['pubdate'] = $this->Fields['mid'] = $this->Fields['adminid'] = 0;
				$this->Fields['ismake'] = 1;
				$this->Fields['filename'] = '';
			}

			if($this->TypeLink->TypeInfos['corank'] > 0 && $this->Fields['arcrank']==0)
			{
				$this->Fields['arcrank'] = $this->TypeLink->TypeInfos['corank'];
			}

			$this->Fields['tags'] = GetTags($aid);
			$this->dtp = new DedeTagParse();
			$this->dtp->refObj = $this;
			$this->SplitPageField = $this->ChannelUnit->SplitPageField;
			$this->SplitFields = '';
			$this->TotalPage = 1;
			$this->NameFirst = '';
			$this->ShortName = 'html';
			$this->FixedValues = '';
			$this->TempSource = '';
			if(empty($GLOBALS["pageno"]))
			{
				$this->NowPage = 1;
			}
			else
			{
				$this->NowPage = $GLOBALS["pageno"];
			}

			//特殊的字段数据处理
			$this->Fields['aid'] = $aid;
			$this->Fields['id'] = $aid;
			$this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
			$this->Fields['typeid'] = $arr['typeid'];

			//设置一些全局参数的值
			foreach($GLOBALS['PubFields'] as $k=>$v)
			{
				$this->Fields[$k] = $v;
			}

			if(empty($this->Fields['litpic']))
			{
				$this->Fields['litpic'] = $this->Fields["phpurl"]."/img/dfpic.gif";
			}
			else
			{
				$this->Fields['litpic'] = $GLOBALS['cfg_multi_site'] == 'Y' ? $GLOBALS['cfg_mainsite'].$this->Fields['litpic'] : $this->Fields['litpic'];
			}

			//digg
			if($this->Fields['goodpost'] + $this->Fields['badpost'] == 0)
			{
				$this->Fields['goodper'] = $this->Fields['badper'] = 0;
			}
			else
			{
				$this->Fields['goodper'] = number_format($this->Fields['goodpost']/($this->Fields['goodpost']+$this->Fields['badpost']), 3)*100;
				$this->Fields['badper'] = 100 - $this->Fields['goodper'];
			}

			//为了减少重复查询,这里直接把附加表查询记录放在 $this->addTableRow 中,在 ParAddTable() 不再查询
			if($this->ChannelUnit->ChannelInfos['addtable']!='')
			{
				$query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}`WHERE `aid` = '$aid'";
				$this->addTableRow = $this->dsql->GetOne($query);
			}

			//issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
			if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
			{
				if(is_array($this->addTableRow))
				{
					$this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
					$this->Fields['templet'] = $this->addTableRow['templet'];
					$this->Fields['userip'] = $this->addTableRow['userip'];
				}
				$this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
				$this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
				$this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
			}
			else
			{
				$this->Fields['templet'] = $this->Fields['redirecturl'] = '';
			}
		}//!error
	}

	//php4构造函数
	function Archives($aid)
	{
		$this->__construct($aid);
	}

	//解析附加表的内容
	function ParAddTable()
	{
		//读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用 {dede:field name='fieldname' /} 标记统一调用
		if($this->ChannelUnit->ChannelInfos['addtable']!='')
		{
			$row = $this->addTableRow;
			if($this->ChannelUnit->ChannelInfos['issystem']==-1)
			{
				$this->Fields['title'] = $row['title'];
				$this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
				$this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
				$this->Fields['ismake'] = 1;
				$this->Fields['arcrank'] = 0;
				$this->Fields['money']=0;
				$this->Fields['filename'] = '';
			}

			if(is_array($row))
			{
				foreach($row as $k=>$v) $row[strtolower($k)] = $v;
			}
			if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
			{
				foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
				{
					if(isset($row[$k]))
					{
						if(!empty($arr['rename']))
						{
							$nk = $arr['rename'];
						}
						else
						{
							$nk = $k;
						}
						$cobj = $this->GetCurTag($k);
						if(is_object($cobj))
						{
							$this->Fields[$nk] = $this->ChannelUnit->MakeField($k,$row[$k],$this->GetCurTag($k));
						}
						else
						{
							$this->Fields[$nk] = $row[$k];
						}
						if($arr['type']=='htmltext' && $GLOBALS['cfg_keyword_replace']=='Y' && !empty($this->Fields['keywords']))
						{
							$this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'],$this->Fields[$nk]);
						}
					}
				}//End foreach
			}
			//设置全局环境变量
			$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
			SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');
		}
		//完成附加表信息读取
		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);
		}
	}

	//获得当前字段参数
	function GetCurTag($fieldname)
	{
		if(!isset($this->dtp->CTags))
		{
			return '';
		}
		foreach($this->dtp->CTags as $ctag)
		{
			if($ctag->GetTagName()=='field' && $ctag->GetAtt('name')==$fieldname)
			{
				return $ctag;
			}
			else
			{
				continue;
			}
		}
		return '';
	}

	//生成静态HTML
	function MakeHtml()
	{
		if($this->IsError)
		{
			return '';
		}

		//预编译$th
		$this->LoadTemplet();
		$this->ParAddTable();
		$this->ParseTempletsFirst();

		//分析要创建的文件名称
		$filename = 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->Fields['filename']
		);

		$filenames  = explode(".",$filename);
		$this->ShortName = $filenames[count($filenames)-1];
		if($this->ShortName=="")
		{
			$this->ShortName = "html";
		}
		$fileFirst = eregi_replace("\.".$this->ShortName."$","",$filename);
		$filenames  = explode("/",$filename);
		$this->NameFirst = eregi_replace("\.".$this->ShortName."$","",$filenames[count($filenames)-1]);
		if($this->NameFirst=="")
		{
			$this->NameFirst = $this->arcID;
		}

		//获得当前文档的全名
		$filenameFull = GetFileUrl(
		$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->Fields['filename'],
		$this->TypeLink->TypeInfos['moresite'],$this->TypeLink->TypeInfos['siteurl'],$this->TypeLink->TypeInfos['sitepath']
		);
		$this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;

		//对于已设置不生成HTML的文章直接返回网址
		if($this->Fields['ismake']==-1||$this->Fields['arcrank']!=0||
		$this->Fields['typeid']==0||$this->Fields['money']>0)
		{
			return $this->GetTrueUrl($filename);
		}

		//跳转网址
		if($this->Fields['redirecturl']!='')
		{
			$truefilename = $this->GetTruePath().$fileFirst.".".$this->ShortName;
			$pageHtml = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n<title>转向:".$this->Fields['title']."</title>\n";
			$pageHtml .= "<meta http-equiv=\"refresh\" content=\"1;URL=".$this->Fields['redirecturl']."\">\n</head>\n<body>\n";
			$pageHtml .= "现在正在转向:".$this->Fields['title'].",请稍候...<br/><br/>\n转向内容简介:".$this->Fields['description']."\n</body>\n</html>\n";
			$fp = @fopen($truefilename,"w") or die("Create File False:$filename");
			fwrite($fp,$pageHtml);
			fclose($fp);
		}

		//循环生成HTML文件
		else
		{
			for($i=1;$i<=$this->TotalPage;$i++)
			{
				if($i>1)
				{
					$truefilename = $this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;
				}
				else
				{
					$truefilename = $this->GetTruePath().$filename;
				}
				$this->ParseDMFields($i,1);
				$this->dtp->SaveTo($truefilename);
			}
		}
		$this->dsql->ExecuteNoneQuery("Update `#@__archives` set ismake=1 where id='".$this->ArcID."'");
		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;
		}
		return $nurl;
	}

	//获得站点的真实根路径
	function GetTruePath()
	{
		$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(!empty($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();
		$this->ParAddTable();

		$this->ParseTempletsFirst();

		//跳转网址
		if($this->Fields['redirecturl']!="")
		{
			global $fileFirst;
			$truefilename = $this->GetTruePath().$fileFirst.".".$this->ShortName;
			$pageHtml = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n<title>转向:".$this->Fields['title']."</title>\n";
			$pageHtml .= "<meta http-equiv=\"refresh\" content=\"1;URL=".$this->Fields['redirecturl']."\">\n</head>\n<body>\n";
			$pageHtml .= "现在正在转向:".$this->Fields['title'].",请稍候...<br/><br/>\n转向内容简介:\n".$this->Fields['description']."\n</body>\n</html>\n";
			echo $pageHtml;
			exit();
		}
		$pageCount = $this->NowPage;
		$this->ParseDMFields($pageCount,0);
		$this->dtp->display();
	}

	//载入模板
	function LoadTemplet()
	{
		if($this->TempSource=='')
		{
			$tempfile = $this->GetTempletFile();
			if(!file_exists($tempfile) || !is_file($tempfile))
			{
				echo "模板文件不存在,无法解析文档!";
				exit();
			}
			$this->dtp->LoadTemplate($tempfile);
			$this->TempSource = $this->dtp->SourceString;
		}
		else
		{
			$this->dtp->LoadSource($this->TempSource);
		}
	}

	//解析模板,对固定的标记进行初始给值
	function ParseTempletsFirst()
	{
		if(empty($this->Fields['keywords']))
		{
			$this->Fields['keywords'] = '';
		}

		if(empty($this->Fields['reid']))
		{
			$this->Fields['reid'] = 0;
		}

		$GLOBALS['envs']['tags'] = $this->Fields['tags'];

		if(isset($this->TypeLink->TypeInfos['reid']))
		{
			$GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];

⌨️ 快捷键说明

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