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

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