国内流行的内容管理系统(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.

947 lines
33KB

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