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

1032 lines
43KB

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