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

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