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

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