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

777 lines
30KB

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