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

1201 lines
52KB

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