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

718 lines
28KB

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