国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1205 lines
52KB

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