国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

listview.class.php 51KB

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