国内流行的内容管理系统(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.

570 lines
22KB

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