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

734 строки
29KB

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