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

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