DedeV6移动版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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