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

1041 lines
43KB

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