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

990 lines
42KB

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