国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

576 řádky
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
  335. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  336. WHERE $orwhere $ordersql LIMIT $limitstart,$row ";
  337. $this->dsql->SetQuery($query);
  338. $this->dsql->Execute('al');
  339. $artlist = '';
  340. if ($col > 1) {
  341. $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  342. }
  343. $this->dtp2->LoadSource($innertext);
  344. for ($i = 0; $i < $row; $i++) {
  345. if ($col > 1) {
  346. $artlist .= "<tr>\r\n";
  347. }
  348. for ($j = 0; $j < $col; $j++) {
  349. if ($col > 1) {
  350. $artlist .= "<td width='$colWidth'>\r\n";
  351. }
  352. if ($row = $this->dsql->GetArray("al")) {
  353. //处理一些特殊字段
  354. $row["description"] = cn_substr($row["description"], $infolen);
  355. $row["title"] = cn_substr($row["title"], $titlelen);
  356. $row["id"] = $row["id"];
  357. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  358. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/defaultpic.jpg';
  359. }
  360. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  361. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  362. }
  363. $row['picname'] = $row['litpic'];
  364. $row["arcurl"] = GetFileUrl(
  365. $row["id"],
  366. $row["typeid"],
  367. $row["senddate"],
  368. $row["title"],
  369. $row["ismake"],
  370. $row["arcrank"],
  371. $row["namerule"],
  372. $row["typedir"],
  373. $row["money"],
  374. $row['filename'],
  375. $row["moresite"],
  376. $row["siteurl"],
  377. $row["sitepath"]
  378. );
  379. $row["typeurl"] = GetTypeUrl($row["typeid"], $row["typedir"], $row["isdefault"], $row["defaultname"], $row["ispart"], $row["namerule2"], $row["moresite"], $row["siteurl"], $row["sitepath"]);
  380. $row["info"] = $row["description"];
  381. $row["filename"] = $row["arcurl"];
  382. $row["stime"] = GetDateMK($row["pubdate"]);
  383. $row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>";
  384. $row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]";
  385. $row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'></a>";
  386. $row["image"] = "<img src='".$row["picname"]."' width='$imgwidth' height='$imgheight'>";
  387. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  388. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  389. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  390. //编译附加表里的数据
  391. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  392. if (isset($row[$k])) {
  393. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  394. }
  395. }
  396. if (is_array($this->dtp2->CTags)) {
  397. foreach ($this->dtp2->CTags as $k => $ctag) {
  398. if ($ctag->GetName() == 'array') {
  399. //传递整个数组,在runphp模式中有特殊作用
  400. $this->dtp2->Assign($k, $row);
  401. } else {
  402. if (isset($row[$ctag->GetName()])) {
  403. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  404. } else {
  405. $this->dtp2->Assign($k, '');
  406. }
  407. }
  408. }
  409. }
  410. $artlist .= $this->dtp2->GetResult();
  411. } //if hasRow
  412. else {
  413. $artlist .= "";
  414. }
  415. if ($col > 1) {
  416. $artlist .= "</td>\r\n";
  417. }
  418. } //Loop Col
  419. if ($col > 1) {
  420. $artlist .= "</tr>\r\n";
  421. }
  422. } //Loop Line
  423. if ($col > 1) {
  424. $artlist .= "</table>\r\n";
  425. }
  426. $this->dsql->FreeResult("al");
  427. return $artlist;
  428. }
  429. /**
  430. * 获取静态的分页列表
  431. *
  432. * @access public
  433. * @param int $list_len 列表宽度
  434. * @return string
  435. */
  436. function GetPageListST($list_len)
  437. {
  438. $prepage = "";
  439. $nextpage = "";
  440. $prepagenum = $this->PageNo - 1;
  441. $nextpagenum = $this->PageNo + 1;
  442. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  443. $list_len = 3;
  444. }
  445. $totalpage = ceil($this->TotalResult / $this->pagesize);
  446. if ($totalpage <= 1 && $this->TotalResult > 0) {
  447. return "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  448. }
  449. if ($this->TotalResult == 0) {
  450. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  451. }
  452. $purl = $this->GetCurUrl();
  453. $tnamerule = "spec_";
  454. //获得上一页和下一页的链接
  455. if ($this->PageNo != 1) {
  456. $prepage .= "<li><a href='".$tnamerule."$prepagenum".$GLOBALS['art_shortname']."'>上一页</a></li>\r\n";
  457. $indexpage = "<li><a href='".$tnamerule."1".$GLOBALS['art_shortname']."'>首页</a></li>\r\n";
  458. } else {
  459. $indexpage = "<li><a>首页</a></li>\r\n";
  460. }
  461. if ($this->PageNo != $totalpage && $totalpage > 1) {
  462. $nextpage .= "<li><a href='".$tnamerule."$nextpagenum".$GLOBALS['art_shortname']."'>下一页</a></li>\r\n";
  463. $endpage = "<li><a href='".$tnamerule."$totalpage".$GLOBALS['art_shortname']."'>末页</a></li>\r\n";
  464. } else {
  465. $endpage = "<li><a>末页</a></li>\r\n";
  466. }
  467. //获得数字链接
  468. $listdd = "";
  469. $total_list = $list_len * 2 + 1;
  470. if ($this->PageNo >= $total_list) {
  471. $j = $this->PageNo - $list_len;
  472. $total_list = $this->PageNo + $list_len;
  473. if ($total_list > $totalpage) {
  474. $total_list = $totalpage;
  475. }
  476. } else {
  477. $j = 1;
  478. if ($total_list > $totalpage) {
  479. $total_list = $totalpage;
  480. }
  481. }
  482. for ($j; $j <= $total_list; $j++) {
  483. if ($j == $this->PageNo) {
  484. $listdd .= "<li class='thisclass'><a>$j</a></li>\r\n";
  485. } else {
  486. $listdd .= "<li><a href='".$tnamerule."$j".$GLOBALS['art_shortname']."'>".$j."</a></li>\r\n";
  487. }
  488. }
  489. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  490. return $plist;
  491. }
  492. /**
  493. * 获取动态的分页列表
  494. *
  495. * @access private
  496. * @param int $list_len 列表宽度
  497. * @return string
  498. */
  499. function GetPageListDM($list_len)
  500. {
  501. $prepage = "";
  502. $nextpage = "";
  503. $prepagenum = $this->PageNo - 1;
  504. $nextpagenum = $this->PageNo + 1;
  505. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  506. $list_len = 3;
  507. }
  508. $totalpage = ceil($this->TotalResult / $this->pagesize);
  509. if ($totalpage <= 1 && $this->TotalResult > 0) {
  510. return "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  511. }
  512. if ($this->TotalResult == 0) {
  513. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  514. }
  515. $purl = $this->GetCurUrl();
  516. $geturl = "typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  517. $hidenform = "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
  518. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  519. $purl .= "?".$geturl;
  520. //获得上一页和下一页的链接
  521. if ($this->PageNo != 1) {
  522. $prepage .= "<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  523. $indexpage = "<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
  524. } else {
  525. $indexpage = "<li><a>首页</a></li>\r\n";
  526. }
  527. if ($this->PageNo != $totalpage && $totalpage > 1) {
  528. $nextpage .= "<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  529. $endpage = "<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  530. } else {
  531. $endpage = "<li><a>末页</a></li>";
  532. }
  533. //获得数字链接
  534. $listdd = "";
  535. $total_list = $list_len * 2 + 1;
  536. if ($this->PageNo >= $total_list) {
  537. $j = $this->PageNo - $list_len;
  538. $total_list = $this->PageNo + $list_len;
  539. if ($total_list > $totalpage) {
  540. $total_list = $totalpage;
  541. }
  542. } else {
  543. $j = 1;
  544. if ($total_list > $totalpage) {
  545. $total_list = $totalpage;
  546. }
  547. }
  548. for ($j; $j <= $total_list; $j++) {
  549. if ($j == $this->PageNo) {
  550. $listdd .= "<li class='thisclass'><a>$j</a></li>\r\n";
  551. } else {
  552. $listdd .= "<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  553. }
  554. }
  555. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  556. return $plist;
  557. }
  558. /**
  559. * 获得当前的页面文件的url
  560. *
  561. * @access private
  562. * @return string
  563. */
  564. function GetCurUrl()
  565. {
  566. if (!empty($_SERVER["REQUEST_URI"])) {
  567. $nowurl = $_SERVER["REQUEST_URI"];
  568. $nowurls = explode("?", $nowurl);
  569. $nowurl = $nowurls[0];
  570. } else {
  571. $nowurl = $_SERVER["PHP_SELF"];
  572. }
  573. return $nowurl;
  574. }
  575. }//End Class