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

608 lines
22KB

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