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

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