国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
22KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 专题视图类
  5. *
  6. * @version $Id: specview.class.php 1 18:17 2010年7月7日Z 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."/typelink/typelink.class.php");
  13. require_once(DEDEINC."/channelunit.class.php");
  14. @set_time_limit(0);
  15. /**
  16. * 专题视图类
  17. *
  18. * @package SpecView
  19. * @subpackage DedeBIZ.Libraries
  20. * @link https://www.dedebiz.com
  21. */
  22. class SpecView
  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 $TempInfos;
  36. var $Fields;
  37. var $StartTime;
  38. var $remoteDir;
  39. /**
  40. * php5构造函数
  41. *
  42. * @access public
  43. * @param int $starttime 开始时间
  44. * @return string
  45. */
  46. function __construct($starttime = 0)
  47. {
  48. $this->TypeID = 0;
  49. $this->dsql = $GLOBALS['dsql'];
  50. $this->dtp = new DedeTagParse();
  51. $this->dtp->SetRefObj($this);
  52. $this->dtp->SetNameSpace("dede", "{", "}");
  53. $this->dtp2 = new DedeTagParse();
  54. $this->dtp2->SetNameSpace("field", "[", "]");
  55. $this->TypeLink = new TypeLink(0);
  56. $this->ChannelUnit = new ChannelUnit(-1);
  57. $this->remoteDir = '';
  58. //设置一些全局参数的值
  59. foreach ($GLOBALS['PubFields'] as $k => $v) {
  60. $this->Fields[$k] = $v;
  61. }
  62. if ($starttime == 0) {
  63. $this->StartTime = 0;
  64. } else {
  65. $this->StartTime = GetMkTime($starttime);
  66. }
  67. $this->CountRecord();
  68. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_spec.htm";
  69. if (!file_exists($tempfile) || !is_file($tempfile)) {
  70. echo "模板文件不存在,无法解析文档";
  71. exit();
  72. }
  73. $this->dtp->LoadTemplate($tempfile);
  74. $this->TempInfos['tags'] = $this->dtp->CTags;
  75. $this->TempInfos['source'] = $this->dtp->SourceString;
  76. $ctag = $this->dtp->GetTag("page");
  77. if (!is_object($ctag)) {
  78. $this->pagesize = 20;
  79. } else {
  80. if ($ctag->GetAtt("pagesize") != "") {
  81. $this->pagesize = $ctag->GetAtt("pagesize");
  82. } else {
  83. $this->pagesize = 20;
  84. }
  85. }
  86. $this->TotalPage = ceil($this->TotalResult / $this->pagesize);
  87. }
  88. //php4构造函数
  89. function SpecView($starttime = 0)
  90. {
  91. $this->__construct($starttime);
  92. }
  93. //关闭相关资源
  94. function Close()
  95. {
  96. }
  97. /**
  98. * 统计列表里的记录
  99. *
  100. * @access private
  101. * @return void
  102. */
  103. function CountRecord()
  104. {
  105. $this->TotalResult = -1;
  106. if (isset($GLOBALS['TotalResult'])) {
  107. $this->TotalResult = $GLOBALS['TotalResult'];
  108. }
  109. if (isset($GLOBALS['PageNo'])) {
  110. $this->PageNo = $GLOBALS['PageNo'];
  111. } else {
  112. $this->PageNo = 1;
  113. }
  114. if ($this->TotalResult == -1) {
  115. if ($this->StartTime > 0) {
  116. $timesql = " AND #@__archives.senddate>'".$this->StartTime."'";
  117. } else {
  118. $timesql = "";
  119. }
  120. $row = $this->dsql->GetOne("SELECT count(*) AS dd FROM #@__archives WHERE #@__archives.arcrank > -1 AND channel=-1 $timesql");
  121. if (is_array($row)) {
  122. $this->TotalResult = $row['dd'];
  123. } else {
  124. $this->TotalResult = 0;
  125. }
  126. }
  127. }
  128. /**
  129. * 显示列表
  130. *
  131. * @access public
  132. * @return void
  133. */
  134. function Display()
  135. {
  136. if (isset($this->TypeLink->TypeInfos) && ($this->TypeLink->TypeInfos['ispart'] == 1
  137. || $this->TypeLink->TypeInfos['ispart'] == 2)) {
  138. $this->DisplayPartTemplets();
  139. }
  140. $this->ParseTempletsFirst();
  141. foreach ($this->dtp->CTags as $tagid => $ctag) {
  142. if ($ctag->GetName() == "list") {
  143. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  144. $row = $this->pagesize;
  145. if (trim($ctag->GetInnerText()) == "") {
  146. $InnerText = GetSysTemplets("list_fulllist.htm");
  147. } else {
  148. $InnerText = trim($ctag->GetInnerText());
  149. }
  150. $this->dtp->Assign(
  151. $tagid,
  152. $this->GetArcList(
  153. $limitstart,
  154. $row,
  155. $ctag->GetAtt("col"),
  156. $ctag->GetAtt("titlelen"),
  157. $ctag->GetAtt("infolen"),
  158. $ctag->GetAtt("imgwidth"),
  159. $ctag->GetAtt("imgheight"),
  160. $ctag->GetAtt("listtype"),
  161. $ctag->GetAtt("orderby"),
  162. $InnerText,
  163. $ctag->GetAtt("tablewidth")
  164. )
  165. );
  166. } else if ($ctag->GetName() == "pagelist") {
  167. $list_len = trim($ctag->GetAtt("listsize"));
  168. if ($list_len == "") {
  169. $list_len = 3;
  170. }
  171. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len));
  172. }
  173. }
  174. $this->dtp->Display();
  175. }
  176. /**
  177. * 开始创建列表
  178. *
  179. * @access public
  180. * @param int $isremote 是否远程
  181. * @return string
  182. */
  183. function MakeHtml($isremote = 0)
  184. {
  185. //初步给固定值的标记赋值
  186. $this->ParseTempletsFirst();
  187. $totalpage = ceil($this->TotalResult / $this->pagesize);
  188. if ($totalpage == 0) {
  189. $totalpage = 1;
  190. }
  191. CreateDir($GLOBALS['cfg_special']);
  192. $murl = "";
  193. for ($this->PageNo = 1; $this->PageNo <= $totalpage; $this->PageNo++) {
  194. foreach ($this->dtp->CTags as $tagid => $ctag) {
  195. if ($ctag->GetName() == "list") {
  196. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  197. $row = $this->pagesize;
  198. if (trim($ctag->GetInnerText()) == "") {
  199. $InnerText = GetSysTemplets("spec_list.htm");
  200. } else {
  201. $InnerText = trim($ctag->GetInnerText());
  202. }
  203. $this->dtp->Assign(
  204. $tagid,
  205. $this->GetArcList(
  206. $limitstart,
  207. $row,
  208. $ctag->GetAtt("col"),
  209. $ctag->GetAtt("titlelen"),
  210. $ctag->GetAtt("infolen"),
  211. $ctag->GetAtt("imgwidth"),
  212. $ctag->GetAtt("imgheight"),
  213. "spec",
  214. $ctag->GetAtt("orderby"),
  215. $InnerText,
  216. $ctag->GetAtt("tablewidth")
  217. )
  218. );
  219. } else if ($ctag->GetName() == "pagelist") {
  220. $list_len = trim($ctag->GetAtt("listsize"));
  221. if ($list_len == "") {
  222. $list_len = 3;
  223. }
  224. $this->dtp->Assign($tagid, $this->GetPageListST($list_len));
  225. }
  226. } //End foreach
  227. $makeFile = $GLOBALS['cfg_special']."/spec_".$this->PageNo.$GLOBALS['art_shortname'];
  228. $murl = $makeFile;
  229. $makeFile = $GLOBALS['cfg_basedir'].$makeFile;
  230. $this->dtp->SaveTo($makeFile);
  231. echo "成功创建:$murl<br>";
  232. }
  233. copy($GLOBALS['cfg_basedir'].$GLOBALS['cfg_special']."/spec_1".$GLOBALS['art_shortname'], $GLOBALS['cfg_basedir'].$GLOBALS['cfg_special']."/index.html");
  234. $murl = $GLOBALS['cfg_special']."/index.html";
  235. return $murl;
  236. }
  237. /**
  238. * 解析模板,对固定的标记进行初始给值
  239. *
  240. * @access private
  241. * @return void
  242. */
  243. function ParseTempletsFirst()
  244. {
  245. MakeOneTag($this->dtp, $this);
  246. }
  247. /**
  248. * 获取内容列表
  249. *
  250. * @access public
  251. * @param int $limitstart 限制开始
  252. * @param int $row 行数
  253. * @param int $col 列数
  254. * @param int $titlelen 标题长度
  255. * @param int $infolen 描述长度
  256. * @param int $imgwidth 图片宽度
  257. * @param int $imgheight 图片高度
  258. * @param string $listtype 列表类型
  259. * @param string $orderby 排列顺序
  260. * @param string $innertext 底层模板
  261. * @param string $tablewidth 表格宽度
  262. * @return string
  263. */
  264. function GetArcList(
  265. $limitstart = 0,
  266. $row = 10,
  267. $col = 1,
  268. $titlelen = 30,
  269. $infolen = 250,
  270. $imgwidth = 120,
  271. $imgheight = 90,
  272. $listtype = "all",
  273. $orderby = "default",
  274. $innertext = "",
  275. $tablewidth = "100"
  276. ) {
  277. $typeid = $this->TypeID;
  278. if ($row == "") {
  279. $row = 10;
  280. }
  281. if ($limitstart == "") {
  282. $limitstart = 0;
  283. }
  284. if ($titlelen == "") {
  285. $titlelen = 30;
  286. }
  287. if ($infolen == "") {
  288. $infolen = 250;
  289. }
  290. if ($imgwidth == "") {
  291. $imgwidth = 120;
  292. }
  293. if ($imgheight == "") {
  294. $imgheight = 120;
  295. }
  296. if ($listtype == "") {
  297. $listtype = "all";
  298. }
  299. if ($orderby == "") {
  300. $orderby = "default";
  301. } else {
  302. $orderby = strtolower($orderby);
  303. }
  304. $tablewidth = str_replace("%", "", $tablewidth);
  305. if ($tablewidth == "") {
  306. $tablewidth = 100;
  307. }
  308. if ($col == "") {
  309. $col = 1;
  310. }
  311. $colWidth = ceil(100 / $col);
  312. $tablewidth = $tablewidth."%";
  313. $colWidth = $colWidth."%";
  314. $innertext = trim($innertext);
  315. if ($innertext == "") {
  316. $innertext = GetSysTemplets("spec_list.htm");
  317. }
  318. //按不同情况设定SQL条件
  319. $orwhere = " arc.arcrank > -1 AND arc.channel = -1 ";
  320. if ($this->StartTime > 0) {
  321. $orwhere .= " AND arc.senddate>'".$this->StartTime."'";
  322. }
  323. //排序方式
  324. $ordersql = '';
  325. if ($orderby == 'senddate') {
  326. $ordersql = " ORDER BY arc.senddate desc";
  327. } else if ($orderby == 'pubdate') {
  328. $ordersql = " ORDER BY arc.pubdate desc";
  329. } else if ($orderby == 'id') {
  330. $ordersql = " ORDER BY arc.id desc";
  331. } else {
  332. $ordersql = " ORDER BY arc.sortrank desc";
  333. }
  334. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,arc.money,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE $orwhere $ordersql LIMIT $limitstart,$row ";
  335. $this->dsql->SetQuery($query);
  336. $this->dsql->Execute('al');
  337. $artlist = '';
  338. if ($col > 1) {
  339. $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  340. }
  341. $this->dtp2->LoadSource($innertext);
  342. for ($i = 0; $i < $row; $i++) {
  343. if ($col > 1) {
  344. $artlist .= "<tr>\r\n";
  345. }
  346. for ($j = 0; $j < $col; $j++) {
  347. if ($col > 1) {
  348. $artlist .= "<td width='$colWidth'>\r\n";
  349. }
  350. if ($row = $this->dsql->GetArray("al")) {
  351. //处理一些特殊字段
  352. $row["description"] = cn_substr($row["description"], $infolen);
  353. $row["title"] = cn_substr($row["title"], $titlelen);
  354. $row["id"] = $row["id"];
  355. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  356. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  357. }
  358. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  359. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  360. }
  361. $row['picname'] = $row['litpic'];
  362. $row["arcurl"] = GetFileUrl(
  363. $row["id"],
  364. $row["typeid"],
  365. $row["senddate"],
  366. $row["title"],
  367. $row["ismake"],
  368. $row["arcrank"],
  369. $row["namerule"],
  370. $row["typedir"],
  371. $row["money"],
  372. $row['filename'],
  373. $row["moresite"],
  374. $row["siteurl"],
  375. $row["sitepath"]
  376. );
  377. $row["typeurl"] = GetTypeUrl($row["typeid"], $row["typedir"], $row["isdefault"], $row["defaultname"], $row["ispart"], $row["namerule2"], $row["moresite"], $row["siteurl"], $row["sitepath"]);
  378. $row["info"] = $row["description"];
  379. $row["filename"] = $row["arcurl"];
  380. $row["stime"] = GetDateMK($row["pubdate"]);
  381. $row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>";
  382. $row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]";
  383. $row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'></a>";
  384. $row["image"] = "<img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'>";
  385. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  386. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  387. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  388. //编译附加表里的数据
  389. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  390. if (isset($row[$k])) {
  391. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  392. }
  393. }
  394. if (is_array($this->dtp2->CTags)) {
  395. foreach ($this->dtp2->CTags as $k => $ctag) {
  396. if ($ctag->GetName() == 'array') {
  397. //传递整个数组,在runphp模式中有特殊作用
  398. $this->dtp2->Assign($k, $row);
  399. } else {
  400. if (isset($row[$ctag->GetName()])) {
  401. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  402. } else {
  403. $this->dtp2->Assign($k, '');
  404. }
  405. }
  406. }
  407. }
  408. $artlist .= $this->dtp2->GetResult();
  409. } //if hasRow
  410. else {
  411. $artlist .= "";
  412. }
  413. if ($col > 1) {
  414. $artlist .= "</td>\r\n";
  415. }
  416. } //Loop Col
  417. if ($col > 1) {
  418. $artlist .= "</tr>\r\n";
  419. }
  420. } //Loop Line
  421. if ($col > 1) {
  422. $artlist .= "</table>\r\n";
  423. }
  424. $this->dsql->FreeResult("al");
  425. return $artlist;
  426. }
  427. /**
  428. * 获取静态的分页列表
  429. *
  430. * @access public
  431. * @param int $list_len 列表宽度
  432. * @return string
  433. */
  434. function GetPageListST($list_len)
  435. {
  436. $prepage = "";
  437. $nextpage = "";
  438. $prepagenum = $this->PageNo - 1;
  439. $nextpagenum = $this->PageNo + 1;
  440. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  441. $list_len = 3;
  442. }
  443. $totalpage = ceil($this->TotalResult / $this->pagesize);
  444. if ($totalpage <= 1 && $this->TotalResult > 0) {
  445. return "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  446. }
  447. if ($this->TotalResult == 0) {
  448. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  449. }
  450. $purl = $this->GetCurUrl();
  451. $tnamerule = "spec_";
  452. //获得上一页和下一页的链接
  453. if ($this->PageNo != 1) {
  454. $prepage .= "<li><a href='".$tnamerule."$prepagenum".$GLOBALS['art_shortname']."'>上一页</a></li>\r\n";
  455. $indexpage = "<li><a href='".$tnamerule."1".$GLOBALS['art_shortname']."'>首页</a></li>\r\n";
  456. } else {
  457. $indexpage = "<li><a>首页</a></li>\r\n";
  458. }
  459. if ($this->PageNo != $totalpage && $totalpage > 1) {
  460. $nextpage .= "<li><a href='".$tnamerule."$nextpagenum".$GLOBALS['art_shortname']."'>下一页</a></li>\r\n";
  461. $endpage = "<li><a href='".$tnamerule."$totalpage".$GLOBALS['art_shortname']."'>末页</a></li>\r\n";
  462. } else {
  463. $endpage = "<li><a>末页</a></li>\r\n";
  464. }
  465. //获得数字链接
  466. $listdd = "";
  467. $total_list = $list_len * 2 + 1;
  468. if ($this->PageNo >= $total_list) {
  469. $j = $this->PageNo - $list_len;
  470. $total_list = $this->PageNo + $list_len;
  471. if ($total_list > $totalpage) {
  472. $total_list = $totalpage;
  473. }
  474. } else {
  475. $j = 1;
  476. if ($total_list > $totalpage) {
  477. $total_list = $totalpage;
  478. }
  479. }
  480. for ($j; $j <= $total_list; $j++) {
  481. if ($j == $this->PageNo) {
  482. $listdd .= "<li class='thisclass'><a>$j</a></li>\r\n";
  483. } else {
  484. $listdd .= "<li><a href='".$tnamerule."$j".$GLOBALS['art_shortname']."'>".$j."</a></li>\r\n";
  485. }
  486. }
  487. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  488. return $plist;
  489. }
  490. /**
  491. * 获取动态的分页列表
  492. *
  493. * @access private
  494. * @param int $list_len 列表宽度
  495. * @return string
  496. */
  497. function GetPageListDM($list_len)
  498. {
  499. $prepage = "";
  500. $nextpage = "";
  501. $prepagenum = $this->PageNo - 1;
  502. $nextpagenum = $this->PageNo + 1;
  503. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  504. $list_len = 3;
  505. }
  506. $totalpage = ceil($this->TotalResult / $this->pagesize);
  507. if ($totalpage <= 1 && $this->TotalResult > 0) {
  508. return "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  509. }
  510. if ($this->TotalResult == 0) {
  511. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  512. }
  513. $purl = $this->GetCurUrl();
  514. $geturl = "typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  515. $hidenform = "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
  516. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  517. $purl .= "?".$geturl;
  518. //获得上一页和下一页的链接
  519. if ($this->PageNo != 1) {
  520. $prepage .= "<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  521. $indexpage = "<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
  522. } else {
  523. $indexpage = "<li><a>首页</a></li>\r\n";
  524. }
  525. if ($this->PageNo != $totalpage && $totalpage > 1) {
  526. $nextpage .= "<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  527. $endpage = "<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  528. } else {
  529. $endpage = "<li><a>末页</a></li>";
  530. }
  531. //获得数字链接
  532. $listdd = "";
  533. $total_list = $list_len * 2 + 1;
  534. if ($this->PageNo >= $total_list) {
  535. $j = $this->PageNo - $list_len;
  536. $total_list = $this->PageNo + $list_len;
  537. if ($total_list > $totalpage) {
  538. $total_list = $totalpage;
  539. }
  540. } else {
  541. $j = 1;
  542. if ($total_list > $totalpage) {
  543. $total_list = $totalpage;
  544. }
  545. }
  546. for ($j; $j <= $total_list; $j++) {
  547. if ($j == $this->PageNo) {
  548. $listdd .= "<li class='thisclass'><a>$j</a></li>\r\n";
  549. } else {
  550. $listdd .= "<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  551. }
  552. }
  553. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  554. return $plist;
  555. }
  556. /**
  557. * 获得当前的页面文件的url
  558. *
  559. * @access private
  560. * @return string
  561. */
  562. function GetCurUrl()
  563. {
  564. if (!empty($_SERVER["REQUEST_URI"])) {
  565. $nowurl = $_SERVER["REQUEST_URI"];
  566. $nowurls = explode("?", $nowurl);
  567. $nowurl = $nowurls[0];
  568. } else {
  569. $nowurl = $_SERVER["PHP_SELF"];
  570. }
  571. return $nowurl;
  572. }
  573. }//End Class
  574. ?>