国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

987 lignes
42KB

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