diff --git a/src/include/arc.searchview.class.php b/src/include/arc.searchview.class.php index 77371349..458a428c 100755 --- a/src/include/arc.searchview.class.php +++ b/src/include/arc.searchview.class.php @@ -1,4 +1,4 @@ -TypeID = $typeid; @@ -88,76 +94,63 @@ class SearchView $this->SearchTime = $cfg_search_time; $this->mid = $mid; $this->RsFields = ''; - $this->SearchType = $searchtype=='' ? 'titlekeyword' : $searchtype; + $this->SearchType = $searchtype == '' ? 'titlekeyword' : $searchtype; $this->dsql = $GLOBALS['dsql']; $this->dtp = new DedeTagParse(); $this->dtp->SetRefObj($this); - $this->dtp->SetNameSpace("dede","{","}"); + $this->dtp->SetNameSpace("dede", "{", "}"); $this->dtp2 = new DedeTagParse(); - $this->dtp2->SetNameSpace("field","[","]"); + $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(); + if ($this->TypeID == "0") { + $this->ChannelTypeid = 1; } else { - $this->CountRecord(); + $row = $this->dsql->GetOne("SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}"); + $this->ChannelTypeid = $row['channeltype']; } - - - $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm"; - if ( defined('DEDEMOB') ) - { - $tempfile =str_replace('.htm','_m.htm',$tempfile); + foreach ($GLOBALS['PubFields'] as $k => $v) { + $this->Fields[$k] = $v; } - if(!file_exists($tempfile)||!is_file($tempfile)) - { + $this->CountRecord(); + + + $tempfile = $GLOBALS['cfg_basedir'] . $GLOBALS['cfg_templets_dir'] . "/" . $GLOBALS['cfg_df_style'] . "/search.htm"; + if (defined('DEDEMOB')) { + $tempfile = str_replace('.htm', '_m.htm', $tempfile); + } + 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=="") - { + 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)."'; "); + $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 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); } //关闭相关资源 @@ -175,22 +168,20 @@ class SearchView function GetKeywords($keyword) { global $cfg_soft_lang; - global $cfg_bizcore_appid,$cfg_bizcore_key,$cfg_bizcore_hostname,$cfg_bizcore_port; + global $cfg_bizcore_appid, $cfg_bizcore_key, $cfg_bizcore_hostname, $cfg_bizcore_port; $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) - { + $row = $this->dsql->GetOne("SELECT spwords FROM `#@__search_keywords` WHERE keyword='" . addslashes($keyword) . "'; "); + if (!is_array($row)) { + if (strlen($keyword) > 7) { if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) { $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port); $client->appid = $cfg_bizcore_appid; $client->key = $cfg_bizcore_key; $data = $client->Spliteword($keyword); $kvs = explode(",", $data->data); - $keywords = $keyword." "; + $keywords = $keyword . " "; foreach ($kvs as $key => $value) { - $keywords .= ' '.$value; + $keywords .= ' ' . $value; } $keywords = preg_replace("/[ ]{1,}/", " ", $keywords); $client->Close(); @@ -203,31 +194,25 @@ class SearchView $keywords = $sp->GetFinallyResult(); $idx_keywords = $sp->GetFinallyIndex(); ksort($idx_keywords); - $keywords = $keyword.' '; + $keywords = $keyword . ' '; foreach ($idx_keywords as $key => $value) { if (strlen($key) <= 3) { continue; } - $keywords .= ' '.$key; + $keywords .= ' ' . $key; } $keywords = preg_replace("/[ ]{1,}/", " ", $keywords); // var_dump($keywords);exit(); unset($sp); } - - - } - else - { + } else { $keywords = $keyword; } $inquery = "INSERT INTO `#@__search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`) - VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); "; + 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)."'; "); + } else { + $this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET count=count+1,lasttime='" . time() . "' WHERE keyword='" . addslashes($keyword) . "'; "); $keywords = $row['spwords']; } return $keywords; @@ -241,44 +226,35 @@ class SearchView */ function GetKeywordSql() { - $ks = explode(' ',$this->Keywords); + $ks = explode(' ', $this->Keywords); $kwsql = ''; $kwsqls = array(); - foreach($ks as $k) - { + foreach ($ks as $k) { $k = trim($k); - if(strlen($k)<1) - { + if (strlen($k) < 1) { continue; } - if(ord($k[0])>0x80 && strlen($k)<2) - { + if (ord($k[0]) > 0x80 && strlen($k) < 2) { continue; } $k = addslashes($k); - if($this->ChannelType < 0 || $this->ChannelTypeid < 0){ + if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) { $kwsqls[] = " arc.title LIKE '%$k%' "; - }else{ - if($this->SearchType=="title"){ + } else { + if ($this->SearchType == "title") { $kwsqls[] = " arc.title LIKE '%$k%' "; - }else{ + } else { $kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) LIKE '%$k%' "; } } } - if(!isset($kwsqls[0])) - { + if (!isset($kwsqls[0])) { return ''; - } - else - { - if($this->KType==1) - { - $kwsql = join(' OR ',$kwsqls); - } - else - { - $kwsql = join(' And ',$kwsqls); + } else { + if ($this->KType == 1) { + $kwsql = join(' OR ', $kwsqls); + } else { + $kwsql = join(' And ', $kwsqls); } return $kwsql; } @@ -291,54 +267,41 @@ class SearchView * @param string $num 关键词数目 * @return string */ - function GetLikeWords($num=8) + function GetLikeWords($num = 8) { - $ks = explode(' ',$this->Keywords); + $ks = explode(' ', $this->Keywords); $lsql = ''; - foreach($ks as $k) - { + foreach ($ks as $k) { $k = trim($k); - if(strlen($k)<2) - { + if (strlen($k) < 2) { continue; } - if(ord($k[0])>0x80 && strlen($k)<2) - { + 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 == '') { + $lsql = $lsql . " CONCAT(spwords,' ') LIKE '%$k %' "; + } else { + $lsql = $lsql . " OR CONCAT(spwords,' ') LIKE '%$k %' "; } } - if($lsql=='') - { + if ($lsql == '') { return ''; - } - else - { + } else { $likeword = ''; - $lsql = "(".$lsql.") AND NOT(keyword like '".addslashes($this->Keyword)."') "; + $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 - { + 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 .= " ".$row['keyword']." "; + $likeword .= " " . $row['keyword'] . " "; } return $likeword; } @@ -354,16 +317,13 @@ class SearchView function GetRedKeyWord($fstr) { //echo $fstr; - $ks = explode(' ',$this->Keywords); - foreach($ks as $k) - { + $ks = explode(' ', $this->Keywords); + foreach ($ks as $k) { $k = trim($k); - if($k=='') - { + if ($k == '') { continue; } - if(ord($k[0])>0x80 && strlen($k)<2) - { + if (ord($k[0]) > 0x80 && strlen($k) < 2) { continue; } // 这里不区分大小写进行关键词替换 @@ -373,45 +333,6 @@ class SearchView } 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']; - } /** * 统计列表里的记录 @@ -422,75 +343,62 @@ class SearchView function CountRecord() { $this->TotalResult = -1; - if(isset($GLOBALS['TotalResult'])) - { + if (isset($GLOBALS['TotalResult'])) { $this->TotalResult = $GLOBALS['TotalResult']; - $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : ""; + $this->TotalResult = is_numeric($this->TotalResult) ? $this->TotalResult : ""; } - if(isset($GLOBALS['PageNo'])) - { + if (isset($GLOBALS['PageNo'])) { $this->PageNo = intval($GLOBALS['PageNo']); - } - else - { + } else { $this->PageNo = 1; } $ksql = $this->GetKeywordSql(); $ksqls = array(); - if($this->StartTime > 0) - { - $ksqls[] = " arc.senddate>'".$this->StartTime."' "; + if ($this->StartTime > 0) { + $ksqls[] = " arc.senddate>'" . $this->StartTime . "' "; } - if($this->TypeID > 0) - { - $ksqls[] = " typeid IN (".GetSonIds($this->TypeID).") "; + if ($this->TypeID > 0) { + $ksqls[] = " typeid IN (" . GetSonIds($this->TypeID) . ") "; } - if($this->ChannelType > 0) - { - $ksqls[] = " arc.channel='".$this->ChannelType."'"; + if ($this->ChannelType > 0) { + $ksqls[] = " arc.channel='" . $this->ChannelType . "'"; } - if($this->mid > 0) - { - $ksqls[] = " arc.mid = '".$this->mid."'"; + 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; + $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"; + $this->AddTable = $addtable; + } else { + $this->AddTable = "#@__archives"; } - $cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql; + $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."' "); + $row = $this->dsql->GetOne("SELECT * FROM `#@__arccache` WHERE `md5hash`='" . $hascode . "' "); $uptime = time(); - if(is_array($row) && time()-$row['uptime'] < 3600 * 24) - { + if (is_array($row) && time() - $row['uptime'] < 3600 * 24) { $aids = explode(',', $row['cachedata']); - $this->TotalResult = count($aids)-1; + $this->TotalResult = count($aids) - 1; $this->RsFields = $row['cachedata']; - } - else - { - if($this->TotalResult==-1) - { + } 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']; + while ($row = $this->dsql->getarray()) { + if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) $aidarr[] = $row['aid']; else $aidarr[] = $row['id']; } - $nums = count($aidarr)-1; + $nums = count($aidarr) - 1; $aids = implode(',', $aidarr); - $delete = "DELETE FROM `#@__arccache` WHERE uptime<".(time() - 3600 * 24); + $delete = "DELETE FROM `#@__arccache` WHERE uptime<" . (time() - 3600 * 24); $this->dsql->SetQuery($delete); $this->dsql->executenonequery(); $insert = "INSERT INTO `#@__arccache` (`md5hash`, `uptime`, `cachedata`) @@ -511,83 +419,66 @@ class SearchView */ function Display() { - foreach($this->dtp->CTags as $tagid=>$ctag) - { + foreach ($this->dtp->CTags as $tagid => $ctag) { $tagname = $ctag->GetName(); - if($tagname=="list") - { - $limitstart = ($this->PageNo-1) * $this->PageSize; + if ($tagname == "list") { + $limitstart = ($this->PageNo - 1) * $this->PageSize; $row = $this->PageSize; - if(trim($ctag->GetInnerText())=="") - { + if (trim($ctag->GetInnerText()) == "") { $InnerText = GetSysTemplets("list_fulllist.htm"); - } - else - { + } 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")) + $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") - { + } else if ($tagname == "pagelist") { $list_len = trim($ctag->GetAtt("listsize")); - if($list_len=="") - { + 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") - { + $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,""); + 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") - { + } else if ($tagname == "channel") { //下级频道列表 - if($this->TypeID>0) - { - $typeid = $this->TypeID; $reid = $this->TypeLink->TypeInfos['reid']; - } - else - { - $typeid = 0; $reid=0; + 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 + $this->dtp->Assign($tagid, lib_channel($ctag, $this)); + } //End if } global $keyword, $oldkeyword; - if(!empty($oldkeyword)) $keyword = $oldkeyword; + if (!empty($oldkeyword)) $keyword = $oldkeyword; $this->dtp->Display(); } @@ -608,211 +499,155 @@ class SearchView * @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."%"; + function GetArcList( + $limitstart = 0, + $row = 10, + $col = 1, + $titlelen = 30, + $infolen = 250, + $imgwidth = 120, + $imgheight = 90, + $achanneltype = "all", + $orderby = "default", + $innertext = "", + $tablewidth = "100" + ) { + $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=='') - { + 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"; - } + + //排序方式 + $ordersql = ''; + if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) { + if ($orderby == "id") { + $ordersql = "ORDER BY arc.aid 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']; + $ordersql = "ORDER BY arc.senddate desc"; } - - $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"; - } + 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 { - 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"; - } + $ordersql = " ORDER BY arc.sortrank desc"; } + } - //搜索 - $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule, + //搜索 + $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) - { + if ($col > 1) { $artlist = "\r\n"; } $this->dtp2->LoadSource($innertext); - for($i=0;$i<$row;$i++) - { - if($col>1) - { + for ($i = 0; $i < $row; $i++) { + if ($col > 1) { $artlist .= "\r\n"; } - for($j=0;$j<$col;$j++) - { - if($col>1) - { + for ($j = 0; $j < $col; $j++) { + if ($col > 1) { $artlist .= "\r\n"; - }//Loop Col + if ($col > 1) $artlist .= "\r\n"; + } //Loop Col - if($col>1) - { + if ($col > 1) { $artlist .= "\r\n"; } - }//Loop Line + } //Loop Line - if($col>1) - { + if ($col > 1) { $artlist .= "
\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"]; + 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["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["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 ($row['litpic'] == '-' || $row['litpic'] == '') { + $row['litpic'] = $GLOBALS['cfg_cmspath'] . '/static/defaultpic.jpg'; } - if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') - { - $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic']; + 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["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"] = "".$row["title"].""; - $row["typelink"] = "[".$row["typename"]."]"; - $row["imglink"] = ""; - $row["image"] = ""; + $row["textlink"] = "" . $row["title"] . ""; + $row["typelink"] = "[" . $row["typename"] . "]"; + $row["imglink"] = ""; + $row["image"] = ""; $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') - { + 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,''); + $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 + } //if hasRow - else - { + else { $artlist .= ""; } - if($col>1) $artlist .= "
\r\n"; } $this->dsql->FreeResult("al"); @@ -830,101 +665,82 @@ class SearchView function GetPageListDM($list_len) { global $oldkeyword; - $prepage=""; - $nextpage=""; + $prepage = ""; + $nextpage = ""; $prepagenum = $this->PageNo - 1; $nextpagenum = $this->PageNo + 1; - if($list_len=="" || preg_match("/[^0-9]/", $list_len)) - { - $list_len=3; + 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 ""; + if ($totalpage <= 1 && $this->TotalResult > 0) { + return ""; } - if($this->TotalResult == 0) - { - return ""; + if ($this->TotalResult == 0) { + return ""; } $purl = $this->GetCurUrl(); - + $oldkeyword = (empty($oldkeyword) ? $this->Keyword : $oldkeyword); //当结果超过限制时,重设结果页数 - if($this->TotalResult > $this->SearchMaxRc) - { - $totalpage = ceil($this->SearchMaxRc/$this->PageSize); - } - $infos = "
  • 共找到".$this->TotalResult."条记录/最大显示{$totalpage}
  • \r\n"; - $geturl = "keyword=".urlencode($oldkeyword)."&searchtype=".$this->SearchType; - $hidenform = "\r\n"; - $geturl .= "&channeltype=".$this->ChannelType."&orderby=".$this->OrderBy; - $hidenform .= "\r\n"; - $hidenform .= "\r\n"; - $geturl .= "&kwtype=".$this->KType."&pagesize=".$this->PageSize; - $hidenform .= "\r\n"; - $hidenform .= "\r\n"; - $geturl .= "&typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&"; - $hidenform .= "\r\n"; - $hidenform .= "\r\n"; - $purl .= "?".$geturl; + if ($this->TotalResult > $this->SearchMaxRc) { + $totalpage = ceil($this->SearchMaxRc / $this->PageSize); + } + $infos = "
  • 共找到" . $this->TotalResult . "条记录/最大显示{$totalpage}
  • \r\n"; + $geturl = "keyword=" . urlencode($oldkeyword) . "&searchtype=" . $this->SearchType; + $hidenform = "\r\n"; + $geturl .= "&channeltype=" . $this->ChannelType . "&orderby=" . $this->OrderBy; + $hidenform .= "\r\n"; + $hidenform .= "\r\n"; + $geturl .= "&kwtype=" . $this->KType . "&pagesize=" . $this->PageSize; + $hidenform .= "\r\n"; + $hidenform .= "\r\n"; + $geturl .= "&typeid=" . $this->TypeID . "&TotalResult=" . $this->TotalResult . "&"; + $hidenform .= "\r\n"; + $hidenform .= "\r\n"; + $purl .= "?" . $geturl; //获得上一页和下一页的链接 - if($this->PageNo != 1) - { - $prepage.="
  • 上一页
  • \r\n"; - $indexpage="
  • 首页
  • \r\n"; - } - else - { - $indexpage="
  • 首页
  • \r\n"; - } - if($this->PageNo!=$totalpage && $totalpage>1) - { - $nextpage.="
  • 下一页
  • \r\n"; - $endpage="
  • 末页
  • \r\n"; + if ($this->PageNo != 1) { + $prepage .= "
  • 上一页
  • \r\n"; + $indexpage = "
  • 首页
  • \r\n"; + } else { + $indexpage = "
  • 首页
  • \r\n"; } - else - { - $endpage="
  • 末页
  • \r\n"; + if ($this->PageNo != $totalpage && $totalpage > 1) { + $nextpage .= "
  • 下一页
  • \r\n"; + $endpage = "
  • 末页
  • \r\n"; + } else { + $endpage = "
  • 末页
  • \r\n"; } //获得数字链接 - $listdd=""; + $listdd = ""; $total_list = $list_len * 2 + 1; - if($this->PageNo >= $total_list) - { + if ($this->PageNo >= $total_list) { $j = $this->PageNo - $list_len; $total_list = $this->PageNo + $list_len; - if($total_list > $totalpage) - { + if ($total_list > $totalpage) { $total_list = $totalpage; } - } - else - { - $j=1; - if($total_list > $totalpage) - { + } else { + $j = 1; + if ($total_list > $totalpage) { $total_list = $totalpage; } } - for($j; $j<=$total_list; $j++) - { - if($j == $this->PageNo) - { - $listdd.= "
  • $j 
  • \r\n"; - } - else - { - $listdd.="
  • ".$j." 
  • \r\n"; + for ($j; $j <= $total_list; $j++) { + if ($j == $this->PageNo) { + $listdd .= "
  • $j 
  • \r\n"; + } else { + $listdd .= "
  • " . $j . " 
  • \r\n"; } } $plist = ""; // $plist = "\r\n"; // $plist .= "\r\n"; - $plist .= "$hidenform"; + $plist .= "$hidenform"; $plist .= "