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

📄 arc.sglistview.class.php

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

@set_time_limit(0);

require_once(DEDEINC."/arc.partview.class.php");

class SgListView
{
	var $dsql;
	var $dtp;
	var $dtp2;
	var $TypeID;
	var $TypeLink;
	var $PageNo;
	var $TotalPage;
	var $TotalResult;
	var $PageSize;
	var $ChannelUnit;
	var $ListType;
	var $Fields;
	var $PartView;
	var $addSql;
	var $IsError;
	var $CrossID;
	var $IsReplace;
	var $AddTable;
	var $ListFields;
	var $searchArr;
	var $sAddTable;
	//php5构造函数
	function __construct($typeid,$searchArr=array())
	{
		global $dsql;
		$this->TypeID = $typeid;
		$this->dsql = &$dsql;
		$this->CrossID = '';
		$this->IsReplace = false;
		$this->IsError = false;
		$this->dtp = new DedeTagParse();
		$this->dtp->refObj = $this;
		$this->sAddTable = false;
		$this->dtp->SetNameSpace("dede","{","}");
		$this->dtp2 = new DedeTagParse();
		$this->dtp2->SetNameSpace("field","[","]");
		$this->TypeLink = new TypeLink($typeid);
		$this->searchArr = $searchArr;
		if(!is_array($this->TypeLink->TypeInfos))
		{
			$this->IsError = true;
		}
		if(!$this->IsError)
		{
			$this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);
			$this->Fields = $this->TypeLink->TypeInfos;
			$this->Fields['id'] = $typeid;
			$this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
			$this->Fields['title'] = ereg_replace("[<>]"," / ",$this->TypeLink->GetPositionLink(false));

			//获得附加表和列表字段信息
			$this->AddTable = $this->ChannelUnit->ChannelInfos['addtable'];
			$listfield = trim($this->ChannelUnit->ChannelInfos['listfields']);

			$this->ListFields = explode(',',$listfield);

			//设置一些全局参数的值
			foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;
			$this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/data/rss/".$this->TypeID.".xml";

			//设置环境变量
			SetSysEnv($this->TypeID,$this->Fields['typename'],0,'','list');
			$this->Fields['typeid'] = $this->TypeID;

			//获得交叉栏目ID
			if($this->TypeLink->TypeInfos['cross']>0 && $this->TypeLink->TypeInfos['ispart']==0)
			{
				$selquery = '';
				if($this->TypeLink->TypeInfos['cross']==1)
				{
					$selquery = "Select id,topid From `#@__arctype` where typename like '{$this->Fields['typename']}' And id<>'{$this->TypeID}' And topid<>'{$this->TypeID}'  ";
				}
				else
				{
					$this->Fields['crossid'] = ereg_replace('[^0-9,]','',trim($this->Fields['crossid']));
					if($this->Fields['crossid']!='')
					{
						$selquery = "Select id,topid From `#@__arctype` where id in({$this->Fields['crossid']}) And id<>{$this->TypeID} And topid<>{$this->TypeID}  ";
					}
				}
				if($selquery!='')
				{
					$this->dsql->SetQuery($selquery);
					$this->dsql->Execute();
					while($arr = $this->dsql->GetArray())
					{
						$this->CrossID .= ($this->CrossID=='' ? $arr['id'] : ','.$arr['id']);
					}
				}
			}

		}//!error

	}

	//php4构造函数
	function SgListView($typeid,$searchArr=array()){
		$this->__construct($typeid,$searchArr);
	}
	//关闭相关资源
	function Close()
	{

	}

	//统计列表里的记录
	function CountRecord()
	{
		global $cfg_list_son;

		//统计数据库记录
		$this->TotalResult = -1;
		if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
		if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
		else $this->PageNo = 1;
		$this->addSql  = " arc.arcrank > -1 ";

		//栏目id条件
		if(!empty($this->TypeID))
		{
			if($cfg_list_son=='N')
			{
				if($this->CrossID=='') $this->addSql .= " And (arc.typeid='".$this->TypeID."') ";
				else $this->addSql .= " And (arc.typeid in({$this->CrossID},{$this->TypeID})) ";
			}
			else
			{
				if($this->CrossID=='') $this->addSql .= " And (arc.typeid in (".GetSonIds($this->TypeID,$this->Fields['channeltype']).") ) ";
				else $this->addSql .= " And (arc.typeid in (".GetSonIds($this->TypeID,$this->Fields['channeltype']).",{$this->CrossID}) ) ";
			}
		}

		$naddQuery = '';
		//地区与信息类型条件
		if(count($this->searchArr) > 0)
		{
			if(!empty($this->searchArr['nativeplace']))
			{
				if($this->searchArr['nativeplace'] % 500 ==0 )
				{
					$naddQuery .= " And arc.nativeplace >= '{$this->searchArr['nativeplace']}' And arc.nativeplace < '".($this->searchArr['nativeplace']+500)."'";
				}
				else
				{
					$naddQuery .= "And arc.nativeplace = '{$this->searchArr['nativeplace']}'";
				}
			}
			if(!empty($this->searchArr['infotype']))
			{
				if($this->searchArr['infotype'] % 500 ==0 )
				{
					$naddQuery .= " And arc.infotype >= '{$this->searchArr['infotype']}' And arc.infotype < '".($this->searchArr['infotype']+500)."'";
				}
				else
				{
					$naddQuery .= "And arc.infotype = '{$this->searchArr['infotype']}'";
				}
			}
		}

		if($naddQuery!='')
		{
			$this->sAddTable = true;
			$this->addSql .= $naddQuery;
		}

		if($this->TotalResult==-1)
		{
			if($this->sAddTable)
			{
				$cquery = "Select count(*) as dd From `#@__arctiny` arc where ".$this->addSql;
			}
			else
			{
				$cquery = "Select count(*) as dd From `{$this->AddTable}` arc where ".$this->addSql;
			}
			$row = $this->dsql->GetOne($cquery);
			if(is_array($row))
			{
				$this->TotalResult = $row['dd'];
			}
			else
			{
				$this->TotalResult = 0;
			}
		}
		//初始化列表模板,并统计页面总数
		$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
		$tempfile = str_replace("{tid}",$this->TypeID,$tempfile);
		$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
		if(!file_exists($tempfile))
		{
			$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default_sg.htm";
		}
		if(!file_exists($tempfile)||!is_file($tempfile))
		{
			echo "模板文件不存在,无法解析文档!";
			exit();
		}
		$this->dtp->LoadTemplate($tempfile);
		$ctag = $this->dtp->GetTag("page");
		if(!is_object($ctag))
		{
			$ctag = $this->dtp->GetTag("list");
		}
		if(!is_object($ctag))
		{
			$this->PageSize = 20;
		}
		else
		{
			if($ctag->GetAtt('pagesize')!='')
			{
				$this->PageSize = $ctag->GetAtt('pagesize');
			}
			else
			{
				$this->PageSize = 20;
			}
		}
		$this->TotalPage = ceil($this->TotalResult/$this->PageSize);
	}

	//列表创建HTML
	function MakeHtml($startpage=1,$makepagesize=0)
	{
		if(empty($startpage))
		{
			$startpage = 1;
		}

		//创建封面模板文件
		if($this->TypeLink->TypeInfos['isdefault']==-1)
		{
			echo '这个类目是动态类目!';
			return '';
		}

		//单独页面
		else if($this->TypeLink->TypeInfos['ispart']>0)
		{
			$reurl = $this->MakePartTemplets();
			return $reurl;
		}

		$this->CountRecord();
		//初步给固定值的标记赋值
		$this->ParseTempletsFirst();
		$totalpage = ceil($this->TotalResult/$this->PageSize);
		if($totalpage==0)
		{
			$totalpage = 1;
		}
		CreateDir(MfTypedir($this->Fields['typedir']));
		$murl = '';
		if($makepagesize > 0)
		{
			$endpage = $startpage+$makepagesize;
		}
		else
		{
			$endpage = ($totalpage+1);
		}
		if( $endpage >= $totalpage+1 )
		{
			$endpage = $totalpage+1;
		}
		if($endpage==1)
		{
			$endpage = 2;
		}
		for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)
		{
			$this->ParseDMFields($this->PageNo,1);
			$makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
			$makeFile = str_replace("{page}",$this->PageNo,$makeFile);
			$murl = $makeFile;
			if(!ereg("^/",$makeFile))
			{
				$makeFile = "/".$makeFile;
			}
			$makeFile = $this->GetTruePath().$makeFile;
			$makeFile = ereg_replace("/{1,}","/",$makeFile);
			$murl = $this->GetTrueUrl($murl);
			$this->dtp->SaveTo($makeFile);
		}
		if($startpage==1)
		{
			//如果列表启用封面文件,复制这个文件第一页
			if($this->TypeLink->TypeInfos['isdefault']==1
			&& $this->TypeLink->TypeInfos['ispart']==0)
			{
				$onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
				$onlyrule = str_replace("{page}","1",$onlyrule);
				$list_1 = $this->GetTruePath().$onlyrule;
				$murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
				$indexname = $this->GetTruePath().$murl;
				copy($list_1,$indexname);
			}
		}
		return $murl;
	}

	//显示列表
	function Display()
	{
		if($this->TypeLink->TypeInfos['ispart']>0)
		{
			$this->DisplayPartTemplets();
			return ;
		}
		$this->CountRecord();
		if((empty($this->PageNo) || $this->PageNo==1)
		&& $this->TypeLink->TypeInfos['ispart']==1)
		{
			$tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
			$tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
			$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
			$tempfile = $tmpdir."/".$tempfile;
			if(!file_exists($tempfile))
			{
				$tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
			}
			$this->dtp->LoadTemplate($tempfile);
		}
		$this->ParseTempletsFirst();
		$this->ParseDMFields($this->PageNo,0);
		$this->dtp->Display();
	}

	//创建单独模板页面
	function MakePartTemplets()
	{
		$this->PartView = new PartView($this->TypeID,false);
		$this->PartView->SetTypeLink($this->TypeLink);
		$nmfa = 0;
		$tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
		if($this->Fields['ispart']==1)
		{
			$tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
			$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
			$tempfile = $tmpdir."/".$tempfile;
			if(!file_exists($tempfile))
			{
				$tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
			}
			$this->PartView->SetTemplet($tempfile);
		}
		else if($this->Fields['ispart']==2)
		{
			//跳转网址
			return $this->Fields['typedir'];
		}
		CreateDir(MfTypedir($this->Fields['typedir']));
		$makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
		$makeUrl = ereg_replace("/{1,}","/",$makeUrl);
		$makeFile = $this->GetTruePath().$makeUrl;
		if($nmfa==0)
		{
			$this->PartView->SaveToHtml($makeFile);
		}
		else
		{
			if(!file_exists($makeFile))
			{
				$this->PartView->SaveToHtml($makeFile);
			}
		}
		return $this->GetTrueUrl($makeUrl);
	}

	//显示单独模板页面
	function DisplayPartTemplets()
	{
		$this->PartView = new PartView($this->TypeID,false);
		$this->PartView->SetTypeLink($this->TypeLink);
		$nmfa = 0;
		$tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
		if($this->Fields['ispart']==1)
		{
			//封面模板
			$tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
			$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
			$tempfile = $tmpdir."/".$tempfile;
			if(!file_exists($tempfile))
			{
				$tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
			}
			$this->PartView->SetTemplet($tempfile);
		}
		else if($this->Fields['ispart']==2)
		{
			//跳转网址
			$gotourl = $this->Fields['typedir'];
			header("Location:$gotourl");
			exit();
		}
		CreateDir(MfTypedir($this->Fields['typedir']));
		$makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
		$makeFile = $this->GetTruePath().$makeUrl;
		if($nmfa==0)
		{
			$this->PartView->Display();
		}
		else
		{
			if(!file_exists($makeFile))
			{
				$this->PartView->Display();
			}
			else
			{
				include($makeFile);
			}
		}
	}

	//获得站点的真实根路径
	function GetTruePath()
	{
		$truepath = $GLOBALS["cfg_basedir"];
		return $truepath;
	}

	//获得真实连接路径
	function GetTrueUrl($nurl)
	{
		if($this->Fields['moresite']==1)
		{
			if($this->Fields['sitepath']!='')
			{
				$nurl = ereg_replace("^".$this->Fields['sitepath'],'',$nurl);
			}
			$nurl = $this->Fields['siteurl'].$nurl;
		}
		return $nurl;
	}

	//解析模板,对固定的标记进行初始给值
	function ParseTempletsFirst()
	{
		if(isset($this->TypeLink->TypeInfos['reid']))
		{
			$GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
		}
		$GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
		$GLOBALS['envs']['typeid'] = $this->TypeID;
		$GLOBALS['envs']['cross'] = 1;
		MakeOneTag($this->dtp,$this);
	}

	//解析模板,对内容里的变动进行赋值
	function ParseDMFields($PageNo,$ismake=1)
	{
		//替换第二页后的内容
		if(($PageNo>1 || strlen($this->Fields['content'])<10 ) && !$this->IsReplace)
		{
			$this->dtp->SourceString = str_replace('[cmsreplace]','display:none',$this->dtp->SourceString);
			$this->IsReplace = true;
		}
		foreach($this->dtp->CTags as $tagid=>$ctag)
		{
			if($ctag->GetName()=="list")
			{
				$limitstart = ($this->PageNo-1) * $this->PageSize;
				$row = $this->PageSize;
				if(trim($ctag->GetInnerText())=="")
				{
					$InnerText = GetSysTemplets("list_fulllist.htm");
				}
				else

⌨️ 快捷键说明

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