国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1025 Zeilen
41KB

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