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

725 lines
29KB

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