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

740 lines
30KB

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