国内流行的内容管理系统(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.

listview.class.php 51KB

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