DedeV6移动版
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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