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

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