国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

sglistview.class.php 46KB

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