DedeV6移动版
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.

1239 line
53KB

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