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

569 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 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. /**
  170. * 开始创建列表
  171. *
  172. * @access public
  173. * @param int $isremote 是否远程
  174. * @return string
  175. */
  176. function MakeHtml($isremote = 0)
  177. {
  178. //初步给固定值的标记赋值
  179. $this->ParseTempletsFirst();
  180. $totalpage = ceil($this->TotalResult / $this->pagesize);
  181. if ($totalpage == 0) {
  182. $totalpage = 1;
  183. }
  184. CreateDir($GLOBALS['cfg_special']);
  185. $murl = "";
  186. for ($this->PageNo = 1; $this->PageNo <= $totalpage; $this->PageNo++) {
  187. foreach ($this->dtp->CTags as $tagid => $ctag) {
  188. if ($ctag->GetName() == "list") {
  189. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  190. $row = $this->pagesize;
  191. if (trim($ctag->GetInnerText()) == "") {
  192. $InnerText = GetSysTemplets("spec_list.htm");
  193. } else {
  194. $InnerText = trim($ctag->GetInnerText());
  195. }
  196. $this->dtp->Assign(
  197. $tagid,
  198. $this->GetArcList(
  199. $limitstart,
  200. $row,
  201. $ctag->GetAtt("col"),
  202. $ctag->GetAtt("titlelen"),
  203. $ctag->GetAtt("infolen"),
  204. $ctag->GetAtt("imgwidth"),
  205. $ctag->GetAtt("imgheight"),
  206. "spec",
  207. $ctag->GetAtt("orderby"),
  208. $InnerText,
  209. $ctag->GetAtt("tablewidth")
  210. )
  211. );
  212. } else if ($ctag->GetName() == "pagelist") {
  213. $list_len = trim($ctag->GetAtt("listsize"));
  214. if ($list_len == "") {
  215. $list_len = 3;
  216. }
  217. $this->dtp->Assign($tagid, $this->GetPageListST($list_len));
  218. }
  219. } //End foreach
  220. $makeFile = $GLOBALS['cfg_special']."/spec_".$this->PageNo.$GLOBALS['art_shortname'];
  221. $murl = $makeFile;
  222. $makeFile = $GLOBALS['cfg_basedir'].$makeFile;
  223. $this->dtp->SaveTo($makeFile);
  224. echo "成功创建:$murl<br>";
  225. }
  226. copy($GLOBALS['cfg_basedir'].$GLOBALS['cfg_special']."/spec_1".$GLOBALS['art_shortname'], $GLOBALS['cfg_basedir'].$GLOBALS['cfg_special']."/index.html");
  227. $murl = $GLOBALS['cfg_special']."/index.html";
  228. return $murl;
  229. }
  230. /**
  231. * 解析模板,对固定的标记进行初始给值
  232. *
  233. * @access private
  234. * @return void
  235. */
  236. function ParseTempletsFirst()
  237. {
  238. MakeOneTag($this->dtp, $this);
  239. }
  240. /**
  241. * 获取文档列表
  242. *
  243. * @access public
  244. * @param int $limitstart 限制开始
  245. * @param int $row 行数
  246. * @param int $col 列数
  247. * @param int $titlelen 标题长度
  248. * @param int $infolen 描述长度
  249. * @param int $imgwidth 图片宽度
  250. * @param int $imgheight 图片高度
  251. * @param string $listtype 列表类型
  252. * @param string $orderby 排列顺序
  253. * @param string $innertext 底层模板
  254. * @param string $tablewidth 表格宽度
  255. * @return string
  256. */
  257. function GetArcList(
  258. $limitstart = 0,
  259. $row = 10,
  260. $col = 1,
  261. $titlelen = 30,
  262. $infolen = 250,
  263. $imgwidth = 120,
  264. $imgheight = 90,
  265. $listtype = "all",
  266. $orderby = "default",
  267. $innertext = "",
  268. $tablewidth = "100"
  269. ) {
  270. $typeid = $this->TypeID;
  271. if ($row == "") {
  272. $row = 10;
  273. }
  274. if ($limitstart == "") {
  275. $limitstart = 0;
  276. }
  277. if ($titlelen == "") {
  278. $titlelen = 30;
  279. }
  280. if ($infolen == "") {
  281. $infolen = 250;
  282. }
  283. if ($imgwidth == "") {
  284. $imgwidth = 120;
  285. }
  286. if ($imgheight == "") {
  287. $imgheight = 120;
  288. }
  289. if ($listtype == "") {
  290. $listtype = "all";
  291. }
  292. if ($orderby == "") {
  293. $orderby = "default";
  294. } else {
  295. $orderby = strtolower($orderby);
  296. }
  297. $tablewidth = str_replace("%", "", $tablewidth);
  298. if ($tablewidth == "") {
  299. $tablewidth = 100;
  300. }
  301. if ($col == "") {
  302. $col = 1;
  303. }
  304. $colWidth = ceil(100 / $col);
  305. $tablewidth = $tablewidth."%";
  306. $colWidth = $colWidth."%";
  307. $innertext = trim($innertext);
  308. if ($innertext == "") {
  309. $innertext = GetSysTemplets("spec_list.htm");
  310. }
  311. //按不同情况设定SQL条件
  312. $orwhere = " arc.arcrank > -1 AND arc.channel = -1 ";
  313. if ($this->StartTime > 0) {
  314. $orwhere .= " AND arc.senddate>'".$this->StartTime."'";
  315. }
  316. //排序方式
  317. $ordersql = '';
  318. if ($orderby == 'senddate') {
  319. $ordersql = " ORDER BY arc.senddate desc";
  320. } else if ($orderby == 'pubdate') {
  321. $ordersql = " ORDER BY arc.pubdate desc";
  322. } else if ($orderby == 'id') {
  323. $ordersql = " ORDER BY arc.id desc";
  324. } else {
  325. $ordersql = " ORDER BY arc.sortrank desc";
  326. }
  327. $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 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 ";
  328. $this->dsql->SetQuery($query);
  329. $this->dsql->Execute('al');
  330. $artlist = '';
  331. if ($col > 1) {
  332. $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  333. }
  334. $this->dtp2->LoadSource($innertext);
  335. for ($i = 0; $i < $row; $i++) {
  336. if ($col > 1) {
  337. $artlist .= "<tr>\r\n";
  338. }
  339. for ($j = 0; $j < $col; $j++) {
  340. if ($col > 1) {
  341. $artlist .= "<td width='$colWidth'>\r\n";
  342. }
  343. if ($row = $this->dsql->GetArray("al")) {
  344. //处理一些特殊字段
  345. $row["description"] = cn_substr($row["description"], $infolen);
  346. $row["title"] = cn_substr($row["title"], $titlelen);
  347. $row["id"] = $row["id"];
  348. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  349. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  350. }
  351. if (!preg_match("/^http:\/\//", $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['templeturl'] = $GLOBALS['cfg_templeturl'];
  382. //编译附加表里的数据
  383. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  384. if (isset($row[$k])) {
  385. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  386. }
  387. }
  388. if (is_array($this->dtp2->CTags)) {
  389. foreach ($this->dtp2->CTags as $k => $ctag) {
  390. if ($ctag->GetName() == 'array') {
  391. //传递整个数组,在runphp模式中有特殊作用
  392. $this->dtp2->Assign($k, $row);
  393. } else {
  394. if (isset($row[$ctag->GetName()])) {
  395. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  396. } else {
  397. $this->dtp2->Assign($k, '');
  398. }
  399. }
  400. }
  401. }
  402. $artlist .= $this->dtp2->GetResult();
  403. }//if hasRow
  404. else {
  405. $artlist .= "";
  406. }
  407. if ($col > 1) {
  408. $artlist .= "</td>\r\n";
  409. }
  410. }//Loop Col
  411. if ($col > 1) {
  412. $artlist .= "</tr>\r\n";
  413. }
  414. }//Loop Line
  415. if ($col > 1) {
  416. $artlist .= "</table>\r\n";
  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 "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  440. }
  441. if ($this->TotalResult == 0) {
  442. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  443. }
  444. $purl = $this->GetCurUrl();
  445. $tnamerule = "spec_";
  446. //获得上一页和下一页的链接
  447. if ($this->PageNo != 1) {
  448. $prepage .= "<li><a href='".$tnamerule."$prepagenum".$GLOBALS['art_shortname']."'>上一页</a></li>\r\n";
  449. $indexpage = "<li><a href='".$tnamerule."1".$GLOBALS['art_shortname']."'>首页</a></li>\r\n";
  450. } else {
  451. $indexpage = "<li><a>首页</a></li>\r\n";
  452. }
  453. if ($this->PageNo != $totalpage && $totalpage > 1) {
  454. $nextpage .= "<li><a href='".$tnamerule."$nextpagenum".$GLOBALS['art_shortname']."'>下一页</a></li>\r\n";
  455. $endpage = "<li><a href='".$tnamerule."$totalpage".$GLOBALS['art_shortname']."'>末页</a></li>\r\n";
  456. } else {
  457. $endpage = "<li><a>末页</a></li>\r\n";
  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='thisclass'><a>$j</a></li>\r\n";
  477. } else {
  478. $listdd .= "<li><a href='".$tnamerule."$j".$GLOBALS['art_shortname']."'>".$j."</a></li>\r\n";
  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 "<span class='pageinfo'>1页".$this->TotalResult."条</span>";
  503. }
  504. if ($this->TotalResult == 0) {
  505. return "<span class='pageinfo'>0页".$this->TotalResult."条</span>";
  506. }
  507. $purl = $this->GetCurUrl();
  508. $geturl = "typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
  509. $hidenform = "<input type='hidden' name='typeid' value='".$this->TypeID."'>\r\n";
  510. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";
  511. $purl .= "?".$geturl;
  512. //获得上一页和下一页的链接
  513. if ($this->PageNo != 1) {
  514. $prepage .= "<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  515. $indexpage = "<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
  516. } else {
  517. $indexpage = "<li><a>首页</a></li>\r\n";
  518. }
  519. if ($this->PageNo != $totalpage && $totalpage > 1) {
  520. $nextpage .= "<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  521. $endpage = "<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  522. } else {
  523. $endpage = "<li><a>末页</a></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='thisclass'><a>$j</a></li>\r\n";
  543. } else {
  544. $listdd .= "<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  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. }//End Class
  568. ?>