国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

754 рядки
30KB

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