用arc.listview.class.php覆盖include/arc.listview.class.php
调用方法
{dede:pagelist listsize='5'/}
{dede:pagelist pagelang='en' listsize='5'/}
pagelang:en为英文,cn为中文,默认语言中文
可以自行扩展
<?php
if(!defined('DEDEINC')) exit('Request Error!');
require_once(DEDEINC.'/arc.partview.class.php');
require_once(DEDEINC.'/ftp.class.php');
@set_time_limit(0);
class ListView
{
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 $upPageType;
var $addSql;
var $IsError;
var $CrossID;
var $IsReplace;
var $ftp;
var $remoteDir;
var $pagelang;
//php5构造函数
function __construct($typeid,$uppage=1)
{
global $dsql,$ftp;
$this->TypeID = $typeid;
$this->dsql = &$dsql;
$this->CrossID = '';
$this->IsReplace = false;
$this->IsError = false;
$this->dtp = new DedeTagParse();
$this->dtp->SetRefObj($this);
$this->dtp->SetNameSpace("dede", "{", "}");
$this->dtp2 = new DedeTagParse();
$this->dtp2->SetNameSpace("field","[","]");
$this->TypeLink = new TypeLink($typeid);
$this->upPageType = $uppage;
$this->ftp = &$ftp;;
$this->remoteDir = '';
$this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
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));
//设置一些全局参数的值
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 ListView($typeid,$uppage=0){
$this->__construct($typeid,$uppage);
}
//关闭相关资源
function Close()
{
}
//统计列表里的记录
function CountRecord()
{
global $cfg_list_son,$cfg_need_typeid2;
if(empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N';
//统计数据库记录
$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 ";
$typeid2like = " '%,{$this->TypeID},%' ";
if($cfg_list_son=='N')
{
if($cfg_need_typeid2=='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='".$this->TypeID."') OR CONCAT(',', arc.typeid2, ',') like $typeid2like) ";
else $this->addSql .= " And ( arc.typeid in({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') like $typeid2like) ";
}
}
else
{
$sonids = GetSonIds($this->TypeID,$this->Fields['channeltype']);
if(!preg_match("/,/", $sonids)) {
$sonidsCon = " arc.typeid = '$sonids' ";
}
else {
$sonidsCon = " arc.typeid in($sonids) ";
}
if($cfg_need_typeid2=='N')
{
if($this->CrossID=='') $this->addSql .= " And ( $sonidsCon ) ";
else $this->addSql .= " And ( arc.typeid in ({$sonids},{$this->CrossID}) ) ";
}
else
{
if($this->CrossID=='') $this->addSql .= " And ( $sonidsCon OR CONCAT(',', arc.typeid2, ',') like $typeid2like ) ";
else $this->addSql .= " And ( arc.typeid in ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') like $typeid2like ) ";
}
}
if($this->TotalResult==-1)
{
$cquery = "Select count(*) as dd From `#@__arctiny` 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.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,$isremote=0)
{
global $cfg_remote_site;
if(empty($startpage))
{
$startpage = 1;
}
//创建封面模板文件
if($this->TypeLink->TypeInfos['isdefault']==-1)
{
echo '这个类目是动态类目!';
return '../plus/list.php?tid='.$this->TypeLink->TypeInfos['id'];
}
//单独页面
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($cfg_remote_site=='Y'&& $isremote == 1)
{
//分析远程文件路径
$remotefile = str_replace(DEDEROOT, '',$makeFile);
$localfile = '..'.$remotefile;
$remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
//不相等则说明已经切换目录则可以创建镜像
$this->ftp->rmkdir($remotedir);
$this->ftp->upload($localfile, $remotefile, 'acii');
}
}
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'];
//如果启用远程发布则需要进行判断
if($cfg_remote_site=='Y'&& $isremote == 1)
{
//分析远程文件路径
$remotefile = $murl;
$localfile = '..'.$remotefile;
$remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
//不相等则说明已经切换目录则可以创建镜像
$this->ftp->rmkdir($remotedir);
$this->ftp->upload($localfile, $remotefile, 'acii');
}
$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.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.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);
//如果启用远程发布则需要进行判断
if($GLOBALS['cfg_remote_site']=='Y'&& $isremote == 1)
{
//分析远程文件路径
$remotefile = str_replace(DEDEROOT, '',$makeFile);
$localfile = '..'.$remotefile;
$remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
//不相等则说明已经切换目录则可以创建镜像
$this->ftp->rmkdir($remotedir);
$this->ftp->upload($localfile, $remotefile, 'acii');
}
}
else
{
if(!file_exists($makeFile))
{
$this->PartView->SaveToHtml($makeFile);
//如果启用远程发布则需要进行判断
if($cfg_remote_site=='Y'&& $isremote == 1)
{
//分析远程文件路径
$remotefile = str_replace(DEDEROOT, '',$makeFile);
$localfile = '..'.$remotefile;
$remotedir = preg_replace('/[^\/]*\.html/', '',$remotefile);
//不相等则说明已经切换目录则可以创建镜像
$this->ftp->rmkdir($remotedir);
$this->ftp->upload($localfile, $remotefile, 'acii');
}
}
}
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.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']['typeid'] = $this->TypeID;
$GLOBALS['envs']['topid'] = GetTopid($this->Fields['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
{
$InnerText = trim($ctag->GetInnerText());
}
$this->dtp->Assign($tagid,
$this->GetArcList(
$limitstart,
$row,
$ctag->GetAtt("col"),
$ctag->GetAtt("titlelen"),
$ctag->GetAtt("infolen"),
$ctag->GetAtt("imgwidth"),
$ctag->GetAtt("imgheight"),
$ctag->GetAtt("listtype"),
$ctag->GetAtt("orderby"),
$InnerText,
$ctag->GetAtt("tablewidth"),
$ismake,
$ctag->GetAtt("orderway")
)
);
}
else if($ctag->GetName()=="pagelist")
{
$list_len = trim($ctag->GetAtt("listsize"));
$pagelang = trim($ctag->GetAtt("pagelang"));
$ctag->GetAtt("listitem")=="" ? $listitem="index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");
if($pagelang=="")
{
$pagelang = 'cn';
}
if($list_len=="")
{
$list_len = 3;
}
if($ismake==0)
{
$this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem,$pagelang));
}
else
{
$this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem,$pagelang));
}
}
else if($PageNo!=1 && $ctag->GetName()=='field' && $ctag->GetAtt('display')!='')
{
$this->dtp->Assign($tagid,'');
}
}
}
//获得要创建的文件名称规则
function GetMakeFileRule($typeid,$wname,$typedir,$defaultname,$namerule2)
{
$typedir = MfTypedir($typedir);
if($wname=='index')
{
return $typedir.'/'.$defaultname;
}
else
{
$namerule2 = str_replace('{tid}',$typeid,$namerule2);
$namerule2 = str_replace('{typedir}',$typedir,$namerule2);
return $namerule2;
}
}
//获得一个单列的文档列表
function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
$imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')
{
global $cfg_list_son;
$typeid=$this->TypeID;
if($row=='') $row = 10;
if($limitstart=='') $limitstart = 0;
if($titlelen=='') $titlelen = 100;
if($infolen=='') $infolen = 250;
if($imgwidth=='') $imgwidth = 120;
if($imgheight=='') $imgheight = 120;
if($listtype=='') $listtype = 'all';
if($orderWay=='') $orderWay = 'desc';
if($orderby=='') {
$orderby='default';
}
else {
$orderby=strtolower($orderby);
}
$tablewidth = str_replace('%','',$tablewidth);
if($tablewidth=='') $tablewidth=100;
if($col=='') $col=1;
$colWidth = ceil(100/$col);
$tablewidth = $tablewidth.'%';
$colWidth = $colWidth.'%';
$innertext = trim($innertext);
if($innertext=='') {
$innertext = GetSysTemplets('list_fulllist.htm');
}
//排序方式
$ordersql = '';
if($orderby=="senddate" || $orderby=="id") {
$ordersql=" order by arc.id $orderWay";
}
else if($orderby=="hot" || $orderby=="click") {
$ordersql = " order by arc.click $orderWay";
}
else if($orderby=="lastpost") {
$ordersql = " order by arc.lastpost $orderWay";
}else if($orderby=="weight") {
$ordersql = " order by arc.weight $orderWay";
}
else {
$ordersql=" order by arc.sortrank $orderWay";
}
//获得附加表的相关信息
$addtable = $this->ChannelUnit->ChannelInfos['addtable'];
if($addtable!="")
{
$addJoin = " left join `$addtable` on arc.id = ".$addtable.'.aid ';
$addField = '';
$fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
foreach($fields as $k=>$v)
{
$nfields[$v] = $k;
}
if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
{
foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
{
if(isset($nfields[$k]))
{
if(!empty($arr['rename'])) {
$addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
}
else {
$addField .= ','.$addtable.'.'.$k;
}
}
}
}
}
else
{
$addField = '';
$addJoin = '';
}
//如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
if(ereg('hot|click|lastpost|weight',$orderby))
{
$query = "Select arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
$addField
from `#@__archives` arc
left join `#@__arctype` tp on arc.typeid=tp.id
$addJoin
where {$this->addSql} $ordersql limit $limitstart,$row";
}
//普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)
else
{
$t1 = ExecTime();
$ids = array();
$query = "Select id From `#@__arctiny` arc where {$this->addSql} $ordersql limit $limitstart,$row ";
$this->dsql->SetQuery($query);
$this->dsql->Execute();
while($arr=$this->dsql->GetArray())
{
$ids[] = $arr['id'];
}
$idstr = join(',',$ids);
if($idstr=='')
{
return '';
}
else
{
$query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,
tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
$addField
from `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id
$addJoin
where arc.id in($idstr) $ordersql ";
}
$t2 = ExecTime();
//echo $t2-$t1;
}
$this->dsql->SetQuery($query);
$this->dsql->Execute('al');
$t2 = ExecTime();
//echo $t2-$t1;
$artlist = '';
$this->dtp2->LoadSource($innertext);
$GLOBALS['autoindex'] = 0;
for($i=0;$i<$row;$i++)
{
if($col>1)
{
$artlist .= "<div>\r\n";
}
for($j=0;$j<$col;$j++)
{
if($row = $this->dsql->GetArray("al"))
{
$GLOBALS['autoindex']++;
$ids[$row['id']] = $row['id'];
//处理一些特殊字段
$row['infos'] = cn_substr($row['description'],$infolen);
$row['id'] = $row['id'];
if($row['corank'] > 0 && $row['arcrank']==0)
{
$row['arcrank'] = $row['corank'];
}
$row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
$row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
$row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
$row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
if($row['litpic'] == '-' || $row['litpic'] == '')
{
$row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
}
if(!eregi("^http://",$row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
{
$row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
}
$row['picname'] = $row['litpic'];
$row['stime'] = GetDateMK($row['pubdate']);
$row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
$row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".ereg_replace("['><]","",$row['title'])."'>";
$row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
$row['fulltitle'] = $row['title'];
$row['title'] = cn_substr($row['title'],$titlelen);
if($row['color']!='')
{
$row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
}
if(ereg('c',$row['flag']))
{
$row['title'] = "<b>".$row['title']."</b>";
}
$row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
$row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
$row['memberurl'] = $GLOBALS['cfg_memberurl'];
$row['templeturl'] = $GLOBALS['cfg_templeturl'];
//编译附加表里的数据
foreach($row as $k=>$v)
{
$row[strtolower($k)] = $v;
}
foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
{
if(isset($row[$k]))
{
$row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);
}
}
if(is_array($this->dtp2->CTags))
{
foreach($this->dtp2->CTags as $k=>$ctag)
{
if($ctag->GetName()=='array')
{
//传递整个数组,在runphp模式中有特殊作用
$this->dtp2->Assign($k,$row);
}
else
{
if(isset($row[$ctag->GetName()]))
{
$this->dtp2->Assign($k,$row[$ctag->GetName()]);
}
else
{
$this->dtp2->Assign($k,'');
}
}
}
}
$artlist .= $this->dtp2->GetResult();
}//if hasRow
}//Loop Col
if($col>1)
{
$i += $col - 1;
$artlist .= " </div>\r\n";
}
}//Loop Line
$t3 = ExecTime();
//echo ($t3-$t2);
$this->dsql->FreeResult('al');
return $artlist;
}
//获取静态的分页列表
function GetPageListST($list_len,$listitem="index,end,pre,next,pageno",$pagelang)
{
/*****************************************************************************************/
if($pagelang=='cn'){
$uahome="首页";
$uaprevious="上一页";
$uanext="下一页";
$ualastpage="末页";
$uapage="页";
$uatotal="共";
$uarecords="条记录";
}else{
$uahome=" Home ";
$uaprevious=" Previous ";
$uanext=" Next ";
$ualastpage=" Last Page ";
$uapage=" Page ";
$uatotal=" Total ";
$uarecords=" Records. ";
}
$prepage = $nextpage = '';
$prepagenum = $this->PageNo-1;
$nextpagenum = $this->PageNo+1;
if($list_len=='' || ereg("[^0-9]",$list_len))
{
$list_len=3;
}
$totalpage = ceil($this->TotalResult/$this->PageSize);
if($totalpage<=1 && $this->TotalResult>0)
{
return "<li><span class=\"pageinfo\">".$uatotal." <strong>1</strong> ".$uapage." <strong>".$this->TotalResult."</strong> ".$uarecords."</span></li>\r\n";
}
if($this->TotalResult == 0)
{
return "<li><span class=\"pageinfo\">".$uatotal." <strong>0</strong> ".$uapage." <strong>".$this->TotalResult."</strong> ".$uarecords."</span></li>\r\n";
}
$purl = $this->GetCurUrl();
$maininfo = "<li><span class=\"pageinfo\">".$uatotal." <strong>{$totalpage}</strong> ".$uapage." <strong>".$this->TotalResult."</strong> ".$uarecords."</span></li>\r\n";
$tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
$tnamerule = ereg_replace('^(.*)/','',$tnamerule);
//获得上一页和主页的链接
if($this->PageNo != 1)
{
$prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'>".$uaprevious."</a></li>\r\n";
$indexpage="<li><a href='".str_replace("{page}",1,$tnamerule)."'>".$uahome."</a></li>\r\n";
}
else
{
$indexpage="<li>".$uahome."</li>\r\n";
}
//下一页,未页的链接
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>".$uanext."</a></li>\r\n";
$endpage="<li><a href='".str_replace("{page}",$totalpage,$tnamerule)."'>".$ualastpage."</a></li>\r\n";
}
else
{
$endpage="<li>".$ualastpage."</li>\r\n";
}
//option链接
$optionlist = '';
$optionlen = strlen($totalpage);
$optionlen = $optionlen*12 + 18;
if($optionlen < 36) $optionlen = 36;
if($optionlen > 100) $optionlen = 100;
$optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
for($mjj=1;$mjj<=$totalpage;$mjj++)
{
if($mjj==$this->PageNo)
{
$optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
}
else
{
$optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
}
}
$optionlist .= "</select></li>\r\n";
//获得数字链接
$listdd="";
$total_list = $list_len * 2 + 1;
if($this->PageNo >= $total_list)
{
$j = $this->PageNo-$list_len;
$total_list = $this->PageNo+$list_len;
if($total_list>$totalpage)
{
$total_list=$totalpage;
}
}
else
{
$j=1;
if($total_list>$totalpage)
{
$total_list=$totalpage;
}
}
for($j;$j<=$total_list;$j++)
{
if($j==$this->PageNo)
{
$listdd.= "<li class=\"thisclass\">$j</li>\r\n";
}
else
{
$listdd.="<li><a href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a></li>\r\n";
}
}
$plist = '';
if(eregi('index',$listitem)) $plist .= $indexpage;
if(eregi('pre',$listitem)) $plist .= $prepage;
if(eregi('pageno',$listitem)) $plist .= $listdd;
if(eregi('next',$listitem)) $plist .= $nextpage;
if(eregi('end',$listitem)) $plist .= $endpage;
if(eregi('option',$listitem)) $plist .= $optionlist;
if(eregi('info',$listitem)) $plist .= $maininfo;
return $plist;
}
//获取动态的分页列表
function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno",$pagelang)
{
/*****************************************************************************************/
if($pagelang=='cn'){
$uahome="首页";
$uaprevious="上一页";
$uanext="下一页";
$ualastpage="末页";
$uapage="页";
$uatotal="共";
$uarecords="条记录";
}else{
$uahome=" Home ";
$uaprevious=" Previous ";
$uanext=" Next ";
$ualastpage=" Last Page ";
$uapage=" Page ";
$uatotal=" Total ";
$uarecords=" Records. ";
}
global $cfg_rewrite;
$prepage = $nextpage = '';
$prepagenum = $this->PageNo-1;
$nextpagenum = $this->PageNo+1;
if($list_len=='' || ereg("[^0-9]",$list_len))
{
$list_len=3;
}
$totalpage = ceil($this->TotalResult/$this->PageSize);
if($totalpage<=1 && $this->TotalResult>0)
{
return "<li><span class=\"pageinfo\">".$uatotal." 1 ".$uapage."/".$this->TotalResult."".$uarecords."</span></li>\r\n";
}
if($this->TotalResult == 0)
{
return "<li><span class=\"pageinfo\">".$uatotal." 0 ".$uapage."/".$this->TotalResult."".$uarecords."</span></li>\r\n";
}
$maininfo = "<li><span class=\"pageinfo\">".$uatotal." <strong>{$totalpage}</strong>".$uapage."<strong>".$this->TotalResult."</strong>".$uarecords."</span></li>\r\n";
$purl = $this->GetCurUrl();
if($cfg_rewrite == 'Y')
{
$nowurls = ereg_replace("\-", ".php?", $purl);
$nowurls = explode("?", $nowurls);
$purl = $nowurls[0];
}
$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$purl .= '?'.$geturl;
$optionlist = '';
//$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>\r\n";
//$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
//获得上一页和下一页的链接
if($this->PageNo != 1)
{
$prepage.="<li><a href='".$purl."PageNo=$prepagenum'>".$uaprevious."</a></li>\r\n";
$indexpage="<li><a href='".$purl."PageNo=1'>".$uahome."</a></li>\r\n";
}
else
{
$indexpage="<li><a>".$uahome."</a></li>\r\n";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>".$uanext."</a></li>\r\n";
$endpage="<li><a href='".$purl."PageNo=$totalpage'>".$ualastpage."</a></li>\r\n";
}
else
{
$endpage="<li><a>".$ualastpage."</a></li>\r\n";
}
//获得数字链接
$listdd="";
$total_list = $list_len * 2 + 1;
if($this->PageNo >= $total_list)
{
$j = $this->PageNo-$list_len;
$total_list = $this->PageNo+$list_len;
if($total_list>$totalpage)
{
$total_list=$totalpage;
}
}
else
{
$j=1;
if($total_list>$totalpage)
{
$total_list=$totalpage;
}
}
for($j;$j<=$total_list;$j++)
{
if($j==$this->PageNo)
{
$listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
}
else
{
$listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
}
}
$plist = '';
if(eregi('index',$listitem)) $plist .= $indexpage;
if(eregi('pre',$listitem)) $plist .= $prepage;
if(eregi('pageno',$listitem)) $plist .= $listdd;
if(eregi('next',$listitem)) $plist .= $nextpage;
if(eregi('end',$listitem)) $plist .= $endpage;
if(eregi('option',$listitem)) $plist .= $optionlist;
if(eregi('info',$listitem)) $plist .= $maininfo;
if($cfg_rewrite == 'Y')
{
$plist = str_replace('.php?tid=', '-', $plist);
$plist = str_replace('&TotalResult=', '-', $plist);
$plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
}
return $plist;
}
//获得当前的页面文件的url
function GetCurUrl()
{
if(!empty($_SERVER['REQUEST_URI']))
{
$nowurl = $_SERVER['REQUEST_URI'];
$nowurls = explode('?', $nowurl);
$nowurl = $nowurls[0];
}
else
{
$nowurl = $_SERVER['PHP_SELF'];
}
return $nowurl;
}
}//End Class
?>
下面的是搜索结果页的英文,修改arc.searchview.class.php
<?php if(!defined('DEDEINC')) exit("Request Error!");
/**
* 搜索视图类
*
* @version $Id: arc.searchview.class.php 1 15:26 2010年7月7日Z tianya $
* @package DedeCMS.Libraries
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
require_once(DEDEINC."/typelink.class.php");
require_once(DEDEINC."/dedetag.class.php");
require_once(DEDEINC."/splitword.class.php");
require_once(DEDEINC."/taglib/hotwords.lib.php");
require_once(DEDEINC."/taglib/channel.lib.php");
@set_time_limit(0);
@ini_set('memory_limit', '512M');
/**
* 搜索视图类
*
* @package SearchView
* @subpackage DedeCMS.Libraries
* @link http://www.dedecms.com
*/
class SearchView
{
var $dsql;
var $dtp;
var $dtp2;
var $TypeID;
var $TypeLink;
var $PageNo;
var $TotalPage;
var $TotalResult;
var $PageSize;
var $ChannelType;
var $TempInfos;
var $Fields;
var $PartView;
var $StartTime;
var $Keywords;
var $OrderBy;
var $SearchType;
var $mid;
var $KType;
var $Keyword;
var $SearchMax;
var $SearchMaxRc;
var $SearchTime;
var $AddSql;
var $RsFields;
var $Sphinx;
/**
* php5构造函数
*
* @access public
* @param int $typeid 栏目ID
* @param string $keyword 关键词
* @param string $orderby 排序
* @param string $achanneltype 频道类型
* @param string $searchtype 搜索类型
* @param string $starttime 开始时间
* @param string $upagesize Page 数
* @param string $kwtype 关键词类型
* @param string $mid 会员ID
* @return string
*/
function __construct($typeid,$keyword,$orderby,$achanneltype="all",
$searchtype='',$starttime=0,$upagesize=20,$kwtype=1,$mid=0)
{
global $cfg_search_max,$cfg_search_maxrc,$cfg_search_time,$cfg_sphinx_article;
if(empty($upagesize))
{
$upagesize = 10;
}
$this->TypeID = $typeid;
$this->Keyword = $keyword;
$this->OrderBy = $orderby;
$this->KType = $kwtype;
$this->PageSize = (int)$upagesize;
$this->StartTime = $starttime;
$this->ChannelType = $achanneltype;
$this->SearchMax = $cfg_search_max;
$this->SearchMaxRc = $cfg_search_maxrc;
$this->SearchTime = $cfg_search_time;
$this->mid = $mid;
$this->RsFields = '';
$this->SearchType = $searchtype=='' ? 'titlekeyword' : $searchtype;
$this->dsql = $GLOBALS['dsql'];
$this->dtp = new DedeTagParse();
$this->dtp->SetRefObj($this);
$this->dtp->SetNameSpace("dede","{","}");
$this->dtp2 = new DedeTagParse();
$this->dtp2->SetNameSpace("field","[","]");
$this->TypeLink = new TypeLink($typeid);
// 通过分词获取关键词
$this->Keywords = $this->GetKeywords($keyword);
//设置一些全局参数的值
if($this->TypeID=="0"){
$this->ChannelTypeid=1;
}else{
$row =$this->dsql->GetOne("SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}");
$this->ChannelTypeid=$row['channeltype'];
}
foreach($GLOBALS['PubFields'] as $k=>$v)
{
$this->Fields[$k] = $v;
}
if ($cfg_sphinx_article == 'Y')
{
// 初始化sphinx
$this->sphinx = new SphinxClient;
$mode = SPH_MATCH_EXTENDED2; //匹配模式
$ranker = SPH_RANK_PROXIMITY_BM25; //统计相关度计算模式,仅使用BM25评分计算
$this->sphinx->SetServer($GLOBALS['cfg_sphinx_host'], $GLOBALS['cfg_sphinx_port']);
$this->sphinx->SetArrayResult(true);
$this->sphinx->SetMatchMode($mode);
$this->sphinx->SetRankingMode($ranker);
$this->CountRecordSphinx();
} else {
$this->CountRecord();
}
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
if(!file_exists($tempfile)||!is_file($tempfile))
{
echo "模板文件不存在,无法解析!";
exit();
}
$this->dtp->LoadTemplate($tempfile);
$this->TempInfos['tags'] = $this->dtp->CTags;
$this->TempInfos['source'] = $this->dtp->SourceString;
if($this->PageSize=="")
{
$this->PageSize = 20;
}
$this->TotalPage = ceil($this->TotalResult/$this->PageSize);
if($this->PageNo==1)
{
$this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET result='".$this->TotalResult."' WHERE keyword='".addslashes($keyword)."'; ");
}
}
//php4构造函数
function SearchView($typeid,$keyword,$orderby,$achanneltype="all",
$searchtype="",$starttime=0,$upagesize=20,$kwtype=1,$mid=0)
{
$this->__construct($typeid,$keyword,$orderby,$achanneltype,$searchtype,$starttime,$upagesize,$kwtype,$mid);
}
//关闭相关资源
function Close()
{
}
/**
* 获得关键字的分词结果,并保存到数据库
*
* @access public
* @param string $keyword 关键词
* @return string
*/
function GetKeywords($keyword)
{
global $cfg_soft_lang;
$keyword = cn_substr($keyword, 50);
$row = $this->dsql->GetOne("SELECT spwords FROM `#@__search_keywords` WHERE keyword='".addslashes($keyword)."'; ");
if(!is_array($row))
{
if(strlen($keyword)>7)
{
$sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
$sp->SetSource($keyword, $cfg_soft_lang, $cfg_soft_lang);
$sp->SetResultType(2);
$sp->StartAnalysis(TRUE);
$keywords = $sp->GetFinallyResult();
$idx_keywords = $sp->GetFinallyIndex();
ksort($idx_keywords);
$keywords = $keyword.' ';
foreach ($idx_keywords as $key => $value) {
if (strlen($key) <= 3) {
continue;
}
$keywords .= ' '.$key;
}
$keywords = preg_replace("/[ ]{1,}/", " ", $keywords);
//var_dump($idx_keywords);exit();
unset($sp);
}
else
{
$keywords = $keyword;
}
$inquery = "INSERT INTO `#@__search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`)
VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); ";
$this->dsql->ExecuteNoneQuery($inquery);
}
else
{
$this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET count=count+1,lasttime='".time()."' WHERE keyword='".addslashes($keyword)."'; ");
$keywords = $row['spwords'];
}
return $keywords;
}
/**
* 获得关键字SQL
*
* @access private
* @return string
*/
function GetKeywordSql()
{
$ks = explode(' ',$this->Keywords);
$kwsql = '';
$kwsqls = array();
foreach($ks as $k)
{
$k = trim($k);
if(strlen($k)<1)
{
continue;
}
if(ord($k[0])>0x80 && strlen($k)<2)
{
continue;
}
$k = addslashes($k);
if($this->ChannelType < 0 || $this->ChannelTypeid < 0){
$kwsqls[] = " arc.title LIKE '%$k%' ";
}else{
if($this->SearchType=="title"){
$kwsqls[] = " arc.title LIKE '%$k%' ";
}else{
$kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) LIKE '%$k%' ";
}
}
}
if(!isset($kwsqls[0]))
{
return '';
}
else
{
if($this->KType==1)
{
$kwsql = join(' OR ',$kwsqls);
}
else
{
$kwsql = join(' And ',$kwsqls);
}
return $kwsql;
}
}
/**
* 获得相关的关键字
*
* @access public
* @param string $num 关键词数目
* @return string
*/
function GetLikeWords($num=8)
{
$ks = explode(' ',$this->Keywords);
$lsql = '';
foreach($ks as $k)
{
$k = trim($k);
if(strlen($k)<2)
{
continue;
}
if(ord($k[0])>0x80 && strlen($k)<2)
{
continue;
}
$k = addslashes($k);
if($lsql=='')
{
$lsql = $lsql." CONCAT(spwords,' ') LIKE '%$k %' ";
}else{
$lsql = $lsql." OR CONCAT(spwords,' ') LIKE '%$k %' ";
}
}
if($lsql=='')
{
return '';
}
else
{
$likeword = '';
$lsql = "(".$lsql.") AND NOT(keyword like '".addslashes($this->Keyword)."') ";
$this->dsql->SetQuery("SELECT keyword,count FROM `#@__search_keywords` WHERE $lsql ORDER BY lasttime DESC LIMIT 0,$num; ");
$this->dsql->Execute('l');
while($row=$this->dsql->GetArray('l'))
{
if($row['count']>1000)
{
$fstyle=" style='font-size:11pt;color:red'";
}
else if($row['count']>300)
{
$fstyle=" style='font-size:10pt;color:green'";
}
else
{
$style = "";
}
$likeword .= " <a href='search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'".$style."><u>".$row['keyword']."</u></a> ";
}
return $likeword;
}
}
/**
* 加粗关键字
*
* @access private
* @param string $fstr 关键词字符
* @return string
*/
function GetRedKeyWord($fstr)
{
//echo $fstr;
$ks = explode(' ',$this->Keywords);
foreach($ks as $k)
{
$k = trim($k);
if($k=='')
{
continue;
}
if(ord($k[0])>0x80 && strlen($k)<2)
{
continue;
}
// 这里不区分大小写进行关键词替换
$fstr = str_ireplace($k, "<font color='red'>$k</font>", $fstr);
// 速度更快,效率更高
//$fstr = str_replace($k, "<font color='red'>$k</font>", $fstr);
}
return $fstr;
}
// Sphinx记录统计
function CountRecordSphinx()
{
$this->TotalResult = -1;
if(isset($GLOBALS['TotalResult']))
{
$this->TotalResult = $GLOBALS['TotalResult'];
$this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
}
if(isset($GLOBALS['PageNo']))
{
$this->PageNo = intval($GLOBALS['PageNo']);
}
else
{
$this->PageNo = 1;
}
if($this->StartTime > 0)
{
$this->sphinx->SetFilterRange('senddate', $this->StartTime, time(), false);
}
if($this->TypeID > 0)
{
$this->sphinx->SetFilter('typeid', GetSonIds($this->TypeID));
}
$this->sphinx->SetFilter('channel', array(1));
if($this->mid > 0)
{
$this->sphinx->SetFilter('mid', $this->mid);
}
//$this->sphinx->SetFilterRange('arcrank', -1, 100, false);
// var_dump($this->sphinx);exit;
$res = array();
$res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk');
$this->TotalResult = $res['total'];
}
/**
* 统计列表里的记录
*
* @access public
* @return string
*/
function CountRecord()
{
$this->TotalResult = -1;
if(isset($GLOBALS['TotalResult']))
{
$this->TotalResult = $GLOBALS['TotalResult'];
$this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
}
if(isset($GLOBALS['PageNo']))
{
$this->PageNo = intval($GLOBALS['PageNo']);
}
else
{
$this->PageNo = 1;
}
$ksql = $this->GetKeywordSql();
$ksqls = array();
if($this->StartTime > 0)
{
$ksqls[] = " arc.senddate>'".$this->StartTime."' ";
}
if($this->TypeID > 0)
{
$ksqls[] = " typeid IN (".GetSonIds($this->TypeID).") ";
}
if($this->ChannelType > 0)
{
$ksqls[] = " arc.channel='".$this->ChannelType."'";
}
if($this->mid > 0)
{
$ksqls[] = " arc.mid = '".$this->mid."'";
}
$ksqls[] = " arc.arcrank > -1 ";
$this->AddSql = ($ksql=='' ? join(' AND ',$ksqls) : join(' AND ',$ksqls)." AND ($ksql)" );
if($this->ChannelType < 0 || $this->ChannelTypeid< 0){
if($this->ChannelType=="0") $id=$this->ChannelTypeid;
else $id=$this->ChannelType;
$row = $this->dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id=$id");
$addtable = trim($row['addtable']);
$this->AddTable=$addtable;
}else{
$this->AddTable="#@__archives";
}
$cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql;
//var_dump($cquery);
$hascode = md5($cquery);
$row = $this->dsql->GetOne("SELECT * FROM `#@__arccache` WHERE `md5hash`='".$hascode."' ");
$uptime = time();
if(is_array($row) && time()-$row['uptime'] < 3600 * 24)
{
$aids = explode(',', $row['cachedata']);
$this->TotalResult = count($aids)-1;
$this->RsFields = $row['cachedata'];
}
else
{
if($this->TotalResult==-1)
{
$this->dsql->SetQuery($cquery);
$this->dsql->execute();
$aidarr = array();
$aidarr[] = 0;
while($row = $this->dsql->getarray())
{
if($this->ChannelType< 0 ||$this->ChannelTypeid< 0) $aidarr[] = $row['aid'];
else $aidarr[] = $row['id'];
}
$nums = count($aidarr)-1;
$aids = implode(',', $aidarr);
$delete = "DELETE FROM `#@__arccache` WHERE uptime<".(time() - 3600 * 24);
$this->dsql->SetQuery($delete);
$this->dsql->executenonequery();
$insert = "INSERT INTO `#@__arccache` (`md5hash`, `uptime`, `cachedata`)
VALUES('$hascode', '$uptime', '$aids')";
$this->dsql->SetQuery($insert);
$this->dsql->executenonequery();
$this->TotalResult = $nums;
}
}
}
/**
* 显示列表
*
* @access public
* @param string
* @return string
*/
function Display()
{
foreach($this->dtp->CTags as $tagid=>$ctag)
{
$tagname = $ctag->GetName();
if($tagname=="list")
{
$limitstart = ($this->PageNo-1) * $this->PageSize;
$row = $this->PageSize;
if(trim($ctag->GetInnerText())=="")
{
$InnerText = GetSysTemplets("list_fulllist.htm");
}
else
{
$InnerText = trim($ctag->GetInnerText());
}
$this->dtp->Assign($tagid,
$this->GetArcList($limitstart,
$row,
$ctag->GetAtt("col"),
$ctag->GetAtt("titlelen"),
$ctag->GetAtt("infolen"),
$ctag->GetAtt("imgwidth"),
$ctag->GetAtt("imgheight"),
$this->ChannelType,
$this->OrderBy,
$InnerText,
$ctag->GetAtt("tablewidth"))
);
}
else if($tagname=="pagelist")
{
$list_len = trim($ctag->GetAtt("listsize"));
if($list_len=="")
{
$list_len = 3;
}
$this->dtp->Assign($tagid,$this->GetPageListDM($list_len));
}
else if($tagname=="likewords")
{
$this->dtp->Assign($tagid,$this->GetLikeWords($ctag->GetAtt('num')));
}
else if($tagname=="hotwords")
{
$this->dtp->Assign($tagid,lib_hotwords($ctag,$this));
}
else if($tagname=="field")
{
//类别的指定字段
if(isset($this->Fields[$ctag->GetAtt('name')]))
{
$this->dtp->Assign($tagid,$this->Fields[$ctag->GetAtt('name')]);
}
else
{
$this->dtp->Assign($tagid,"");
}
}
else if($tagname=="channel")
{
//下级频道列表
if($this->TypeID>0)
{
$typeid = $this->TypeID; $reid = $this->TypeLink->TypeInfos['reid'];
}
else
{
$typeid = 0; $reid=0;
}
$GLOBALS['envs']['typeid'] = $typeid;
$GLOBALS['envs']['reid'] = $typeid;
$this->dtp->Assign($tagid,lib_channel($ctag,$this));
}//End if
}
global $keyword, $oldkeyword;
if(!empty($oldkeyword)) $keyword = $oldkeyword;
$this->dtp->Display();
}
/**
* 获得文档列表
*
* @access public
* @param int $limitstart 限制开始
* @param int $row 行数
* @param int $col 列数
* @param int $titlelen 标题长度
* @param int $infolen 描述长度
* @param int $imgwidth 图片宽度
* @param int $imgheight 图片高度
* @param string $achanneltype 列表类型
* @param string $orderby 排列顺序
* @param string $innertext 底层模板
* @param string $tablewidth 表格宽度
* @return string
*/
function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
$imgwidth=120,$imgheight=90,$achanneltype="all",$orderby="default",$innertext="",$tablewidth="100")
{
global $cfg_sphinx_article;
$typeid=$this->TypeID;
if($row=='') $row = 10;
if($limitstart=='') $limitstart = 0;
if($titlelen=='') $titlelen = 30;
if($infolen=='') $infolen = 250;
if($imgwidth=='') $imgwidth = 120;
if($imgheight='') $imgheight = 120;
if($achanneltype=='') $achanneltype = '0';
$orderby = $orderby=='' ? 'default' : strtolower($orderby);
$tablewidth = str_replace("%","",$tablewidth);
if($tablewidth=='') $tablewidth=100;
if($col=='') $col=1;
$colWidth = ceil(100/$col);
$tablewidth = $tablewidth."%";
$colWidth = $colWidth."%";
$innertext = trim($innertext);
if($innertext=='')
{
$innertext = GetSysTemplets("search_list.htm");
}
if ($cfg_sphinx_article == 'Y')
{
$ordersql = '';
if($this->ChannelType< 0 ||$this->ChannelTypeid< 0)
{
if($orderby=="id"){
$ordersql="@id desc";
}else{
$ordersql="@senddate desc";
}
} else {
if($orderby=="senddate")
{
$ordersql="@senddate desc";
}
else if($orderby=="pubdate")
{
$ordersql="@pubdate desc";
}
else if($orderby=="id")
{
$ordersql="@id desc";
}
else
{
$ordersql="@sortrank desc";
}
}
$this->sphinx->SetLimits($limitstart, (int)$row, ($row>1000) ? $row : 1000);
$res = array();
$res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk');
foreach ($res['words'] as $k => $v) {
$this->Keywords .= " $k";
}
foreach($res['matches'] as $_v) {
$aids[] = $_v['id'];
}
$aids = @implode(',', $aids);
//搜索
$query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
FROM `#@__archives` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id
WHERE arc.id IN ($aids)";
} else {
//排序方式
$ordersql = '';
if($this->ChannelType< 0 ||$this->ChannelTypeid< 0)
{
if($orderby=="id"){
$ordersql="ORDER BY arc.aid desc";
}else{
$ordersql="ORDER BY arc.senddate desc";
}
} else {
if($orderby=="senddate")
{
$ordersql=" ORDER BY arc.senddate desc";
}
else if($orderby=="pubdate")
{
$ordersql=" ORDER BY arc.pubdate desc";
}
else if($orderby=="id")
{
$ordersql=" ORDER BY arc.id desc";
}
else
{
$ordersql=" ORDER BY arc.sortrank desc";
}
}
//搜索
$query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id
WHERE {$this->AddSql} $ordersql LIMIT $limitstart,$row";
}
$this->dsql->SetQuery($query);
$this->dsql->Execute("al");
$artlist = "";
if($col>1)
{
$artlist = "<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\r\n";
}
$this->dtp2->LoadSource($innertext);
for($i=0;$i<$row;$i++)
{
if($col>1)
{
$artlist .= "<tr>\r\n";
}
for($j=0;$j<$col;$j++)
{
if($col>1)
{
$artlist .= "<td width='$colWidth'>\r\n";
}
if($row = $this->dsql->GetArray("al"))
{
if($this->ChannelType< 0 || $this->ChannelTypeid< 0) {
$row["id"]=$row["aid"];
$row["ismake"]=empty($row["ismake"])? "" : $row["ismake"];
$row["filename"]=empty($row["filename"])? "" : $row["filename"];
$row["money"]=empty($row["money"])? "" : $row["money"];
$row["description"]=empty($row["description "])? "" : $row["description"];
$row["pubdate"]=empty($row["pubdate "])? $row["senddate"] : $row["pubdate"];
}
//处理一些特殊字段
$row["xinghao"]=Search_addfields($row["id"],"xinghao");
$row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"],
$row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]);
$row["description"] = $this->GetRedKeyWord(cn_substr($row["description"],$infolen));
$row["title"] = $this->GetRedKeyWord(cn_substr($row["title"],$titlelen));
$row["id"] = $row["id"];
if($row['litpic'] == '-' || $row['litpic'] == '')
{
$row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
}
if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
{
$row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
}
$row['picname'] = $row['litpic'];
$row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"],$row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]);
$row["info"] = $row["description"];
$row["filename"] = $row["arcurl"];
$row["stime"] = GetDateMK($row["pubdate"]);
$row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>";
$row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]";
$row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'></a>";
$row["image"] = "<img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'>";
$row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
$row['memberurl'] = $GLOBALS['cfg_memberurl'];
$row['templeturl'] = $GLOBALS['cfg_templeturl'];
if(is_array($this->dtp2->CTags))
{
foreach($this->dtp2->CTags as $k=>$ctag)
{
if($ctag->GetName()=='array')
{
//传递整个数组,在runphp模式中有特殊作用
$this->dtp2->Assign($k,$row);
}
else
{
if(isset($row[$ctag->GetName()]))
{
$this->dtp2->Assign($k,$row[$ctag->GetName()]);
}
else
{
$this->dtp2->Assign($k,'');
}
}
}
}
$artlist .= $this->dtp2->GetResult();
}//if hasRow
else
{
$artlist .= "";
}
if($col>1) $artlist .= "</td>\r\n";
}//Loop Col
if($col>1)
{
$artlist .= "</tr>\r\n";
}
}//Loop Line
if($col>1)
{
$artlist .= "</table>\r\n";
}
$this->dsql->FreeResult("al");
return $artlist;
}
/**
* 获取动态的分 Page 列表
*
* @access public
* @param string $list_len 列表宽度
* @return string
*/
function GetPageListDM($list_len)
{
global $oldkeyword;
$prepage="";
$nextpage="";
$prepagenum = $this->PageNo - 1;
$nextpagenum = $this->PageNo + 1;
if($list_len=="" || preg_match("/[^0-9]/", $list_len))
{
$list_len=3;
}
$totalpage = ceil($this->TotalResult / $this->PageSize);
if($totalpage<=1 && $this->TotalResult>0)
{
return " Total 1 Page /".$this->TotalResult." Records. ";
}
if($this->TotalResult == 0)
{
return " Total 0 Page /".$this->TotalResult." Records. ";
}
$purl = $this->GetCurUrl();
$oldkeyword = (empty($oldkeyword) ? $this->Keyword : $oldkeyword);
//当结果超过限制时,重设结果 Page 数
if($this->TotalResult > $this->SearchMaxRc)
{
$totalpage = ceil($this->SearchMaxRc/$this->PageSize);
}
$infos = "<td> Total Found <b>".$this->TotalResult."</b> Records. /Max <b>{$totalpage}</b> Page </td>\r\n";
$geturl = "keyword=".urlencode($oldkeyword)."&searchtype=".$this->SearchType;
$hidenform = "<input type='hidden' name='keyword' value='".rawurldecode($oldkeyword)."'>\r\n";
$geturl .= "&channeltype=".$this->ChannelType."&orderby=".$this->OrderBy;
$hidenform .= "<input type='hidden' name='channeltype' value='".$this->ChannelType."'>\r\n";
$hidenform .= "<input type='hidden' name='orderby' value='".$this->OrderBy."'>\r\n";
$geturl .= "&kwtype=".$this->KType."&pagesize=".$this->PageSize;
$hidenform .= "<input type='hidden' name='kwtype' value='".$this->KType."'>\r\n";
$hidenform .= "<input type='hidden' name='pagesize' value='".$this->PageSize."'>\r\n";
$geturl .= "&typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$hidenform .= "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
$purl .= "?".$geturl;
//获得 Previous 和 Next 的链接
if($this->PageNo != 1)
{
$prepage.="<td width='50'><a href='".$purl."PageNo=$prepagenum'> Previous </a></td>\r\n";
$indexpage="<td width='30'><a href='".$purl."PageNo=1'> Home </a></td>\r\n";
}
else
{
$indexpage="<td width='30'> Home </td>\r\n";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<td width='50'><a href='".$purl."PageNo=$nextpagenum'> Next </a></td>\r\n";
$endpage="<td width='100'><a href='".$purl."PageNo=$totalpage'> Last Page </a></td>\r\n";
}
else
{
$endpage="<td width='100'> Last Page </td>\r\n";
}
//获得数字链接
$listdd="";
$total_list = $list_len * 2 + 1;
if($this->PageNo >= $total_list)
{
$j = $this->PageNo - $list_len;
$total_list = $this->PageNo + $list_len;
if($total_list > $totalpage)
{
$total_list = $totalpage;
}
}
else
{
$j=1;
if($total_list > $totalpage)
{
$total_list = $totalpage;
}
}
for($j; $j<=$total_list; $j++)
{
if($j == $this->PageNo)
{
$listdd.= "<td>$j </td>\r\n";
}
else
{
$listdd.="<td><a href='".$purl."PageNo=$j'>[".$j."]</a> </td>\r\n";
}
}
$plist = "<table border='0' cellpadding='0' cellspacing='0'>\r\n";
$plist .= "<tr align='center' style='font-size:10pt'>\r\n";
$plist .= "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
$plist .= $infos;
$plist .= $indexpage;
$plist .= $prepage;
$plist .= $listdd;
$plist .= $nextpage;
$plist .= $endpage;
if($totalpage>$total_list)
{
$plist.="<td width='38'><input type='text' name='PageNo' style='width:28px;height:14px' value='".$this->PageNo."' /></td>\r\n";
$plist.="<td width='30'><input type='submit' name='plistgo' value='GO' style='width:30px;height:22px;font-size:9pt' /></td>\r\n";
}
$plist .= "</form>\r\n</tr>\r\n</table>\r\n";
return $plist;
}
/**
* 获得当前的 Page 面文件的url
*
* @access public
* @return string
*/
function GetCurUrl()
{
if(!empty($_SERVER["REQUEST_URI"]))
{
$nowurl = $_SERVER["REQUEST_URI"];
$nowurls = explode("?",$nowurl);
$nowurl = $nowurls[0];
}
else
{
$nowurl = $_SERVER["PHP_SELF"];
}
return $nowurl;
}
}//End Class