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

745 lines
30KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 搜索视图类
  5. *
  6. * @version $Id: searchview.class.php 1 15:26 2010年7月7日Z tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC."/typelink/typelink.class.php");
  13. require_once(DEDEINC."/dedetag.class.php");
  14. require_once(DEDEINC."/libraries/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 DedeBIZ.Libraries
  24. * @link https://www.dedebiz.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. /**
  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(
  69. $typeid,
  70. $keyword,
  71. $orderby,
  72. $achanneltype = "all",
  73. $searchtype = '',
  74. $starttime = 0,
  75. $upagesize = 20,
  76. $kwtype = 1,
  77. $mid = 0
  78. ) {
  79. global $cfg_search_max, $cfg_search_maxrc, $cfg_search_time,$envs;
  80. if (empty($upagesize)) {
  81. $upagesize = 10;
  82. }
  83. $this->TypeID = $typeid;
  84. $this->Keyword = $keyword;
  85. $this->OrderBy = $orderby;
  86. $this->KType = $kwtype;
  87. $this->pagesize = (int)$upagesize;
  88. $this->StartTime = $starttime;
  89. $this->ChannelType = $achanneltype;
  90. $this->SearchMax = $cfg_search_max;
  91. $this->SearchMaxRc = $cfg_search_maxrc;
  92. $this->SearchTime = $cfg_search_time;
  93. $this->mid = $mid;
  94. $this->RsFields = '';
  95. $this->SearchType = $searchtype == '' ? 'titlekeyword' : $searchtype;
  96. $this->dsql = $GLOBALS['dsql'];
  97. $this->dtp = new DedeTagParse();
  98. $this->dtp->SetRefObj($this);
  99. $this->dtp->SetNameSpace("dede", "{", "}");
  100. $this->dtp2 = new DedeTagParse();
  101. $this->dtp2->SetNameSpace("field", "[", "]");
  102. $this->TypeLink = new TypeLink($typeid);
  103. //通过分词获取关键词
  104. $this->Keywords = $this->GetKeywords($keyword);
  105. //设置一些全局参数的值
  106. if ($this->TypeID == "0") {
  107. $this->ChannelTypeid = 1;
  108. } else {
  109. $row = $this->dsql->GetOne("SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}");
  110. $this->ChannelTypeid = $row['channeltype'];
  111. }
  112. foreach ($GLOBALS['PubFields'] as $k => $v) {
  113. $this->Fields[$k] = $v;
  114. }
  115. $this->CountRecord();
  116. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
  117. if (!file_exists($tempfile) || !is_file($tempfile)) {
  118. echo "模板文件不存在,无法解析";
  119. exit();
  120. }
  121. $this->dtp->LoadTemplate($tempfile);
  122. $this->TempInfos['tags'] = $this->dtp->CTags;
  123. $this->TempInfos['source'] = $this->dtp->SourceString;
  124. if ($this->pagesize == "") {
  125. $this->pagesize = 30;
  126. }
  127. $this->TotalPage = ceil($this->TotalResult / $this->pagesize);
  128. if ($this->PageNo == 1) {
  129. $this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET result='".$this->TotalResult."' WHERE keyword='".addslashes($keyword)."'; ");
  130. }
  131. $envs['url_type'] = 3;
  132. $envs['value'] = $keyword;
  133. }
  134. //php4构造函数
  135. function SearchView(
  136. $typeid,
  137. $keyword,
  138. $orderby,
  139. $achanneltype = "all",
  140. $searchtype = "",
  141. $starttime = 0,
  142. $upagesize = 20,
  143. $kwtype = 1,
  144. $mid = 0
  145. ) {
  146. $this->__construct($typeid, $keyword, $orderby, $achanneltype, $searchtype, $starttime, $upagesize, $kwtype, $mid);
  147. }
  148. //关闭相关资源
  149. function Close()
  150. {
  151. }
  152. /**
  153. * 获得关键词的分词结果,并保存到数据库
  154. *
  155. * @access public
  156. * @param string $keyword 关键词
  157. * @return string
  158. */
  159. function GetKeywords($keyword)
  160. {
  161. global $cfg_soft_lang;
  162. global $cfg_bizcore_appid, $cfg_bizcore_key, $cfg_bizcore_hostname, $cfg_bizcore_port;
  163. $keyword = cn_substr($keyword, 50);
  164. $row = $this->dsql->GetOne("SELECT spwords FROM `#@__search_keywords` WHERE keyword='".addslashes($keyword)."'; ");
  165. if (!is_array($row)) {
  166. if (strlen($keyword) > 7) {
  167. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  168. $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port);
  169. $client->appid = $cfg_bizcore_appid;
  170. $client->key = $cfg_bizcore_key;
  171. $data = $client->Spliteword($keyword);
  172. $kvs = explode(",", $data->data);
  173. $keywords = $keyword." ";
  174. foreach ($kvs as $key => $value) {
  175. $keywords .= ' '.$value;
  176. }
  177. $keywords = preg_replace("/[ ]{1,}/", " ", $keywords);
  178. $client->Close();
  179. //var_dump($keywords);exit;
  180. } else {
  181. $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
  182. $sp->SetSource($keyword, $cfg_soft_lang, $cfg_soft_lang);
  183. $sp->SetResultType(2);
  184. $sp->StartAnalysis(TRUE);
  185. $keywords = $sp->GetFinallyResult();
  186. $idx_keywords = $sp->GetFinallyIndex();
  187. ksort($idx_keywords);
  188. $keywords = $keyword.' ';
  189. foreach ($idx_keywords as $key => $value) {
  190. if (strlen($key) <= 3) {
  191. continue;
  192. }
  193. $keywords .= ' '.$key;
  194. }
  195. $keywords = preg_replace("/[ ]{1,}/", " ", $keywords);
  196. //var_dump($keywords);exit();
  197. unset($sp);
  198. }
  199. } else {
  200. $keywords = $keyword;
  201. }
  202. $inquery = "INSERT INTO `#@__search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`)
  203. VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); ";
  204. $this->dsql->ExecuteNoneQuery($inquery);
  205. } else {
  206. $this->dsql->ExecuteNoneQuery("UPDATE `#@__search_keywords` SET count=count+1,lasttime='".time()."' WHERE keyword='".addslashes($keyword)."'; ");
  207. $keywords = $row['spwords'];
  208. }
  209. return $keywords;
  210. }
  211. /**
  212. * 获得关键词SQL
  213. *
  214. * @access private
  215. * @return string
  216. */
  217. function GetKeywordSql()
  218. {
  219. $ks = explode(' ', $this->Keywords);
  220. $kwsql = '';
  221. $kwsqls = array();
  222. foreach ($ks as $k) {
  223. $k = trim($k);
  224. if (strlen($k) < 1) {
  225. continue;
  226. }
  227. if (ord($k[0]) > 0x80 && strlen($k) < 2) {
  228. continue;
  229. }
  230. $k = addslashes($k);
  231. if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) {
  232. $kwsqls[] = " arc.title LIKE '%$k%' ";
  233. } else {
  234. if ($this->SearchType == "title") {
  235. $kwsqls[] = " arc.title LIKE '%$k%' ";
  236. } else {
  237. $kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) LIKE '%$k%' ";
  238. }
  239. }
  240. }
  241. if (!isset($kwsqls[0])) {
  242. return '';
  243. } else {
  244. if ($this->KType == 1) {
  245. $kwsql = join(' OR ', $kwsqls);
  246. } else {
  247. $kwsql = join(' And ', $kwsqls);
  248. }
  249. return $kwsql;
  250. }
  251. }
  252. /**
  253. * 获得相关的关键词
  254. *
  255. * @access public
  256. * @param string $num 关键词数目
  257. * @return string
  258. */
  259. function GetLikeWords($num = 8)
  260. {
  261. $ks = explode(' ', $this->Keywords);
  262. $lsql = '';
  263. foreach ($ks as $k) {
  264. $k = trim($k);
  265. if (strlen($k) < 2) {
  266. continue;
  267. }
  268. if (ord($k[0]) > 0x80 && strlen($k) < 2) {
  269. continue;
  270. }
  271. $k = addslashes($k);
  272. if ($lsql == '') {
  273. $lsql = $lsql." CONCAT(spwords,' ') LIKE '%$k %' ";
  274. } else {
  275. $lsql = $lsql." OR CONCAT(spwords,' ') LIKE '%$k %' ";
  276. }
  277. }
  278. if ($lsql == '') {
  279. return '';
  280. } else {
  281. $likeword = '';
  282. $lsql = "(".$lsql.") AND NOT(keyword like '".addslashes($this->Keyword)."') ";
  283. $this->dsql->SetQuery("SELECT keyword,count FROM `#@__search_keywords` WHERE $lsql ORDER BY lasttime DESC LIMIT 0,$num; ");
  284. $this->dsql->Execute('l');
  285. while ($row = $this->dsql->GetArray('l')) {
  286. if ($row['count'] > 1000) {
  287. $fstyle = " style='font-size:11pt;color:red'";
  288. } else if ($row['count'] > 300) {
  289. $fstyle = " style='font-size:10pt;color:green'";
  290. } else {
  291. $style = "";
  292. }
  293. $likeword .= " <a href='search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'".$style.">".$row['keyword']."</a> ";
  294. }
  295. return $likeword;
  296. }
  297. }
  298. /**
  299. * 加粗关键词
  300. *
  301. * @access private
  302. * @param string $fstr 关键词字符
  303. * @return string
  304. */
  305. function GetRedKeyWord($fstr)
  306. {
  307. //echo $fstr;
  308. $ks = explode(' ', $this->Keywords);
  309. foreach ($ks as $k) {
  310. $k = trim($k);
  311. if ($k == '') {
  312. continue;
  313. }
  314. if (ord($k[0]) > 0x80 && strlen($k) < 2) {
  315. continue;
  316. }
  317. //这里不区分大小写进行关键词替换
  318. $fstr = str_ireplace($k, "<span class='text-danger'>$k</span>", $fstr);
  319. //速度更快,效率更高
  320. //$fstr = str_replace($k, "<span class='text-danger'>$k</span>", $fstr);
  321. }
  322. return $fstr;
  323. }
  324. /**
  325. * 统计列表里的记录
  326. *
  327. * @access public
  328. * @return string
  329. */
  330. function CountRecord()
  331. {
  332. $this->TotalResult = -1;
  333. if (isset($GLOBALS['TotalResult'])) {
  334. $this->TotalResult = $GLOBALS['TotalResult'];
  335. $this->TotalResult = is_numeric($this->TotalResult) ? $this->TotalResult : "";
  336. }
  337. if (isset($GLOBALS['PageNo'])) {
  338. $this->PageNo = intval($GLOBALS['PageNo']);
  339. } else {
  340. $this->PageNo = 1;
  341. }
  342. $ksql = $this->GetKeywordSql();
  343. $ksqls = array();
  344. if ($this->StartTime > 0) {
  345. $ksqls[] = " arc.senddate>'".$this->StartTime."' ";
  346. }
  347. if ($this->TypeID > 0) {
  348. $ksqls[] = " typeid IN (".GetSonIds($this->TypeID).") ";
  349. }
  350. if ($this->ChannelType > 0) {
  351. $ksqls[] = " arc.channel='".$this->ChannelType."'";
  352. }
  353. if ($this->mid > 0) {
  354. $ksqls[] = " arc.mid = '".$this->mid."'";
  355. }
  356. $ksqls[] = " arc.arcrank > -1 ";
  357. $this->AddSql = ($ksql == '' ? join(' AND ', $ksqls) : join(' AND ', $ksqls)." AND ($ksql)");
  358. if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) {
  359. if ($this->ChannelType == "0") $id = $this->ChannelTypeid;
  360. else $id = $this->ChannelType;
  361. $row = $this->dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id=$id");
  362. $addtable = trim($row['addtable']);
  363. $this->AddTable = $addtable;
  364. } else {
  365. $this->AddTable = "#@__archives";
  366. }
  367. $cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql;
  368. //var_dump($cquery);
  369. $hascode = md5($cquery);
  370. $row = $this->dsql->GetOne("SELECT * FROM `#@__arccache` WHERE `md5hash`='".$hascode."' ");
  371. $uptime = time();
  372. if (is_array($row) && time() - $row['uptime'] < 3600 * 24) {
  373. $aids = explode(',', $row['cachedata']);
  374. $this->TotalResult = count($aids) - 1;
  375. $this->RsFields = $row['cachedata'];
  376. } else {
  377. if ($this->TotalResult == -1) {
  378. $this->dsql->SetQuery($cquery);
  379. $this->dsql->execute();
  380. $aidarr = array();
  381. $aidarr[] = 0;
  382. while ($row = $this->dsql->getarray()) {
  383. if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) $aidarr[] = $row['aid'];
  384. else $aidarr[] = $row['id'];
  385. }
  386. $nums = count($aidarr) - 1;
  387. $aids = implode(',', $aidarr);
  388. $delete = "DELETE FROM `#@__arccache` WHERE uptime<".(time() - 3600 * 24);
  389. $this->dsql->SetQuery($delete);
  390. $this->dsql->executenonequery();
  391. $insert = "INSERT INTO `#@__arccache` (`md5hash`, `uptime`, `cachedata`)
  392. VALUES('$hascode', '$uptime', '$aids')";
  393. $this->dsql->SetQuery($insert);
  394. $this->dsql->executenonequery();
  395. $this->TotalResult = $nums;
  396. }
  397. }
  398. }
  399. /**
  400. * 显示列表
  401. *
  402. * @access public
  403. * @param string
  404. * @return string
  405. */
  406. function Display()
  407. {
  408. foreach ($this->dtp->CTags as $tagid => $ctag) {
  409. $tagname = $ctag->GetName();
  410. if ($tagname == "list") {
  411. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  412. $row = $this->pagesize;
  413. if (trim($ctag->GetInnerText()) == "") {
  414. $InnerText = GetSysTemplets("list_fulllist.htm");
  415. } else {
  416. $InnerText = trim($ctag->GetInnerText());
  417. }
  418. $this->dtp->Assign(
  419. $tagid,
  420. $this->GetArcList(
  421. $limitstart,
  422. $row,
  423. $ctag->GetAtt("col"),
  424. $ctag->GetAtt("titlelen"),
  425. $ctag->GetAtt("infolen"),
  426. $ctag->GetAtt("imgwidth"),
  427. $ctag->GetAtt("imgheight"),
  428. $this->ChannelType,
  429. $this->OrderBy,
  430. $InnerText,
  431. $ctag->GetAtt("tablewidth")
  432. )
  433. );
  434. } else if ($tagname == "pagelist") {
  435. $list_len = trim($ctag->GetAtt("listsize"));
  436. $ctag->GetAtt("listitem") == "" ? $listitem = "index,pre,pageno,next,end,option" : $listitem = $ctag->GetAtt("listitem");
  437. if ($list_len == "") {
  438. $list_len = 3;
  439. }
  440. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len, $listitem));
  441. } else if ($tagname == "likewords") {
  442. $this->dtp->Assign($tagid, $this->GetLikeWords($ctag->GetAtt('num')));
  443. } else if ($tagname == "hotwords") {
  444. $this->dtp->Assign($tagid, lib_hotwords($ctag, $this));
  445. } else if ($tagname == "field") {
  446. //类别的指定字段
  447. if (isset($this->Fields[$ctag->GetAtt('name')])) {
  448. $this->dtp->Assign($tagid, $this->Fields[$ctag->GetAtt('name')]);
  449. } else {
  450. $this->dtp->Assign($tagid, "");
  451. }
  452. } else if ($tagname == "channel") {
  453. //下级频道列表
  454. if ($this->TypeID > 0) {
  455. $typeid = $this->TypeID;
  456. $reid = $this->TypeLink->TypeInfos['reid'];
  457. } else {
  458. $typeid = 0;
  459. $reid = 0;
  460. }
  461. $GLOBALS['envs']['typeid'] = $typeid;
  462. $GLOBALS['envs']['reid'] = $typeid;
  463. $this->dtp->Assign($tagid, lib_channel($ctag, $this));
  464. } //End if
  465. }
  466. global $keyword, $oldkeyword;
  467. if (!empty($oldkeyword)) $keyword = $oldkeyword;
  468. $this->dtp->Display();
  469. }
  470. /**
  471. * 获得文档列表
  472. *
  473. * @access public
  474. * @param int $limitstart 限制开始
  475. * @param int $row 行数
  476. * @param int $col 列数
  477. * @param int $titlelen 标题长度
  478. * @param int $infolen 描述长度
  479. * @param int $imgwidth 图片宽度
  480. * @param int $imgheight 图片高度
  481. * @param string $achanneltype 列表类型
  482. * @param string $orderby 排列顺序
  483. * @param string $innertext 底层模板
  484. * @param string $tablewidth 表格宽度
  485. * @return string
  486. */
  487. function GetArcList(
  488. $limitstart = 0,
  489. $row = 10,
  490. $col = 1,
  491. $titlelen = 30,
  492. $infolen = 250,
  493. $imgwidth = 120,
  494. $imgheight = 90,
  495. $achanneltype = "all",
  496. $orderby = "default",
  497. $innertext = "",
  498. $tablewidth = "100"
  499. ) {
  500. $typeid = $this->TypeID;
  501. if ($row == '') $row = 10;
  502. if ($limitstart == '') $limitstart = 0;
  503. if ($titlelen == '') $titlelen = 30;
  504. if ($infolen == '') $infolen = 250;
  505. if ($imgwidth == '') $imgwidth = 120;
  506. if ($imgheight = '') $imgheight = 120;
  507. if ($achanneltype == '') $achanneltype = '0';
  508. $orderby = $orderby == '' ? 'default' : strtolower($orderby);
  509. $tablewidth = str_replace("%", "", $tablewidth);
  510. if ($tablewidth == '') $tablewidth = 100;
  511. if ($col == '') $col = 1;
  512. $colWidth = ceil(100 / $col);
  513. $tablewidth = $tablewidth."%";
  514. $colWidth = $colWidth."%";
  515. $innertext = trim($innertext);
  516. if ($innertext == '') {
  517. $innertext = GetSysTemplets("search_list.htm");
  518. }
  519. //排序方式
  520. $ordersql = '';
  521. if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) {
  522. if ($orderby == "id") {
  523. $ordersql = "ORDER BY arc.aid desc";
  524. } else {
  525. $ordersql = "ORDER BY arc.senddate desc";
  526. }
  527. } else {
  528. if ($orderby == "senddate") {
  529. $ordersql = " ORDER BY arc.senddate desc";
  530. } else if ($orderby == "pubdate") {
  531. $ordersql = " ORDER BY arc.pubdate desc";
  532. } else if ($orderby == "id") {
  533. $ordersql = " ORDER BY arc.id desc";
  534. } else {
  535. $ordersql = " ORDER BY arc.sortrank desc";
  536. }
  537. }
  538. //搜索
  539. $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
  540. act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
  541. FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id
  542. WHERE {$this->AddSql} $ordersql LIMIT $limitstart,$row";
  543. $this->dsql->SetQuery($query);
  544. $this->dsql->Execute("al");
  545. $artlist = "";
  546. if ($col > 1) {
  547. $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  548. }
  549. $this->dtp2->LoadSource($innertext);
  550. for ($i = 0; $i < $row; $i++) {
  551. if ($col > 1) {
  552. $artlist .= "<tr>\r\n";
  553. }
  554. for ($j = 0; $j < $col; $j++) {
  555. if ($col > 1) {
  556. $artlist .= "<td width='$colWidth'>\r\n";
  557. }
  558. if ($row = $this->dsql->GetArray("al")) {
  559. if ($this->ChannelType < 0 || $this->ChannelTypeid < 0) {
  560. $row["id"] = $row["aid"];
  561. $row["ismake"] = empty($row["ismake"]) ? "" : $row["ismake"];
  562. $row["filename"] = empty($row["filename"]) ? "" : $row["filename"];
  563. $row["money"] = empty($row["money"]) ? "" : $row["money"];
  564. $row["description"] = empty($row["description "]) ? "" : $row["description"];
  565. $row["pubdate"] = empty($row["pubdate "]) ? $row["senddate"] : $row["pubdate"];
  566. }
  567. //处理一些特殊字段
  568. $row["arcurl"] = GetFileUrl(
  569. $row["id"],
  570. $row["typeid"],
  571. $row["senddate"],
  572. $row["title"],
  573. $row["ismake"],
  574. $row["arcrank"],
  575. $row["namerule"],
  576. $row["typedir"],
  577. $row["money"],
  578. $row['filename'],
  579. $row["moresite"],
  580. $row["siteurl"],
  581. $row["sitepath"]
  582. );
  583. $row["description"] = $this->GetRedKeyWord(cn_substr($row["description"], $infolen));
  584. $row["title"] = $this->GetRedKeyWord(cn_substr($row["title"], $titlelen));
  585. $row["id"] = $row["id"];
  586. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  587. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/defaultpic.jpg';
  588. }
  589. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  590. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  591. }
  592. $row['picname'] = $row['litpic'];
  593. $row["typeurl"] = GetTypeUrl($row["typeid"], $row["typedir"], $row["isdefault"], $row["defaultname"], $row["ispart"], $row["namerule2"], $row["moresite"], $row["siteurl"], $row["sitepath"]);
  594. $row["info"] = $row["description"];
  595. $row["filename"] = $row["arcurl"];
  596. $row["stime"] = GetDateMK($row["pubdate"]);
  597. $row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>";
  598. $row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]";
  599. $row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'></a>";
  600. $row["image"] = "<img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'>";
  601. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  602. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  603. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  604. if (is_array($this->dtp2->CTags)) {
  605. foreach ($this->dtp2->CTags as $k => $ctag) {
  606. if ($ctag->GetName() == 'array') {
  607. //传递整个数组,在runphp模式中有特殊作用
  608. $this->dtp2->Assign($k, $row);
  609. } else {
  610. if (isset($row[$ctag->GetName()])) {
  611. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  612. } else {
  613. $this->dtp2->Assign($k, '');
  614. }
  615. }
  616. }
  617. }
  618. $artlist .= $this->dtp2->GetResult();
  619. } //if hasRow
  620. else {
  621. $artlist .= "";
  622. }
  623. if ($col > 1) $artlist .= "</td>\r\n";
  624. } //Loop Col
  625. if ($col > 1) {
  626. $artlist .= "</tr>\r\n";
  627. }
  628. } //Loop Line
  629. if ($col > 1) {
  630. $artlist .= "</table>\r\n";
  631. }
  632. $this->dsql->FreeResult("al");
  633. return $artlist;
  634. }
  635. /**
  636. * 获取动态的分页列表
  637. *
  638. * @access public
  639. * @param string $list_len 列表宽度
  640. * @return string
  641. */
  642. function GetPageListDM($list_len, $listitem = "index,end,pre,next,pageno")
  643. {
  644. global $oldkeyword;
  645. $prepage = "";
  646. $nextpage = "";
  647. $prepagenum = $this->PageNo - 1;
  648. $nextpagenum = $this->PageNo + 1;
  649. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  650. $list_len = 3;
  651. }
  652. $totalpage = ceil($this->TotalResult / $this->pagesize);
  653. if ($totalpage <= 1 && $this->TotalResult > 0) {
  654. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>";
  655. }
  656. if ($this->TotalResult == 0) {
  657. return "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>";
  658. }
  659. $purl = $this->GetCurUrl();
  660. $oldkeyword = (empty($oldkeyword) ? $this->Keyword : $oldkeyword);
  661. //当结果超过限制时,重设结果页数
  662. if ($this->TotalResult > $this->SearchMaxRc) {
  663. $totalpage = ceil($this->SearchMaxRc / $this->pagesize);
  664. }
  665. $infos = "<li class='page-item d-none d-sm-block disabled'><span class='page-link'>{$totalpage}页".$this->TotalResult."条</span></li>\r\n";
  666. $geturl = "keyword=".urlencode($oldkeyword)."&searchtype=".$this->SearchType;
  667. $hidenform = "<input type='hidden' name='keyword' value='".rawurldecode($oldkeyword)."'>\r\n";
  668. $geturl .= "&channeltype=".$this->ChannelType."&orderby=".$this->OrderBy;
  669. $hidenform .= "<input type='hidden' name='channeltype' value='".$this->ChannelType."'>\r\n";
  670. $hidenform .= "<input type='hidden' name='orderby' value='".$this->OrderBy."'>\r\n";
  671. $geturl .= "&kwtype=".$this->KType."&pagesize=".$this->pagesize;
  672. $hidenform .= "<input type='hidden' name='kwtype' value='".$this->KType."'>\r\n";
  673. $hidenform .= "<input type='hidden' name='pagesize' value='".$this->pagesize."'>\r\n";
  674. $geturl .= "&typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  675. $hidenform .= "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
  676. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  677. $purl .= "?".$geturl;
  678. //获得上一页和下一页的链接
  679. if ($this->PageNo != 1) {
  680. $prepage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  681. $indexpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a></li>\r\n";
  682. } else {
  683. $indexpage = "<li class='page-item disabled'><a class='page-link'>首页</a></li>\r\n";
  684. }
  685. if ($this->PageNo != $totalpage && $totalpage > 1) {
  686. $nextpage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  687. $endpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  688. } else {
  689. $endpage = "<li class='page-item'><a class='page-link'>末页</a></li>\r\n";
  690. }
  691. //获得数字链接
  692. $listdd = "";
  693. $total_list = $list_len * 2 + 1;
  694. if ($this->PageNo >= $total_list) {
  695. $j = $this->PageNo - $list_len;
  696. $total_list = $this->PageNo + $list_len;
  697. if ($total_list > $totalpage) {
  698. $total_list = $totalpage;
  699. }
  700. } else {
  701. $j = 1;
  702. if ($total_list > $totalpage) {
  703. $total_list = $totalpage;
  704. }
  705. }
  706. for ($j; $j <= $total_list; $j++) {
  707. if ($j == $this->PageNo) {
  708. $listdd .= "<li class='page-item active'><a class='page-link'>$j</a></li>\r\n";
  709. } else {
  710. $listdd .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  711. }
  712. }
  713. $plist = "";
  714. $plist .= "<form name='pagelist' action='".$this->GetCurUrl()."'>$hidenform";
  715. $plist .= "<ul class='pagination justify-content-center pt-3'>";
  716. $plist .= preg_match('/info/i', $listitem)? $infos : "";
  717. $plist .= preg_match('/index/i', $listitem)? $indexpage : "";
  718. $plist .= preg_match('/pre/i', $listitem)? $prepage : "";
  719. $plist .= preg_match('/pageno/i', $listitem)? $listdd : "";
  720. $plist .= preg_match('/next/i', $listitem)? $nextpage : "";
  721. $plist .= preg_match('/end/i', $listitem)? $endpage : "";
  722. $plist .= "</ul></form>\r\n";
  723. return $plist;
  724. }
  725. /**
  726. * 获得当前的页面文件的url
  727. *
  728. * @access public
  729. * @return string
  730. */
  731. function GetCurUrl()
  732. {
  733. if (!empty($_SERVER["REQUEST_URI"])) {
  734. $nowurl = $_SERVER["REQUEST_URI"];
  735. $nowurls = explode("?", $nowurl);
  736. $nowurl = $nowurls[0];
  737. } else {
  738. $nowurl = $_SERVER["PHP_SELF"];
  739. }
  740. return $nowurl;
  741. }
  742. }//End Class