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

778 lines
30KB

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