DedeV6移动版
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.

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