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

1174 lines
51KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 文档列表类
  5. *
  6. * @version $id:listview.class.php 2 15:15 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.'/archive/partview.class.php');
  13. helper('cache');
  14. @set_time_limit(0);
  15. class ListView
  16. {
  17. var $dsql;
  18. var $dtp;
  19. var $dtp2;
  20. var $TypeID;
  21. var $TypeLink;
  22. var $PageNo;
  23. var $TotalPage;
  24. var $TotalResult;
  25. var $pagesize;
  26. var $ChannelUnit;
  27. var $ListType;
  28. var $Fields;
  29. var $PartView;
  30. var $upPageType;
  31. var $addSql;
  32. var $IsError;
  33. var $CrossID;
  34. var $IsReplace;
  35. var $remoteDir;
  36. var $mod;
  37. /**
  38. * php5构造函数
  39. *
  40. * @access public
  41. * @param int $typeid 栏目id
  42. * @param int $uppage 上一页
  43. * @param int $mod 渲染类型 0:HTML 1:JSON
  44. * @return string
  45. */
  46. function __construct($typeid, $uppage = 1, $mod = 0)
  47. {
  48. global $dsql, $envs;
  49. $envs['url_type'] = 1;
  50. $this->TypeID = $typeid;
  51. $this->dsql = &$dsql;
  52. $this->CrossID = '';
  53. $this->IsReplace = false;
  54. $this->IsError = false;
  55. $this->dtp = new DedeTagParse();
  56. $this->dtp->SetRefObj($this);
  57. $this->dtp->SetNameSpace("dede", "{", "}");
  58. $this->dtp2 = new DedeTagParse();
  59. $this->dtp2->SetNameSpace("field", "[", "]");
  60. $this->TypeLink = new TypeLink($typeid);
  61. $this->upPageType = $uppage;
  62. $this->remoteDir = '';
  63. $this->mod = $mod;
  64. $this->TotalResult = is_numeric($this->TotalResult) ? $this->TotalResult : "";
  65. if (!is_array($this->TypeLink->TypeInfos)) {
  66. $this->IsError = true;
  67. }
  68. if (!$this->IsError) {
  69. $this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);
  70. $this->Fields = $this->TypeLink->TypeInfos;
  71. $this->Fields['id'] = $typeid;
  72. $this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
  73. $this->Fields['title'] = preg_replace("/[<>]/", " / ", $this->TypeLink->GetPositionLink(false));
  74. //添加联动单筛选
  75. if (isset($_REQUEST['tid'])) {
  76. foreach($_GET as $key => $value) {
  77. if ($key!="tid" && $key!="TotalResult" && $key!="PageNo" && $key!="PageSize" && $key!="mod") {
  78. $this->Fields[string_filter($key)] = string_filter(urldecode($value));
  79. }
  80. }
  81. }
  82. //设置一些全局参数的值
  83. foreach ($GLOBALS['PubFields'] as $k => $v) $this->Fields[$k] = $v;
  84. $this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/static/rss/".$this->TypeID.".xml";
  85. //设置环境变量
  86. SetSysEnv($this->TypeID, $this->Fields['typename'], 0, '', 'list');
  87. $this->Fields['typeid'] = $this->TypeID;
  88. //获得交叉栏目id
  89. if ($this->TypeLink->TypeInfos['cross'] > 0 && $this->TypeLink->TypeInfos['ispart'] == 0) {
  90. $selquery = '';
  91. if ($this->TypeLink->TypeInfos['cross'] == 1) {
  92. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$this->Fields['typename']}' AND id<>'{$this->TypeID}' AND topid<>'{$this->TypeID}' ";
  93. } else {
  94. $this->Fields['crossid'] = preg_replace('/[^0-9,]/', '', trim($this->Fields['crossid']));
  95. if ($this->Fields['crossid'] != '') {
  96. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id in({$this->Fields['crossid']}) AND id<>{$this->TypeID} AND topid<>{$this->TypeID} ";
  97. }
  98. }
  99. if ($selquery != '') {
  100. $this->dsql->SetQuery($selquery);
  101. $this->dsql->Execute();
  102. while ($arr = $this->dsql->GetArray()) {
  103. $this->CrossID .= ($this->CrossID == '' ? $arr['id'] : ','.$arr['id']);
  104. }
  105. }
  106. }
  107. }//!error
  108. }
  109. //php4构造函数
  110. function ListView($typeid, $uppage = 0, $mod = 0)
  111. {
  112. $this->__construct($typeid, $uppage, $mod);
  113. }
  114. //关闭相关资源
  115. function Close()
  116. {
  117. }
  118. /**
  119. * 统计列表里的记录
  120. *
  121. * @access public
  122. * @param string
  123. * @return string
  124. */
  125. function CountRecord()
  126. {
  127. global $cfg_list_son, $cfg_need_typeid2, $cfg_cross_sectypeid;
  128. if (empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N';
  129. $filtersql = '';
  130. //获得附加表的相关信息,联动单筛选
  131. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  132. if ($addtable!="") {
  133. $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
  134. $addField = '';
  135. $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
  136. foreach($fields as $k=>$v)
  137. {
  138. $nfields[$v] = $k;
  139. }
  140. if (is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields)) {
  141. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  142. {
  143. if (isset($nfields[$k])) {
  144. if (!empty($arr['rename'])) {
  145. $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
  146. } else {
  147. $addField .= ','.$addtable.'.'.$k;
  148. }
  149. }
  150. }
  151. }
  152. if (isset($_REQUEST['tid'])) {
  153. foreach ($_GET as $key => $value) {
  154. $filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo" && $key!="PageSize" && $key!="mod") ? " AND $addtable.".string_filter($key)." = '".string_filter(urldecode($value))."'" : '';
  155. }
  156. }
  157. } else {
  158. $addField = '';
  159. $addJoin = '';
  160. }
  161. //统计数据库记录
  162. $this->TotalResult = -1;
  163. if (isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
  164. if (isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
  165. else $this->PageNo = 1;
  166. $this->addSql = " arc.arcrank > -1 ";
  167. $typeid2like = " '%,{$this->TypeID},%' ";
  168. if ($cfg_list_son == 'N') {
  169. if ($cfg_need_typeid2 == 'N') {
  170. if ($this->CrossID == '') $this->addSql .= " AND (arc.typeid='".$this->TypeID."') ";
  171. else $this->addSql .= " AND (arc.typeid in({$this->CrossID},{$this->TypeID})) ";
  172. } else {
  173. if ($this->CrossID == '') {
  174. $this->addSql .= " AND ( (arc.typeid='".$this->TypeID."') OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
  175. } else {
  176. if ($cfg_cross_sectypeid == 'Y') {
  177. $typeid2Clike = " '%,{$this->CrossID},%' ";
  178. $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike)";
  179. } else {
  180. $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like)";
  181. }
  182. }
  183. }
  184. } else {
  185. $sonids = GetSonIds($this->TypeID, $this->Fields['channeltype']);
  186. if (!preg_match("/,/", $sonids)) {
  187. $sonidsCon = " arc.typeid = '$sonids' ";
  188. } else {
  189. $sonidsCon = " arc.typeid IN($sonids) ";
  190. }
  191. if ($cfg_need_typeid2 == 'N') {
  192. if ($this->CrossID == '') $this->addSql .= " AND ( $sonidsCon ) ";
  193. else $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) ) ";
  194. } else {
  195. if ($this->CrossID == '') {
  196. $this->addSql .= " AND ( $sonidsCon OR CONCAT(',', arc.typeid2, ',') like $typeid2like ) ";
  197. } else {
  198. if ($cfg_cross_sectypeid == 'Y') {
  199. $typeid2Clike = " '%,{$this->CrossID},%' ";
  200. $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike) ";
  201. } else {
  202. $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
  203. }
  204. }
  205. }
  206. }
  207. if ($this->TotalResult==-1) {
  208. //添加联动单筛选
  209. $cquery = "SELECT COUNT(*) AS dd FROM `#@__arctiny` arc $addJoin WHERE ".$this->addSql.$filtersql;
  210. $row = $this->dsql->GetOne($cquery);
  211. if (is_array($row)) {
  212. $this->TotalResult = $row['dd'];
  213. } else {
  214. $this->TotalResult = 0;
  215. }
  216. }
  217. if ($this->mod === 0) {
  218. //初始化列表模板,并统计页面总数
  219. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
  220. $tempfile = str_replace("{tid}", $this->TypeID, $tempfile);
  221. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  222. if (!file_exists($tempfile)) {
  223. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
  224. }
  225. if (!file_exists($tempfile) || !is_file($tempfile)) {
  226. echo "主题模板文件不存在,无法发布文档";
  227. exit();
  228. }
  229. $this->dtp->LoadTemplate($tempfile);
  230. $ctag = $this->dtp->GetTag("page");
  231. if (!is_object($ctag)) {
  232. $ctag = $this->dtp->GetTag("list");
  233. }
  234. if (!is_object($ctag)) {
  235. $this->pagesize = 30;
  236. } else {
  237. if ($ctag->GetAtt("pagesize") != "") {
  238. $this->pagesize = $ctag->GetAtt("pagesize");
  239. } else {
  240. $this->pagesize = 30;
  241. }
  242. }
  243. } else {
  244. $this->pagesize = isset($GLOBALS['PageSize'])? intval($GLOBALS['PageSize']) : 10;
  245. $this->pagesize = $this->pagesize > 20? 20 : $this->pagesize;
  246. }
  247. $this->TotalPage = ceil($this->TotalResult / $this->pagesize);
  248. }
  249. /**
  250. * 列表创建网页
  251. *
  252. * @access public
  253. * @param string $startpage 开始页面
  254. * @param string $makepagesize 创建文件数目
  255. * @param string $isremote 是否为远程
  256. * @return string
  257. */
  258. function MakeHtml($startpage = 1, $makepagesize = 0, $isremote = 0)
  259. {
  260. if (empty($startpage)) {
  261. $startpage = 1;
  262. }
  263. //创建封面模板文件
  264. if ($this->TypeLink->TypeInfos['isdefault'] == -1) {
  265. echo '这个是动态栏目';
  266. return '../apps/list.php?tid='.$this->TypeLink->TypeInfos['id'];
  267. }
  268. //单独页面
  269. else if ($this->TypeLink->TypeInfos['ispart'] > 0) {
  270. $reurl = $this->MakePartTemplets();
  271. return $reurl;
  272. }
  273. if (empty($this->TotalResult)) $this->CountRecord();
  274. //初步给固定值的标记赋值
  275. $this->ParseTempletsFirst();
  276. $totalpage = ceil($this->TotalResult / $this->pagesize);
  277. if ($totalpage == 0) {
  278. $totalpage = 1;
  279. }
  280. CreateDir(MfTypedir($this->Fields['typedir']));
  281. $murl = '';
  282. if ($makepagesize > 0) {
  283. $endpage = $startpage + $makepagesize;
  284. } else {
  285. $endpage = ($totalpage + 1);
  286. }
  287. if ($endpage >= $totalpage + 1) {
  288. $endpage = $totalpage + 1;
  289. }
  290. if ($endpage == 1) {
  291. $endpage = 2;
  292. }
  293. for ($this->PageNo = $startpage; $this->PageNo < $endpage; $this->PageNo++) {
  294. $this->ParseDMFields($this->PageNo, 1);
  295. $makeFile = $this->GetMakeFileRule($this->Fields['id'], 'list', $this->Fields['typedir'], '', $this->Fields['namerule2']);
  296. $makeFile = str_replace("{page}", $this->PageNo, $makeFile);
  297. $murl = $makeFile;
  298. if (!preg_match("/^\//", $makeFile)) {
  299. $makeFile = "/".$makeFile;
  300. }
  301. $makeFile = $this->GetTruePath().$makeFile;
  302. $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
  303. $murl = $this->GetTrueUrl($murl);
  304. $this->dtp->SaveTo($makeFile);
  305. if (PHP_SAPI === 'cli') {
  306. DedeCli::showProgress(ceil(($this->PageNo / ($endpage-1)) * 100), 100);
  307. }
  308. }
  309. if ($startpage == 1) {
  310. //如果列表启用封面文件,复制这个文件第一页
  311. if ($this->TypeLink->TypeInfos['isdefault'] == 1 && $this->TypeLink->TypeInfos['ispart'] == 0) {
  312. $onlyrule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], '', $this->Fields['namerule2']);
  313. $onlyrule = str_replace("{page}", "1", $onlyrule);
  314. $list_1 = $this->GetTruePath().$onlyrule;
  315. $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
  316. $indexname = $this->GetTruePath().$murl;
  317. copy($list_1, $indexname);
  318. }
  319. }
  320. return $murl;
  321. }
  322. /**
  323. * 显示列表
  324. *
  325. * @access public
  326. * @return void
  327. */
  328. function Display()
  329. {
  330. if ($this->mod === 0) {
  331. if ($this->TypeLink->TypeInfos['ispart'] > 0) {
  332. $this->DisplayPartTemplets();
  333. return;
  334. }
  335. $this->CountRecord();
  336. if ((empty($this->PageNo) || $this->PageNo == 1) && $this->TypeLink->TypeInfos['ispart'] == 1) {
  337. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  338. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  339. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  340. $tempfile = $tmpdir."/".$tempfile;
  341. if (!file_exists($tempfile)) {
  342. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  343. }
  344. $this->dtp->LoadTemplate($tempfile);
  345. }
  346. $this->ParseTempletsFirst();
  347. $this->ParseDMFields($this->PageNo, 0);
  348. $this->dtp->Display();
  349. } else {
  350. $this->CountRecord();
  351. $result = $this->GetAPIList($this->PageNo,$this->pagesize);
  352. if (!is_array($result)) {
  353. echo json_encode(array(
  354. "code" => -1,
  355. "msg" => "none result",
  356. ));
  357. } else {
  358. echo json_encode(array(
  359. "code" => 0,
  360. "msg" => "",
  361. "lists" => $result,
  362. "total" => intval($this->TotalResult),
  363. ));
  364. }
  365. }
  366. }
  367. /**
  368. * GetAPIList
  369. *
  370. * @param mixed $PageNo 页码
  371. * @param mixed $row 条数
  372. * @param mixed $titlelen 标题字符长度
  373. * @param mixed $infolen 描述字符长度
  374. * @param mixed $orderby 排序
  375. * @param mixed $orderWay 排序方式
  376. * @return array
  377. */
  378. function GetAPIList($PageNo = 1,$row = 10,$titlelen = 30,$infolen = 250,$orderby = "default",$orderWay = 'desc') {
  379. $limitstart = ($PageNo - 1) * $row;
  380. if ($row == '') $row = 10;
  381. if ($limitstart == '') $limitstart = 0;
  382. if ($titlelen == '') $titlelen = 100;
  383. if ($infolen == '') $infolen = 250;
  384. if ($orderWay == '') $orderWay = 'desc';
  385. if ($orderby == '') {
  386. $orderby = 'default';
  387. } else {
  388. $orderby = strtolower($orderby);
  389. }
  390. //排序方式
  391. $ordersql = '';
  392. if ($orderby == "senddate" || $orderby == "id") {
  393. $ordersql = " ORDER BY arc.id $orderWay";
  394. } else if ($orderby == "hot" || $orderby == "click") {
  395. $ordersql = " ORDER BY arc.click $orderWay";
  396. } else if ($orderby == "lastpost") {
  397. $ordersql = " ORDER BY arc.lastpost $orderWay";
  398. } else {
  399. $ordersql = " ORDER BY arc.sortrank $orderWay";
  400. }
  401. //获得附加表的相关信息
  402. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  403. $filtersql = "";
  404. if ($addtable!="")
  405. {
  406. $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
  407. $addField = '';
  408. $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
  409. foreach($fields as $k=>$v)
  410. {
  411. $nfields[$v] = $k;
  412. }
  413. if (is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields)) {
  414. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  415. {
  416. if (isset($nfields[$k])) {
  417. if (!empty($arr['rename'])) {
  418. $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
  419. }
  420. else {
  421. $addField .= ','.$addtable.'.'.$k;
  422. }
  423. }
  424. }
  425. }
  426. //添加联动单筛选
  427. if (isset($_REQUEST['tid'])) {
  428. foreach($_GET as $key => $value)
  429. {
  430. $filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo" && $key!="PageSize" && $key !="mod") ? " AND $addtable.".string_filter($key)." = '".string_filter(urldecode($value))."'" : '';
  431. }
  432. }
  433. } else {
  434. $addField = '';
  435. $addJoin = '';
  436. }
  437. //如果不用默认的sortrank或id排序,使用联合查询数据量大时非常缓慢
  438. if (preg_match('/hot|click|lastpost/', $orderby)) {
  439. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,mb.uname,mb.face $addField FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id LEFT JOIN `#@__member` mb ON arc.mid=mb.mid $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";
  440. }
  441. //普通情况先从arctiny表查出id,然后按di查询速度非常快
  442. else {
  443. $t1 = ExecTime();
  444. $ids = array();
  445. $query = "SELECT id FROM `#@__arctiny` arc $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";
  446. $this->dsql->SetQuery($query);
  447. $this->dsql->Execute();
  448. while ($arr = $this->dsql->GetArray()) {
  449. $ids[] = $arr['id'];
  450. }
  451. $idstr = join(',', $ids);
  452. if ($idstr == '') {
  453. return '';
  454. } else {
  455. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,mb.uname,mb.face $addField FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id LEFT JOIN `#@__member` mb ON arc.mid=mb.mid $addJoin WHERE arc.id in($idstr) $ordersql ";
  456. }
  457. $t2 = ExecTime();
  458. }
  459. $this->dsql->SetQuery($query);
  460. $this->dsql->Execute('al');
  461. $t2 = ExecTime();
  462. $result = array();
  463. $GLOBALS['autoindex'] = 0;
  464. while ($row = $this->dsql->GetArray("al")) {
  465. $GLOBALS['autoindex']++;
  466. $ids[$row['id']] = $row['id'];
  467. //处理一些特殊字段
  468. $row['infos'] = cn_substr($row['description'], $infolen);
  469. $row['id'] = $row['id'];
  470. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  471. $row['arcrank'] = $row['corank'];
  472. }
  473. $row['filename'] = $row['arcurl'] = GetFileUrl(
  474. $row['id'],
  475. $row['typeid'],
  476. $row['senddate'],
  477. $row['title'],
  478. $row['ismake'],
  479. $row['arcrank'],
  480. $row['namerule'],
  481. $row['typedir'],
  482. $row['money'],
  483. $row['filename'],
  484. $row['moresite'],
  485. $row['siteurl'],
  486. $row['sitepath']
  487. );
  488. $row['typeurl'] = GetTypeUrl(
  489. $row['typeid'],
  490. MfTypedir($row['typedir']),
  491. $row['isdefault'],
  492. $row['defaultname'],
  493. $row['ispart'],
  494. $row['namerule2'],
  495. $row['moresite'],
  496. $row['siteurl'],
  497. $row['sitepath']
  498. );
  499. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  500. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  501. }
  502. /*if (!preg_match("/^http:\/\//i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  503. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  504. }*/
  505. $row['picname'] = $row['litpic'];
  506. $row['stime'] = GetDateMK($row['pubdate']);
  507. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  508. $row['image'] = "<img src='".$row['picname']."' title='".preg_replace("/['><]/", "", $row['title'])."'>";
  509. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  510. $row['fulltitle'] = $row['title'];
  511. $row['title'] = cn_substr($row['title'], $titlelen);
  512. if ($row['color'] != '') {
  513. $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  514. }
  515. if (preg_match('/c/', $row['flag'])) {
  516. $row['title'] = "".$row['title']."";
  517. }
  518. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  519. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  520. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  521. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  522. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  523. //编译附加表里的数据
  524. foreach ($row as $k => $v) {
  525. $row[strtolower($k)] = $v;
  526. }
  527. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  528. if (isset($row[$k])) {
  529. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  530. }
  531. }
  532. $result[] = $row;
  533. }//if hasRow
  534. $t3 = ExecTime();
  535. $this->dsql->FreeResult('al');
  536. return $result;
  537. }
  538. /**
  539. * 创建单独模板页面
  540. *
  541. * @access public
  542. * @return string
  543. */
  544. function MakePartTemplets()
  545. {
  546. $this->PartView = new PartView($this->TypeID, false);
  547. $this->PartView->SetTypeLink($this->TypeLink);
  548. $nmfa = 0;
  549. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  550. if ($this->Fields['ispart'] == 1) {
  551. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  552. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  553. $tempfile = $tmpdir."/".$tempfile;
  554. if (!file_exists($tempfile)) {
  555. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  556. }
  557. $this->PartView->SetTemplet($tempfile);
  558. } else if ($this->Fields['ispart'] == 2) {
  559. //跳转网址
  560. return $this->Fields['typedir'];
  561. }
  562. CreateDir(MfTypedir($this->Fields['typedir']));
  563. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  564. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  565. $makeFile = $this->GetTruePath().$makeUrl;
  566. if ($nmfa == 0) {
  567. $this->PartView->SaveToHtml($makeFile);
  568. } else {
  569. if (!file_exists($makeFile)) {
  570. $this->PartView->SaveToHtml($makeFile);
  571. }
  572. }
  573. return $this->GetTrueUrl($makeUrl);
  574. }
  575. /**
  576. * 显示单独模板页面
  577. *
  578. * @access public
  579. * @param string
  580. * @return string
  581. */
  582. function DisplayPartTemplets()
  583. {
  584. $this->PartView = new PartView($this->TypeID, false);
  585. $this->PartView->SetTypeLink($this->TypeLink);
  586. $nmfa = 0;
  587. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  588. if ($this->Fields['ispart'] == 1) {
  589. //封面模板
  590. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  591. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  592. $tempfile = $tmpdir."/".$tempfile;
  593. if (!file_exists($tempfile)) {
  594. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";
  595. }
  596. $this->PartView->SetTemplet($tempfile);
  597. } else if ($this->Fields['ispart'] == 2) {
  598. //跳转网址
  599. $gotourl = $this->Fields['typedir'];
  600. header("Location:$gotourl");
  601. exit();
  602. }
  603. CreateDir(MfTypedir($this->Fields['typedir']));
  604. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  605. $makeFile = $this->GetTruePath().$makeUrl;
  606. if ($nmfa == 0) {
  607. $this->PartView->Display();
  608. } else {
  609. if (!file_exists($makeFile)) {
  610. $this->PartView->Display();
  611. } else {
  612. include($makeFile);
  613. }
  614. }
  615. }
  616. /**
  617. * 获得站点的真实根路径
  618. *
  619. * @access public
  620. * @return string
  621. */
  622. function GetTruePath()
  623. {
  624. $truepath = $GLOBALS["cfg_basedir"];
  625. return $truepath;
  626. }
  627. /**
  628. * 获得真实连接路径
  629. *
  630. * @access public
  631. * @param string $nurl 地址
  632. * @return string
  633. */
  634. function GetTrueUrl($nurl)
  635. {
  636. if ($this->Fields['moresite'] == 1) {
  637. if ($this->Fields['sitepath'] != '') {
  638. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  639. }
  640. $nurl = $this->Fields['siteurl'].$nurl;
  641. }
  642. return $nurl;
  643. }
  644. /**
  645. * 解析模板,对固定的标记进行初始给值
  646. *
  647. * @access public
  648. * @return string
  649. */
  650. function ParseTempletsFirst()
  651. {
  652. if (isset($this->TypeLink->TypeInfos['reid'])) {
  653. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  654. }
  655. $GLOBALS['envs']['typeid'] = $this->TypeID;
  656. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  657. $GLOBALS['envs']['cross'] = 1;
  658. MakeOneTag($this->dtp, $this);
  659. }
  660. /**
  661. * 解析模板,对文档里的变动进行赋值
  662. *
  663. * @access public
  664. * @param int $PageNo 页数
  665. * @param int $ismake 是否编译
  666. * @return string
  667. */
  668. function ParseDMFields($PageNo, $ismake = 1)
  669. {
  670. //替换第二页后的文档
  671. if (($PageNo > 1 || strlen($this->Fields['content']) < 10) && !$this->IsReplace) {
  672. $this->dtp->SourceString = str_replace('[cmsreplace]', 'display:none', $this->dtp->SourceString);
  673. $this->IsReplace = true;
  674. }
  675. foreach ($this->dtp->CTags as $tagid => $ctag) {
  676. if ($ctag->GetName() == "list") {
  677. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  678. $row = $this->pagesize;
  679. if (trim($ctag->GetInnerText()) == "") {
  680. $InnerText = GetSysTemplets("list_fulllist.htm");
  681. } else {
  682. $InnerText = trim($ctag->GetInnerText());
  683. }
  684. $this->dtp->Assign(
  685. $tagid,
  686. $this->GetArcList(
  687. $limitstart,
  688. $row,
  689. $ctag->GetAtt("col"),
  690. $ctag->GetAtt("titlelen"),
  691. $ctag->GetAtt("infolen"),
  692. $ctag->GetAtt("imgwidth"),
  693. $ctag->GetAtt("imgheight"),
  694. $ctag->GetAtt("listtype"),
  695. $ctag->GetAtt("orderby"),
  696. $InnerText,
  697. $ctag->GetAtt("tablewidth"),
  698. $ismake,
  699. $ctag->GetAtt("orderway")
  700. )
  701. );
  702. } else if ($ctag->GetName() == "pagelist") {
  703. $list_len = trim($ctag->GetAtt("listsize"));
  704. $ctag->GetAtt("listitem") == "" ? $listitem = "index,pre,pageno,next,end,option" : $listitem = $ctag->GetAtt("listitem");
  705. if ($list_len == "") {
  706. $list_len = 3;
  707. }
  708. if ($ismake == 0) {
  709. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len, $listitem));
  710. } else {
  711. $this->dtp->Assign($tagid, $this->GetPageListST($list_len, $listitem));
  712. }
  713. } else if ($PageNo != 1 && $ctag->GetName() == 'field' && $ctag->GetAtt('display') != '') {
  714. $this->dtp->Assign($tagid, '');
  715. }
  716. }
  717. }
  718. /**
  719. * 获得要创建的文件名称规则
  720. *
  721. * @access public
  722. * @param int $typeid 栏目id
  723. * @param string $wname
  724. * @param string $typedir 栏目目录
  725. * @param string $defaultname 默认名称
  726. * @param string $namerule2 栏目规则
  727. * @return string
  728. */
  729. function GetMakeFileRule($typeid, $wname, $typedir, $defaultname, $namerule2)
  730. {
  731. $typedir = MfTypedir($typedir);
  732. if ($wname == 'index') {
  733. return $typedir.'/'.$defaultname;
  734. } else {
  735. $namerule2 = str_replace('{tid}', $typeid, $namerule2);
  736. $namerule2 = str_replace('{typedir}', $typedir, $namerule2);
  737. return $namerule2;
  738. }
  739. }
  740. /**
  741. * 获得一个单列的文档列表
  742. *
  743. * @access public
  744. * @param int $limitstart 限制开始
  745. * @param int $row 行数
  746. * @param int $col 列数
  747. * @param int $titlelen 标题长度
  748. * @param int $infolen 描述长度
  749. * @param int $imgwidth 图片宽度
  750. * @param int $imgheight 图片高度
  751. * @param string $listtype 列表类型
  752. * @param string $orderby 排列顺序
  753. * @param string $innertext 底层模板
  754. * @param string $tablewidth 表格宽度
  755. * @param string $ismake 是否编译
  756. * @param string $orderWay 排序方式
  757. * @return string
  758. */
  759. function GetArcList(
  760. $limitstart = 0,
  761. $row = 10,
  762. $col = 1,
  763. $titlelen = 30,
  764. $infolen = 250,
  765. $imgwidth = 120,
  766. $imgheight = 90,
  767. $listtype = "all",
  768. $orderby = "default",
  769. $innertext = "",
  770. $tablewidth = "100",
  771. $ismake = 1,
  772. $orderWay = 'desc'
  773. ) {
  774. global $cfg_list_son, $cfg_digg_update;
  775. $typeid = $this->TypeID;
  776. if ($row == '') $row = 10;
  777. if ($limitstart == '') $limitstart = 0;
  778. if ($titlelen == '') $titlelen = 100;
  779. if ($infolen == '') $infolen = 250;
  780. if ($imgwidth == '') $imgwidth = 120;
  781. if ($imgheight == '') $imgheight = 120;
  782. if ($listtype == '') $listtype = 'all';
  783. if ($orderWay == '') $orderWay = 'desc';
  784. if ($orderby == '') {
  785. $orderby = 'default';
  786. } else {
  787. $orderby = strtolower($orderby);
  788. }
  789. $tablewidth = str_replace('%', '', $tablewidth);
  790. if ($tablewidth == '') $tablewidth = 100;
  791. if ($col == '') $col = 1;
  792. $colWidth = ceil(100 / $col);
  793. $tablewidth = $tablewidth.'%';
  794. $colWidth = $colWidth.'%';
  795. $innertext = trim($innertext);
  796. if ($innertext == '') {
  797. $innertext = GetSysTemplets('list_fulllist.htm');
  798. }
  799. //排序方式
  800. $ordersql = '';
  801. if ($orderby == "senddate" || $orderby == "id") {
  802. $ordersql = " ORDER BY arc.id $orderWay";
  803. } else if ($orderby == "hot" || $orderby == "click") {
  804. $ordersql = " ORDER BY arc.click $orderWay";
  805. } else if ($orderby == "lastpost") {
  806. $ordersql = " ORDER BY arc.lastpost $orderWay";
  807. } else {
  808. $ordersql = " ORDER BY arc.sortrank $orderWay";
  809. }
  810. //获得附加表的相关信息
  811. $addtable = $this->ChannelUnit->ChannelInfos['addtable'];
  812. $filtersql = "";
  813. if ($addtable!="")
  814. {
  815. $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
  816. $addField = '';
  817. $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
  818. foreach($fields as $k=>$v)
  819. {
  820. $nfields[$v] = $k;
  821. }
  822. if (is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields)) {
  823. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  824. {
  825. if (isset($nfields[$k])) {
  826. if (!empty($arr['rename'])) {
  827. $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
  828. }
  829. else {
  830. $addField .= ','.$addtable.'.'.$k;
  831. }
  832. }
  833. }
  834. }
  835. //添加联动单筛选
  836. if (isset($_REQUEST['tid'])) {
  837. foreach($_GET as $key => $value)
  838. {
  839. $filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo" && $key!="PageSize" && $key!="mod") ? " AND $addtable.".string_filter($key)." = '".string_filter(urldecode($value))."'" : '';
  840. }
  841. }
  842. } else {
  843. $addField = '';
  844. $addJoin = '';
  845. }
  846. //如果不用默认的sortrank或id排序,使用联合查询数据量大时非常缓慢
  847. if (preg_match('/hot|click|lastpost/', $orderby)) {
  848. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,mb.uname,mb.face $addField FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id LEFT JOIN `#@__member` mb ON arc.mid=mb.mid $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";
  849. }
  850. //普通情况先从arctiny表查出id,然后按di查询速度非常快
  851. else {
  852. $t1 = ExecTime();
  853. $ids = array();
  854. $query = "SELECT id FROM `#@__arctiny` arc $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";
  855. $this->dsql->SetQuery($query);
  856. $this->dsql->Execute();
  857. while ($arr = $this->dsql->GetArray()) {
  858. $ids[] = $arr['id'];
  859. }
  860. $idstr = join(',', $ids);
  861. if ($idstr == '') {
  862. return '';
  863. } else {
  864. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,mb.uname,mb.face $addField FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id LEFT JOIN `#@__member` mb ON arc.mid=mb.mid $addJoin WHERE arc.id in($idstr) $ordersql ";
  865. }
  866. $t2 = ExecTime();
  867. }
  868. $this->dsql->SetQuery($query);
  869. $this->dsql->Execute('al');
  870. $t2 = ExecTime();
  871. $artlist = '';
  872. $this->dtp2->LoadSource($innertext);
  873. $GLOBALS['autoindex'] = 0;
  874. for ($i = 0; $i < $row; $i++) {
  875. if ($col > 1) {
  876. $artlist .= "<div>";
  877. }
  878. for ($j = 0; $j < $col; $j++) {
  879. if ($row = $this->dsql->GetArray("al")) {
  880. $GLOBALS['autoindex']++;
  881. $ids[$row['id']] = $row['id'];
  882. //处理一些特殊字段
  883. $row['infos'] = cn_substr($row['description'], $infolen);
  884. $row['id'] = $row['id'];
  885. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  886. $row['arcrank'] = $row['corank'];
  887. }
  888. $row['filename'] = $row['arcurl'] = GetFileUrl(
  889. $row['id'],
  890. $row['typeid'],
  891. $row['senddate'],
  892. $row['title'],
  893. $row['ismake'],
  894. $row['arcrank'],
  895. $row['namerule'],
  896. $row['typedir'],
  897. $row['money'],
  898. $row['filename'],
  899. $row['moresite'],
  900. $row['siteurl'],
  901. $row['sitepath']
  902. );
  903. $row['typeurl'] = GetTypeUrl(
  904. $row['typeid'],
  905. MfTypedir($row['typedir']),
  906. $row['isdefault'],
  907. $row['defaultname'],
  908. $row['ispart'],
  909. $row['namerule2'],
  910. $row['moresite'],
  911. $row['siteurl'],
  912. $row['sitepath']
  913. );
  914. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  915. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  916. }
  917. /*if (!preg_match("/^http:\/\//i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  918. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  919. }*/
  920. $row['picname'] = $row['litpic'];
  921. $row['stime'] = GetDateMK($row['pubdate']);
  922. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  923. $row['image'] = "<img src='".$row['picname']."' width='$imgwidth' height='$imgheight' title='".preg_replace("/['><]/", "", $row['title'])."'>";
  924. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  925. $row['fulltitle'] = $row['title'];
  926. $row['title'] = cn_substr($row['title'], $titlelen);
  927. if ($row['color'] != '') {
  928. $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  929. }
  930. if (preg_match('/c/', $row['flag'])) {
  931. $row['title'] = "".$row['title']."";
  932. }
  933. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  934. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  935. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  936. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  937. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  938. //编译附加表里的数据
  939. foreach ($row as $k => $v) {
  940. $row[strtolower($k)] = $v;
  941. }
  942. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  943. if (isset($row[$k])) {
  944. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  945. }
  946. }
  947. if (is_array($this->dtp2->CTags)) {
  948. foreach ($this->dtp2->CTags as $k => $ctag) {
  949. if ($ctag->GetName() == 'array') {
  950. //传递整个数组,在runphp模式中有特殊作用
  951. $this->dtp2->Assign($k, $row);
  952. } else {
  953. if (isset($row[$ctag->GetName()])) {
  954. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  955. } else {
  956. $this->dtp2->Assign($k, '');
  957. }
  958. }
  959. }
  960. }
  961. $artlist .= $this->dtp2->GetResult();
  962. }//if hasRow
  963. }//Loop Col
  964. if ($col > 1) {
  965. $i += $col - 1;
  966. $artlist .= "</div>";
  967. }
  968. }//Loop Line
  969. $t3 = ExecTime();
  970. $this->dsql->FreeResult('al');
  971. return $artlist;
  972. }
  973. /**
  974. * 获取静态的分页列表
  975. *
  976. * @access public
  977. * @param string $list_len 列表宽度
  978. * @param string $list_len 列表样式
  979. * @return string
  980. */
  981. function GetPageListST($list_len, $listitem = "index,end,pre,next,pageno")
  982. {
  983. global $cfg_cmspath;
  984. $prepage = $nextpage = '';
  985. $prepagenum = $this->PageNo - 1;
  986. $nextpagenum = $this->PageNo + 1;
  987. if ($list_len == '' || preg_match("/[^0-9]/", $list_len)) {
  988. $list_len = 3;
  989. }
  990. $totalpage = ceil($this->TotalResult / $this->pagesize);
  991. if ($totalpage <= 1 && $this->TotalResult > 0) {
  992. return "<li class='page-item disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>\r\n";
  993. }
  994. if ($this->TotalResult == 0) {
  995. return "<li class='page-item disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>\r\n";
  996. }
  997. $purl = $this->GetCurUrl();
  998. $maininfo = "<li class='page-item disabled'><span class='page-link'>{$totalpage}页".$this->TotalResult."条</span></li>\r\n";
  999. $tnamerule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], $this->Fields['defaultname'], $this->Fields['namerule2']);
  1000. $tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
  1001. //获得上一页和首页的链接
  1002. if ($this->PageNo != 1) {
  1003. $prepage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $prepagenum, $tnamerule)."'>上一页</a></li>\r\n";
  1004. $indexpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", 1, $tnamerule)."'>首页</a></li>\r\n";
  1005. } else {
  1006. $indexpage = "<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  1007. }
  1008. //下一页和未页的链接
  1009. if ($this->PageNo != $totalpage && $totalpage > 1) {
  1010. $nextpage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $nextpagenum, $tnamerule)."'>下一页</a></li>\r\n";
  1011. $endpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $totalpage, $tnamerule)."'>末页</a></li>\r\n";
  1012. } else {
  1013. $endpage = "<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  1014. }
  1015. //option链接
  1016. $optionlist = '';
  1017. $optionlen = strlen($totalpage);
  1018. $optionlen = $optionlen * 12 + 18;
  1019. if ($optionlen < 36) $optionlen = 36;
  1020. if ($optionlen > 100) $optionlen = 100;
  1021. $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  1022. for ($mjj = 1; $mjj <= $totalpage; $mjj++) {
  1023. if ($mjj == $this->PageNo) {
  1024. $optionlist .= "<option value='".str_replace("{page}", $mjj, $tnamerule)."' selected>$mjj</option>\r\n";
  1025. } else {
  1026. $optionlist .= "<option value='".str_replace("{page}", $mjj, $tnamerule)."'>$mjj</option>\r\n";
  1027. }
  1028. }
  1029. $optionlist .= "</select></li>\r\n";
  1030. //获得数字链接
  1031. $listdd = "";
  1032. $total_list = $list_len * 2 + 1;
  1033. if ($this->PageNo >= $total_list) {
  1034. $j = $this->PageNo - $list_len;
  1035. $total_list = $this->PageNo + $list_len;
  1036. if ($total_list > $totalpage) {
  1037. $total_list = $totalpage;
  1038. }
  1039. } else {
  1040. $j = 1;
  1041. if ($total_list > $totalpage) {
  1042. $total_list = $totalpage;
  1043. }
  1044. }
  1045. for ($j; $j <= $total_list; $j++) {
  1046. if ($j == $this->PageNo) {
  1047. $listdd .= "<li class='page-item active'><span class='page-link'>$j</span></li>\r\n";
  1048. } else {
  1049. $listdd .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $j, $tnamerule)."'>".$j."</a></li>\r\n";
  1050. }
  1051. }
  1052. $plist = '';
  1053. if (preg_match('/index/i', $listitem)) $plist .= $indexpage;
  1054. if (preg_match('/pre/i', $listitem)) $plist .= $prepage;
  1055. if (preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  1056. if (preg_match('/next/i', $listitem)) $plist .= $nextpage;
  1057. if (preg_match('/end/i', $listitem)) $plist .= $endpage;
  1058. if (preg_match('/option/i', $listitem)) $plist .= $optionlist;
  1059. if (preg_match('/info/i', $listitem)) $plist .= $maininfo;
  1060. return $plist;
  1061. }
  1062. /**
  1063. * 获取动态的分页列表
  1064. *
  1065. * @access public
  1066. * @param string $list_len 列表宽度
  1067. * @param string $list_len 列表样式
  1068. * @return string
  1069. */
  1070. function GetPageListDM($list_len, $listitem = "index,end,pre,next,pageno")
  1071. {
  1072. global $cfg_cmspath, $cfg_rewrite;
  1073. $prepage = $nextpage = '';
  1074. $prepagenum = $this->PageNo - 1;
  1075. $nextpagenum = $this->PageNo + 1;
  1076. if ($list_len == '' || preg_match("/[^0-9]/", $list_len)) {
  1077. $list_len = 3;
  1078. }
  1079. $totalpage = ceil($this->TotalResult / $this->pagesize);
  1080. if ($totalpage <= 1 && $this->TotalResult > 0) {
  1081. return "<li class='d-none d-sm-block page-item disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>\r\n";
  1082. }
  1083. if ($this->TotalResult == 0) {
  1084. return "<li class='d-none d-sm-block page-item disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>\r\n";
  1085. }
  1086. $maininfo = "<li class='d-none d-sm-block page-item disabled'><span class='page-link'>{$totalpage}页".$this->TotalResult."条</span></li>\r\n";
  1087. $purl = $this->GetCurUrl();
  1088. //如果开启为静态,则对规则进行替换
  1089. if ($cfg_rewrite == 'Y') {
  1090. $nowurls = preg_replace("/\-/", ".php?", $purl);
  1091. $nowurls = explode("?", $nowurls);
  1092. $purl = $nowurls[0];
  1093. }
  1094. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  1095. $purl .= '?'.$geturl;
  1096. $optionlist = '';
  1097. //添加联动单筛选
  1098. $pageaddurl = "";
  1099. foreach($_GET as $key => $value) {
  1100. $pageaddurl .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo" && $key!="PageSize" && $key!="mod") ? "&".string_filter($key)."=".string_filter($value) : '';
  1101. }
  1102. //获得上一页和下一页的链接
  1103. if ($this->PageNo != 1) {
  1104. $prepage .= "<li class='page-item'><a href='".$purl."PageNo=$prepagenum".$pageaddurl."' class='page-link'>上一页</a></li>\r\n";
  1105. $indexpage = "<li class='page-item'><a href='".$purl."PageNo=1".$pageaddurl."' class='page-link'>首页</a></li>\r\n";
  1106. } else {
  1107. $indexpage = "<li class='page-item'><span class='page-link'>首页</span></li>\r\n";
  1108. }
  1109. if ($this->PageNo != $totalpage && $totalpage > 1) {
  1110. $nextpage .= "<li class='page-item'><a href='".$purl."PageNo=$nextpagenum".$pageaddurl."' class='page-link'>下一页</a></li>\r\n";
  1111. $endpage = "<li class='page-item'><a href='".$purl."PageNo=$totalpage".$pageaddurl."' class='page-link'>末页</a></li>\r\n";
  1112. } else {
  1113. $endpage = "<li class='page-item'><span class='page-link'>末页</span></li>\r\n";
  1114. }
  1115. //获得数字链接
  1116. $listdd = "";
  1117. $total_list = $list_len * 2 + 1;
  1118. if ($this->PageNo >= $total_list) {
  1119. $j = $this->PageNo - $list_len;
  1120. $total_list = $this->PageNo + $list_len;
  1121. if ($total_list > $totalpage) {
  1122. $total_list = $totalpage;
  1123. }
  1124. } else {
  1125. $j = 1;
  1126. if ($total_list > $totalpage) {
  1127. $total_list = $totalpage;
  1128. }
  1129. }
  1130. for ($j; $j <= $total_list; $j++) {
  1131. if ($j == $this->PageNo) {
  1132. $listdd .= "<li class='page-item active'><span class='page-link'>$j</span></li>\r\n";
  1133. } else {
  1134. $listdd .= "<li class='page-item'><a href='".$purl."PageNo=$j".$pageaddurl."' class='page-link'>".$j."</a></li>\r\n";
  1135. }
  1136. }
  1137. $plist = "";
  1138. if (preg_match('/index/i', $listitem)) $plist .= $indexpage;
  1139. if (preg_match('/pre/i', $listitem)) $plist .= $prepage;
  1140. if (preg_match('/pageno/i', $listitem)) $plist .= $listdd;
  1141. if (preg_match('/next/i', $listitem)) $plist .= $nextpage;
  1142. if (preg_match('/end/i', $listitem)) $plist .= $endpage;
  1143. if (preg_match('/option/i', $listitem)) $plist .= $optionlist;
  1144. if (preg_match('/info/i', $listitem)) $plist .= $maininfo;
  1145. //伪静态分页
  1146. if ($cfg_rewrite == 'Y') {
  1147. $plist = str_replace('.php?tid=','-',$plist);
  1148. $plist = preg_replace("/&TotalResult=(\d+)/i","",$plist);//去掉总结果数值
  1149. //目录版默认
  1150. $plist = preg_replace("/&PageNo=(\d+)/i",'-\\1',$plist);
  1151. //网页版$plist = preg_replace("/&PageNo=(\d+)/i",'-\\1.html',$plist);
  1152. }
  1153. return $plist;
  1154. }
  1155. /**
  1156. * 获得当前的页面文件链接
  1157. *
  1158. * @access public
  1159. * @return string
  1160. */
  1161. function GetCurUrl()
  1162. {
  1163. if (!empty($_SERVER['REQUEST_URI'])) {
  1164. $nowurl = $_SERVER['REQUEST_URI'];
  1165. $nowurls = explode('?', $nowurl);
  1166. $nowurl = $nowurls[0];
  1167. } else {
  1168. $nowurl = $_SERVER['PHP_SELF'];
  1169. }
  1170. return $nowurl;
  1171. }
  1172. }//End Class
  1173. ?>