DedeV6移动版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

searchview.class.php 29KB

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