国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1028 rindas
42KB

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