国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

964 lines
34KB

  1. <?php if(!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 搜索视图类
  4. *
  5. * @version $Id: arc.searchview.class.php 1 15:26 2010年7月7日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(DEDEINC."/typelink.class.php");
  12. require_once(DEDEINC."/dedetag.class.php");
  13. require_once(DEDEINC."/splitword.class.php");
  14. require_once(DEDEINC."/taglib/hotwords.lib.php");
  15. require_once(DEDEINC."/taglib/channel.lib.php");
  16. @set_time_limit(0);
  17. @ini_set('memory_limit', '512M');
  18. /**
  19. * 搜索视图类
  20. *
  21. * @package SearchView
  22. * @subpackage DedeCMS.Libraries
  23. * @link https://www.dedebiz.com
  24. */
  25. class SearchView
  26. {
  27. var $dsql;
  28. var $dtp;
  29. var $dtp2;
  30. var $TypeID;
  31. var $TypeLink;
  32. var $PageNo;
  33. var $TotalPage;
  34. var $TotalResult;
  35. var $PageSize;
  36. var $ChannelType;
  37. var $TempInfos;
  38. var $Fields;
  39. var $PartView;
  40. var $StartTime;
  41. var $Keywords;
  42. var $OrderBy;
  43. var $SearchType;
  44. var $mid;
  45. var $KType;
  46. var $Keyword;
  47. var $SearchMax;
  48. var $SearchMaxRc;
  49. var $SearchTime;
  50. var $AddSql;
  51. var $RsFields;
  52. var $Sphinx;
  53. /**
  54. * php5构造函数
  55. *
  56. * @access public
  57. * @param int $typeid 栏目ID
  58. * @param string $keyword 关键词
  59. * @param string $orderby 排序
  60. * @param string $achanneltype 频道类型
  61. * @param string $searchtype 搜索类型
  62. * @param string $starttime 开始时间
  63. * @param string $upagesize 页数
  64. * @param string $kwtype 关键词类型
  65. * @param string $mid 会员ID
  66. * @return string
  67. */
  68. function __construct($typeid,$keyword,$orderby,$achanneltype="all",
  69. $searchtype='',$starttime=0,$upagesize=20,$kwtype=1,$mid=0)
  70. {
  71. global $cfg_search_max,$cfg_search_maxrc,$cfg_search_time,$cfg_sphinx_article;
  72. if(empty($upagesize))
  73. {
  74. $upagesize = 10;
  75. }
  76. $this->TypeID = $typeid;
  77. $this->Keyword = $keyword;
  78. $this->OrderBy = $orderby;
  79. $this->KType = $kwtype;
  80. $this->PageSize = (int)$upagesize;
  81. $this->StartTime = $starttime;
  82. $this->ChannelType = $achanneltype;
  83. $this->SearchMax = $cfg_search_max;
  84. $this->SearchMaxRc = $cfg_search_maxrc;
  85. $this->SearchTime = $cfg_search_time;
  86. $this->mid = $mid;
  87. $this->RsFields = '';
  88. $this->SearchType = $searchtype=='' ? 'titlekeyword' : $searchtype;
  89. $this->dsql = $GLOBALS['dsql'];
  90. $this->dtp = new DedeTagParse();
  91. $this->dtp->SetRefObj($this);
  92. $this->dtp->SetNameSpace("dede","{","}");
  93. $this->dtp2 = new DedeTagParse();
  94. $this->dtp2->SetNameSpace("field","[","]");
  95. $this->TypeLink = new TypeLink($typeid);
  96. // 通过分词获取关键词
  97. $this->Keywords = $this->GetKeywords($keyword);
  98. //设置一些全局参数的值
  99. if($this->TypeID=="0"){
  100. $this->ChannelTypeid=1;
  101. }else{
  102. $row =$this->dsql->GetOne("SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}");
  103. $this->ChannelTypeid=$row['channeltype'];
  104. }
  105. foreach($GLOBALS['PubFields'] as $k=>$v)
  106. {
  107. $this->Fields[$k] = $v;
  108. }
  109. if ($cfg_sphinx_article == 'Y')
  110. {
  111. // 初始化sphinx
  112. $this->sphinx = new SphinxClient;
  113. $mode = SPH_MATCH_EXTENDED2; //匹配模式
  114. $ranker = SPH_RANK_PROXIMITY_BM25; //统计相关度计算模式,仅使用BM25评分计算
  115. $this->sphinx->SetServer($GLOBALS['cfg_sphinx_host'], $GLOBALS['cfg_sphinx_port']);
  116. $this->sphinx->SetArrayResult(true);
  117. $this->sphinx->SetMatchMode($mode);
  118. $this->sphinx->SetRankingMode($ranker);
  119. $this->CountRecordSphinx();
  120. } else {
  121. $this->CountRecord();
  122. }
  123. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
  124. if ( defined('DEDEMOB') )
  125. {
  126. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  127. }
  128. if(!file_exists($tempfile)||!is_file($tempfile))
  129. {
  130. echo "模板文件不存在,无法解析!";
  131. exit();
  132. }
  133. $this->dtp->LoadTemplate($tempfile);
  134. $this->TempInfos['tags'] = $this->dtp->CTags;
  135. $this->TempInfos['source'] = $this->dtp->SourceString;
  136. if($this->PageSize=="")
  137. {
  138. $this->PageSize = 20;
  139. }
  140. $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  141. if($this->PageNo==1)
  142. {
  143. $this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET result='".$this->TotalResult."' WHERE keyword='".addslashes($keyword)."'; ");
  144. }
  145. }
  146. //php4构造函数
  147. function SearchView($typeid,$keyword,$orderby,$achanneltype="all",
  148. $searchtype="",$starttime=0,$upagesize=20,$kwtype=1,$mid=0)
  149. {
  150. $this->__construct($typeid,$keyword,$orderby,$achanneltype,$searchtype,$starttime,$upagesize,$kwtype,$mid);
  151. }
  152. //关闭相关资源
  153. function Close()
  154. {
  155. }
  156. /**
  157. * 获得关键字的分词结果,并保存到数据库
  158. *
  159. * @access public
  160. * @param string $keyword 关键词
  161. * @return string
  162. */
  163. function GetKeywords($keyword)
  164. {
  165. global $cfg_soft_lang;
  166. global $cfg_bizcore_appid,$cfg_bizcore_key,$cfg_bizcore_hostname,$cfg_bizcore_port;
  167. $keyword = cn_substr($keyword, 50);
  168. $row = $this->dsql->GetOne("SELECT spwords FROM `#@__search_keywords` WHERE keyword='".addslashes($keyword)."'; ");
  169. if(!is_array($row))
  170. {
  171. if(strlen($keyword)>7)
  172. {
  173. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  174. $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port);
  175. $client->appid = $cfg_bizcore_appid;
  176. $client->key = $cfg_bizcore_key;
  177. $data = $client->Spliteword($keyword);
  178. $kvs = explode(",", $data->data);
  179. $keywords = $keyword." ";
  180. foreach ($kvs as $key => $value) {
  181. $keywords .= ' '.$value;
  182. }
  183. $keywords = preg_replace("/[ ]{1,}/", " ", $keywords);
  184. $client->Close();
  185. // var_dump($keywords);exit;
  186. } else {
  187. $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
  188. $sp->SetSource($keyword, $cfg_soft_lang, $cfg_soft_lang);
  189. $sp->SetResultType(2);
  190. $sp->StartAnalysis(TRUE);
  191. $keywords = $sp->GetFinallyResult();
  192. $idx_keywords = $sp->GetFinallyIndex();
  193. ksort($idx_keywords);
  194. $keywords = $keyword.' ';
  195. foreach ($idx_keywords as $key => $value) {
  196. if (strlen($key) <= 3) {
  197. continue;
  198. }
  199. $keywords .= ' '.$key;
  200. }
  201. $keywords = preg_replace("/[ ]{1,}/", " ", $keywords);
  202. // var_dump($keywords);exit();
  203. unset($sp);
  204. }
  205. }
  206. else
  207. {
  208. $keywords = $keyword;
  209. }
  210. $inquery = "INSERT INTO `#@__search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`)
  211. VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); ";
  212. $this->dsql->ExecuteNoneQuery($inquery);
  213. }
  214. else
  215. {
  216. $this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET count=count+1,lasttime='".time()."' WHERE keyword='".addslashes($keyword)."'; ");
  217. $keywords = $row['spwords'];
  218. }
  219. return $keywords;
  220. }
  221. /**
  222. * 获得关键字SQL
  223. *
  224. * @access private
  225. * @return string
  226. */
  227. function GetKeywordSql()
  228. {
  229. $ks = explode(' ',$this->Keywords);
  230. $kwsql = '';
  231. $kwsqls = array();
  232. foreach($ks as $k)
  233. {
  234. $k = trim($k);
  235. if(strlen($k)<1)
  236. {
  237. continue;
  238. }
  239. if(ord($k[0])>0x80 && strlen($k)<2)
  240. {
  241. continue;
  242. }
  243. $k = addslashes($k);
  244. if($this->ChannelType < 0 || $this->ChannelTypeid < 0){
  245. $kwsqls[] = " arc.title LIKE '%$k%' ";
  246. }else{
  247. if($this->SearchType=="title"){
  248. $kwsqls[] = " arc.title LIKE '%$k%' ";
  249. }else{
  250. $kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) LIKE '%$k%' ";
  251. }
  252. }
  253. }
  254. if(!isset($kwsqls[0]))
  255. {
  256. return '';
  257. }
  258. else
  259. {
  260. if($this->KType==1)
  261. {
  262. $kwsql = join(' OR ',$kwsqls);
  263. }
  264. else
  265. {
  266. $kwsql = join(' And ',$kwsqls);
  267. }
  268. return $kwsql;
  269. }
  270. }
  271. /**
  272. * 获得相关的关键字
  273. *
  274. * @access public
  275. * @param string $num 关键词数目
  276. * @return string
  277. */
  278. function GetLikeWords($num=8)
  279. {
  280. $ks = explode(' ',$this->Keywords);
  281. $lsql = '';
  282. foreach($ks as $k)
  283. {
  284. $k = trim($k);
  285. if(strlen($k)<2)
  286. {
  287. continue;
  288. }
  289. if(ord($k[0])>0x80 && strlen($k)<2)
  290. {
  291. continue;
  292. }
  293. $k = addslashes($k);
  294. if($lsql=='')
  295. {
  296. $lsql = $lsql." CONCAT(spwords,' ') LIKE '%$k %' ";
  297. }else{
  298. $lsql = $lsql." OR CONCAT(spwords,' ') LIKE '%$k %' ";
  299. }
  300. }
  301. if($lsql=='')
  302. {
  303. return '';
  304. }
  305. else
  306. {
  307. $likeword = '';
  308. $lsql = "(".$lsql.") AND NOT(keyword like '".addslashes($this->Keyword)."') ";
  309. $this->dsql->SetQuery("SELECT keyword,count FROM `#@__search_keywords` WHERE $lsql ORDER BY lasttime DESC LIMIT 0,$num; ");
  310. $this->dsql->Execute('l');
  311. while($row=$this->dsql->GetArray('l'))
  312. {
  313. if($row['count']>1000)
  314. {
  315. $fstyle=" style='font-size:11pt;color:red'";
  316. }
  317. else if($row['count']>300)
  318. {
  319. $fstyle=" style='font-size:10pt;color:green'";
  320. }
  321. else
  322. {
  323. $style = "";
  324. }
  325. $likeword .= " <a href='search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'".$style."><u>".$row['keyword']."</u></a> ";
  326. }
  327. return $likeword;
  328. }
  329. }
  330. /**
  331. * 加粗关键字
  332. *
  333. * @access private
  334. * @param string $fstr 关键词字符
  335. * @return string
  336. */
  337. function GetRedKeyWord($fstr)
  338. {
  339. //echo $fstr;
  340. $ks = explode(' ',$this->Keywords);
  341. foreach($ks as $k)
  342. {
  343. $k = trim($k);
  344. if($k=='')
  345. {
  346. continue;
  347. }
  348. if(ord($k[0])>0x80 && strlen($k)<2)
  349. {
  350. continue;
  351. }
  352. // 这里不区分大小写进行关键词替换
  353. $fstr = str_ireplace($k, "<font color='red'>$k</font>", $fstr);
  354. // 速度更快,效率更高
  355. //$fstr = str_replace($k, "<font color='red'>$k</font>", $fstr);
  356. }
  357. return $fstr;
  358. }
  359. // Sphinx记录统计
  360. function CountRecordSphinx()
  361. {
  362. $this->TotalResult = -1;
  363. if(isset($GLOBALS['TotalResult']))
  364. {
  365. $this->TotalResult = $GLOBALS['TotalResult'];
  366. $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
  367. }
  368. if(isset($GLOBALS['PageNo']))
  369. {
  370. $this->PageNo = intval($GLOBALS['PageNo']);
  371. }
  372. else
  373. {
  374. $this->PageNo = 1;
  375. }
  376. if($this->StartTime > 0)
  377. {
  378. $this->sphinx->SetFilterRange('senddate', $this->StartTime, time(), false);
  379. }
  380. if($this->TypeID > 0)
  381. {
  382. $this->sphinx->SetFilter('typeid', GetSonIds($this->TypeID));
  383. }
  384. $this->sphinx->SetFilter('channel', array(1));
  385. if($this->mid > 0)
  386. {
  387. $this->sphinx->SetFilter('mid', $this->mid);
  388. }
  389. //$this->sphinx->SetFilterRange('arcrank', -1, 100, false);
  390. // var_dump($this->sphinx);exit;
  391. $res = array();
  392. $res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk');
  393. $this->TotalResult = $res['total'];
  394. }
  395. /**
  396. * 统计列表里的记录
  397. *
  398. * @access public
  399. * @return string
  400. */
  401. function CountRecord()
  402. {
  403. $this->TotalResult = -1;
  404. if(isset($GLOBALS['TotalResult']))
  405. {
  406. $this->TotalResult = $GLOBALS['TotalResult'];
  407. $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
  408. }
  409. if(isset($GLOBALS['PageNo']))
  410. {
  411. $this->PageNo = intval($GLOBALS['PageNo']);
  412. }
  413. else
  414. {
  415. $this->PageNo = 1;
  416. }
  417. $ksql = $this->GetKeywordSql();
  418. $ksqls = array();
  419. if($this->StartTime > 0)
  420. {
  421. $ksqls[] = " arc.senddate>'".$this->StartTime."' ";
  422. }
  423. if($this->TypeID > 0)
  424. {
  425. $ksqls[] = " typeid IN (".GetSonIds($this->TypeID).") ";
  426. }
  427. if($this->ChannelType > 0)
  428. {
  429. $ksqls[] = " arc.channel='".$this->ChannelType."'";
  430. }
  431. if($this->mid > 0)
  432. {
  433. $ksqls[] = " arc.mid = '".$this->mid."'";
  434. }
  435. $ksqls[] = " arc.arcrank > -1 ";
  436. $this->AddSql = ($ksql=='' ? join(' AND ',$ksqls) : join(' AND ',$ksqls)." AND ($ksql)" );
  437. if($this->ChannelType < 0 || $this->ChannelTypeid< 0){
  438. if($this->ChannelType=="0") $id=$this->ChannelTypeid;
  439. else $id=$this->ChannelType;
  440. $row = $this->dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id=$id");
  441. $addtable = trim($row['addtable']);
  442. $this->AddTable=$addtable;
  443. }else{
  444. $this->AddTable="#@__archives";
  445. }
  446. $cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql;
  447. //var_dump($cquery);
  448. $hascode = md5($cquery);
  449. $row = $this->dsql->GetOne("SELECT * FROM `#@__arccache` WHERE `md5hash`='".$hascode."' ");
  450. $uptime = time();
  451. if(is_array($row) && time()-$row['uptime'] < 3600 * 24)
  452. {
  453. $aids = explode(',', $row['cachedata']);
  454. $this->TotalResult = count($aids)-1;
  455. $this->RsFields = $row['cachedata'];
  456. }
  457. else
  458. {
  459. if($this->TotalResult==-1)
  460. {
  461. $this->dsql->SetQuery($cquery);
  462. $this->dsql->execute();
  463. $aidarr = array();
  464. $aidarr[] = 0;
  465. while($row = $this->dsql->getarray())
  466. {
  467. if($this->ChannelType< 0 ||$this->ChannelTypeid< 0) $aidarr[] = $row['aid'];
  468. else $aidarr[] = $row['id'];
  469. }
  470. $nums = count($aidarr)-1;
  471. $aids = implode(',', $aidarr);
  472. $delete = "DELETE FROM `#@__arccache` WHERE uptime<".(time() - 3600 * 24);
  473. $this->dsql->SetQuery($delete);
  474. $this->dsql->executenonequery();
  475. $insert = "INSERT INTO `#@__arccache` (`md5hash`, `uptime`, `cachedata`)
  476. VALUES('$hascode', '$uptime', '$aids')";
  477. $this->dsql->SetQuery($insert);
  478. $this->dsql->executenonequery();
  479. $this->TotalResult = $nums;
  480. }
  481. }
  482. }
  483. /**
  484. * 显示列表
  485. *
  486. * @access public
  487. * @param string
  488. * @return string
  489. */
  490. function Display()
  491. {
  492. foreach($this->dtp->CTags as $tagid=>$ctag)
  493. {
  494. $tagname = $ctag->GetName();
  495. if($tagname=="list")
  496. {
  497. $limitstart = ($this->PageNo-1) * $this->PageSize;
  498. $row = $this->PageSize;
  499. if(trim($ctag->GetInnerText())=="")
  500. {
  501. $InnerText = GetSysTemplets("list_fulllist.htm");
  502. }
  503. else
  504. {
  505. $InnerText = trim($ctag->GetInnerText());
  506. }
  507. $this->dtp->Assign($tagid,
  508. $this->GetArcList($limitstart,
  509. $row,
  510. $ctag->GetAtt("col"),
  511. $ctag->GetAtt("titlelen"),
  512. $ctag->GetAtt("infolen"),
  513. $ctag->GetAtt("imgwidth"),
  514. $ctag->GetAtt("imgheight"),
  515. $this->ChannelType,
  516. $this->OrderBy,
  517. $InnerText,
  518. $ctag->GetAtt("tablewidth"))
  519. );
  520. }
  521. else if($tagname=="pagelist")
  522. {
  523. $list_len = trim($ctag->GetAtt("listsize"));
  524. if($list_len=="")
  525. {
  526. $list_len = 3;
  527. }
  528. $this->dtp->Assign($tagid,$this->GetPageListDM($list_len));
  529. }
  530. else if($tagname=="likewords")
  531. {
  532. $this->dtp->Assign($tagid,$this->GetLikeWords($ctag->GetAtt('num')));
  533. }
  534. else if($tagname=="hotwords")
  535. {
  536. $this->dtp->Assign($tagid,lib_hotwords($ctag,$this));
  537. }
  538. else if($tagname=="field")
  539. {
  540. //类别的指定字段
  541. if(isset($this->Fields[$ctag->GetAtt('name')]))
  542. {
  543. $this->dtp->Assign($tagid,$this->Fields[$ctag->GetAtt('name')]);
  544. }
  545. else
  546. {
  547. $this->dtp->Assign($tagid,"");
  548. }
  549. }
  550. else if($tagname=="channel")
  551. {
  552. //下级频道列表
  553. if($this->TypeID>0)
  554. {
  555. $typeid = $this->TypeID; $reid = $this->TypeLink->TypeInfos['reid'];
  556. }
  557. else
  558. {
  559. $typeid = 0; $reid=0;
  560. }
  561. $GLOBALS['envs']['typeid'] = $typeid;
  562. $GLOBALS['envs']['reid'] = $typeid;
  563. $this->dtp->Assign($tagid,lib_channel($ctag,$this));
  564. }//End if
  565. }
  566. global $keyword, $oldkeyword;
  567. if(!empty($oldkeyword)) $keyword = $oldkeyword;
  568. $this->dtp->Display();
  569. }
  570. /**
  571. * 获得文档列表
  572. *
  573. * @access public
  574. * @param int $limitstart 限制开始
  575. * @param int $row 行数
  576. * @param int $col 列数
  577. * @param int $titlelen 标题长度
  578. * @param int $infolen 描述长度
  579. * @param int $imgwidth 图片宽度
  580. * @param int $imgheight 图片高度
  581. * @param string $achanneltype 列表类型
  582. * @param string $orderby 排列顺序
  583. * @param string $innertext 底层模板
  584. * @param string $tablewidth 表格宽度
  585. * @return string
  586. */
  587. function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,
  588. $imgwidth=120,$imgheight=90,$achanneltype="all",$orderby="default",$innertext="",$tablewidth="100")
  589. {
  590. global $cfg_sphinx_article;
  591. $typeid=$this->TypeID;
  592. if($row=='') $row = 10;
  593. if($limitstart=='') $limitstart = 0;
  594. if($titlelen=='') $titlelen = 30;
  595. if($infolen=='') $infolen = 250;
  596. if($imgwidth=='') $imgwidth = 120;
  597. if($imgheight='') $imgheight = 120;
  598. if($achanneltype=='') $achanneltype = '0';
  599. $orderby = $orderby=='' ? 'default' : strtolower($orderby);
  600. $tablewidth = str_replace("%","",$tablewidth);
  601. if($tablewidth=='') $tablewidth=100;
  602. if($col=='') $col=1;
  603. $colWidth = ceil(100/$col);
  604. $tablewidth = $tablewidth."%";
  605. $colWidth = $colWidth."%";
  606. $innertext = trim($innertext);
  607. if($innertext=='')
  608. {
  609. $innertext = GetSysTemplets("search_list.htm");
  610. }
  611. if ($cfg_sphinx_article == 'Y')
  612. {
  613. $ordersql = '';
  614. if($this->ChannelType< 0 ||$this->ChannelTypeid< 0)
  615. {
  616. if($orderby=="id"){
  617. $ordersql="@id desc";
  618. }else{
  619. $ordersql="@senddate desc";
  620. }
  621. } else {
  622. if($orderby=="senddate")
  623. {
  624. $ordersql="@senddate desc";
  625. }
  626. else if($orderby=="pubdate")
  627. {
  628. $ordersql="@pubdate desc";
  629. }
  630. else if($orderby=="id")
  631. {
  632. $ordersql="@id desc";
  633. }
  634. else
  635. {
  636. $ordersql="@sortrank desc";
  637. }
  638. }
  639. $this->sphinx->SetLimits($limitstart, (int)$row, ($row>1000) ? $row : 1000);
  640. $res = array();
  641. $res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk');
  642. foreach ($res['words'] as $k => $v) {
  643. $this->Keywords .= " $k";
  644. }
  645. foreach($res['matches'] as $_v) {
  646. $aids[] = $_v['id'];
  647. }
  648. $aids = @implode(',', $aids);
  649. //搜索
  650. $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
  651. act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
  652. FROM `#@__archives` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id
  653. WHERE arc.id IN ($aids)";
  654. } else {
  655. //排序方式
  656. $ordersql = '';
  657. if($this->ChannelType< 0 ||$this->ChannelTypeid< 0)
  658. {
  659. if($orderby=="id"){
  660. $ordersql="ORDER BY arc.aid desc";
  661. }else{
  662. $ordersql="ORDER BY arc.senddate desc";
  663. }
  664. } else {
  665. if($orderby=="senddate")
  666. {
  667. $ordersql=" ORDER BY arc.senddate desc";
  668. }
  669. else if($orderby=="pubdate")
  670. {
  671. $ordersql=" ORDER BY arc.pubdate desc";
  672. }
  673. else if($orderby=="id")
  674. {
  675. $ordersql=" ORDER BY arc.id desc";
  676. }
  677. else
  678. {
  679. $ordersql=" ORDER BY arc.sortrank desc";
  680. }
  681. }
  682. //搜索
  683. $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
  684. act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
  685. FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id
  686. WHERE {$this->AddSql} $ordersql LIMIT $limitstart,$row";
  687. }
  688. $this->dsql->SetQuery($query);
  689. $this->dsql->Execute("al");
  690. $artlist = "";
  691. if($col>1)
  692. {
  693. $artlist = "<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\r\n";
  694. }
  695. $this->dtp2->LoadSource($innertext);
  696. for($i=0;$i<$row;$i++)
  697. {
  698. if($col>1)
  699. {
  700. $artlist .= "<tr>\r\n";
  701. }
  702. for($j=0;$j<$col;$j++)
  703. {
  704. if($col>1)
  705. {
  706. $artlist .= "<td width='$colWidth'>\r\n";
  707. }
  708. if($row = $this->dsql->GetArray("al"))
  709. {
  710. if($this->ChannelType< 0 || $this->ChannelTypeid< 0) {
  711. $row["id"]=$row["aid"];
  712. $row["ismake"]=empty($row["ismake"])? "" : $row["ismake"];
  713. $row["filename"]=empty($row["filename"])? "" : $row["filename"];
  714. $row["money"]=empty($row["money"])? "" : $row["money"];
  715. $row["description"]=empty($row["description "])? "" : $row["description"];
  716. $row["pubdate"]=empty($row["pubdate "])? $row["senddate"] : $row["pubdate"];
  717. }
  718. //处理一些特殊字段
  719. $row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"],
  720. $row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]);
  721. $row["description"] = $this->GetRedKeyWord(cn_substr($row["description"],$infolen));
  722. $row["title"] = $this->GetRedKeyWord(cn_substr($row["title"],$titlelen));
  723. $row["id"] = $row["id"];
  724. if($row['litpic'] == '-' || $row['litpic'] == '')
  725. {
  726. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  727. }
  728. if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  729. {
  730. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  731. }
  732. $row['picname'] = $row['litpic'];
  733. $row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"],$row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]);
  734. $row["info"] = $row["description"];
  735. $row["filename"] = $row["arcurl"];
  736. $row["stime"] = GetDateMK($row["pubdate"]);
  737. $row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>";
  738. $row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]";
  739. $row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'></a>";
  740. $row["image"] = "<img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'>";
  741. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  742. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  743. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  744. if(is_array($this->dtp2->CTags))
  745. {
  746. foreach($this->dtp2->CTags as $k=>$ctag)
  747. {
  748. if($ctag->GetName()=='array')
  749. {
  750. //传递整个数组,在runphp模式中有特殊作用
  751. $this->dtp2->Assign($k,$row);
  752. }
  753. else
  754. {
  755. if(isset($row[$ctag->GetName()]))
  756. {
  757. $this->dtp2->Assign($k,$row[$ctag->GetName()]);
  758. }
  759. else
  760. {
  761. $this->dtp2->Assign($k,'');
  762. }
  763. }
  764. }
  765. }
  766. $artlist .= $this->dtp2->GetResult();
  767. }//if hasRow
  768. else
  769. {
  770. $artlist .= "";
  771. }
  772. if($col>1) $artlist .= "</td>\r\n";
  773. }//Loop Col
  774. if($col>1)
  775. {
  776. $artlist .= "</tr>\r\n";
  777. }
  778. }//Loop Line
  779. if($col>1)
  780. {
  781. $artlist .= "</table>\r\n";
  782. }
  783. $this->dsql->FreeResult("al");
  784. return $artlist;
  785. }
  786. /**
  787. * 获取动态的分页列表
  788. *
  789. * @access public
  790. * @param string $list_len 列表宽度
  791. * @return string
  792. */
  793. function GetPageListDM($list_len)
  794. {
  795. global $oldkeyword;
  796. $prepage="";
  797. $nextpage="";
  798. $prepagenum = $this->PageNo - 1;
  799. $nextpagenum = $this->PageNo + 1;
  800. if($list_len=="" || preg_match("/[^0-9]/", $list_len))
  801. {
  802. $list_len=3;
  803. }
  804. $totalpage = ceil($this->TotalResult / $this->PageSize);
  805. if($totalpage<=1 && $this->TotalResult>0)
  806. {
  807. return "<ul class=\"pagination justify-content-center pt-3\"><li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共1页/".$this->TotalResult."条记录</span></li></ul>";
  808. }
  809. if($this->TotalResult == 0)
  810. {
  811. return "<ul class=\"pagination justify-content-center pt-3\"><li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共0页/".$this->TotalResult."条记录</span></li></ul>";
  812. }
  813. $purl = $this->GetCurUrl();
  814. $oldkeyword = (empty($oldkeyword) ? $this->Keyword : $oldkeyword);
  815. //当结果超过限制时,重设结果页数
  816. if($this->TotalResult > $this->SearchMaxRc)
  817. {
  818. $totalpage = ceil($this->SearchMaxRc/$this->PageSize);
  819. }
  820. $infos = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共找到<b>".$this->TotalResult."</b>条记录/最大显示<b>{$totalpage}</b>页</span></li>\r\n";
  821. $geturl = "keyword=".urlencode($oldkeyword)."&searchtype=".$this->SearchType;
  822. $hidenform = "<input type='hidden' name='keyword' value='".rawurldecode($oldkeyword)."'>\r\n";
  823. $geturl .= "&channeltype=".$this->ChannelType."&orderby=".$this->OrderBy;
  824. $hidenform .= "<input type='hidden' name='channeltype' value='".$this->ChannelType."'>\r\n";
  825. $hidenform .= "<input type='hidden' name='orderby' value='".$this->OrderBy."'>\r\n";
  826. $geturl .= "&kwtype=".$this->KType."&pagesize=".$this->PageSize;
  827. $hidenform .= "<input type='hidden' name='kwtype' value='".$this->KType."'>\r\n";
  828. $hidenform .= "<input type='hidden' name='pagesize' value='".$this->PageSize."'>\r\n";
  829. $geturl .= "&typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  830. $hidenform .= "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
  831. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  832. $purl .= "?".$geturl;
  833. //获得上一页和下一页的链接
  834. if($this->PageNo != 1)
  835. {
  836. $prepage.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  837. $indexpage="<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a></li>\r\n";
  838. }
  839. else
  840. {
  841. $indexpage="<li class='page-item disabled'><a class='page-link'>首页</a></li>\r\n";
  842. }
  843. if($this->PageNo!=$totalpage && $totalpage>1)
  844. {
  845. $nextpage.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  846. $endpage="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  847. }
  848. else
  849. {
  850. $endpage="<li class='page-item'><a class='page-link'>末页</a></li>\r\n";
  851. }
  852. //获得数字链接
  853. $listdd="";
  854. $total_list = $list_len * 2 + 1;
  855. if($this->PageNo >= $total_list)
  856. {
  857. $j = $this->PageNo - $list_len;
  858. $total_list = $this->PageNo + $list_len;
  859. if($total_list > $totalpage)
  860. {
  861. $total_list = $totalpage;
  862. }
  863. }
  864. else
  865. {
  866. $j=1;
  867. if($total_list > $totalpage)
  868. {
  869. $total_list = $totalpage;
  870. }
  871. }
  872. for($j; $j<=$total_list; $j++)
  873. {
  874. if($j == $this->PageNo)
  875. {
  876. $listdd.= "<li class='page-item active'><a class='page-link'>$j&nbsp;</a></li>\r\n";
  877. }
  878. else
  879. {
  880. $listdd.="<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a>&nbsp;</li>\r\n";
  881. }
  882. }
  883. $plist = "";
  884. // $plist = "<table border='0' cellpadding='0' cellspacing='0'>\r\n";
  885. // $plist .= "<tr align='center' style='font-size:10pt'>\r\n";
  886. $plist .= "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
  887. $plist .= "<ul class=\"pagination justify-content-center pt-3\">";
  888. $plist .= $infos;
  889. $plist .= $indexpage;
  890. $plist .= $prepage;
  891. $plist .= $listdd;
  892. $plist .= $nextpage;
  893. $plist .= $endpage;
  894. // if($totalpage>$total_list)
  895. // {
  896. // $plist.="<td width='38'><input type='text' name='PageNo' style='width:28px;height:14px' value='".$this->PageNo."' /></td>\r\n";
  897. // $plist.="<td width='30'><input type='submit' name='plistgo' value='GO' style='width:30px;height:22px;font-size:9pt' /></td>\r\n";
  898. // }
  899. $plist .= "</ul></form>\r\n";
  900. return $plist;
  901. }
  902. /**
  903. * 获得当前的页面文件的url
  904. *
  905. * @access public
  906. * @return string
  907. */
  908. function GetCurUrl()
  909. {
  910. if(!empty($_SERVER["REQUEST_URI"]))
  911. {
  912. $nowurl = $_SERVER["REQUEST_URI"];
  913. $nowurls = explode("?",$nowurl);
  914. $nowurl = $nowurls[0];
  915. }
  916. else
  917. {
  918. $nowurl = $_SERVER["PHP_SELF"];
  919. }
  920. return $nowurl;
  921. }
  922. }//End Class