国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

604 строки
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) 2021, 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. @set_time_limit(0);
  14. /**
  15. * 专题视图类
  16. *
  17. * @package SpecView
  18. * @subpackage DedeBIZ.Libraries
  19. * @link https://www.dedebiz.com
  20. */
  21. class SpecView
  22. {
  23. var $dsql;
  24. var $dtp;
  25. var $dtp2;
  26. var $TypeID;
  27. var $TypeLink;
  28. var $PageNo;
  29. var $TotalPage;
  30. var $TotalResult;
  31. var $PageSize;
  32. var $ChannelUnit;
  33. var $ListType;
  34. var $TempInfos;
  35. var $Fields;
  36. var $StartTime;
  37. var $remoteDir;
  38. /**
  39. * php5构造函数
  40. *
  41. * @access public
  42. * @param int $starttime 开始时间
  43. * @return string
  44. */
  45. function __construct($starttime = 0)
  46. {
  47. $this->TypeID = 0;
  48. $this->dsql = $GLOBALS['dsql'];
  49. $this->dtp = new DedeTagParse();
  50. $this->dtp->SetRefObj($this);
  51. $this->dtp->SetNameSpace("dede", "{", "}");
  52. $this->dtp2 = new DedeTagParse();
  53. $this->dtp2->SetNameSpace("field", "[", "]");
  54. $this->TypeLink = new TypeLink(0);
  55. $this->ChannelUnit = new ChannelUnit(-1);
  56. $this->remoteDir = '';
  57. //设置一些全局参数的值
  58. foreach ($GLOBALS['PubFields'] as $k => $v) {
  59. $this->Fields[$k] = $v;
  60. }
  61. if ($starttime == 0) {
  62. $this->StartTime = 0;
  63. } else {
  64. $this->StartTime = GetMkTime($starttime);
  65. }
  66. $this->CountRecord();
  67. $tempfile = $GLOBALS['cfg_basedir'] . $GLOBALS['cfg_templets_dir'] . "/" . $GLOBALS['cfg_df_style'] . "/list_spec.htm";
  68. if (!file_exists($tempfile) || !is_file($tempfile)) {
  69. echo "模板文件不存在,无法解析文档!";
  70. exit();
  71. }
  72. $this->dtp->LoadTemplate($tempfile);
  73. $this->TempInfos['tags'] = $this->dtp->CTags;
  74. $this->TempInfos['source'] = $this->dtp->SourceString;
  75. $ctag = $this->dtp->GetTag("page");
  76. if (!is_object($ctag)) {
  77. $this->PageSize = 20;
  78. } else {
  79. if ($ctag->GetAtt("pagesize") != "") {
  80. $this->PageSize = $ctag->GetAtt("pagesize");
  81. } else {
  82. $this->PageSize = 20;
  83. }
  84. }
  85. $this->TotalPage = ceil($this->TotalResult / $this->PageSize);
  86. }
  87. //php4构造函数
  88. function SpecView($starttime = 0)
  89. {
  90. $this->__construct($starttime);
  91. }
  92. //关闭相关资源
  93. function Close()
  94. {
  95. }
  96. /**
  97. * 统计列表里的记录
  98. *
  99. * @access private
  100. * @return void
  101. */
  102. function CountRecord()
  103. {
  104. $this->TotalResult = -1;
  105. if (isset($GLOBALS['TotalResult'])) {
  106. $this->TotalResult = $GLOBALS['TotalResult'];
  107. }
  108. if (isset($GLOBALS['PageNo'])) {
  109. $this->PageNo = $GLOBALS['PageNo'];
  110. } else {
  111. $this->PageNo = 1;
  112. }
  113. if ($this->TotalResult == -1) {
  114. if ($this->StartTime > 0) {
  115. $timesql = " AND #@__archives.senddate>'" . $this->StartTime . "'";
  116. } else {
  117. $timesql = "";
  118. }
  119. $row = $this->dsql->GetOne("SELECT count(*) AS dd FROM #@__archives WHERE #@__archives.arcrank > -1 AND channel=-1 $timesql");
  120. if (is_array($row)) {
  121. $this->TotalResult = $row['dd'];
  122. } else {
  123. $this->TotalResult = 0;
  124. }
  125. }
  126. }
  127. /**
  128. * 显示列表
  129. *
  130. * @access public
  131. * @return void
  132. */
  133. function Display()
  134. {
  135. if (isset($this->TypeLink->TypeInfos) && ($this->TypeLink->TypeInfos['ispart'] == 1
  136. || $this->TypeLink->TypeInfos['ispart'] == 2)) {
  137. $this->DisplayPartTemplets();
  138. }
  139. $this->ParseTempletsFirst();
  140. foreach ($this->dtp->CTags as $tagid => $ctag) {
  141. if ($ctag->GetName() == "list") {
  142. $limitstart = ($this->PageNo - 1) * $this->PageSize;
  143. $row = $this->PageSize;
  144. if (trim($ctag->GetInnerText()) == "") {
  145. $InnerText = GetSysTemplets("list_fulllist.htm");
  146. } else {
  147. $InnerText = trim($ctag->GetInnerText());
  148. }
  149. $this->dtp->Assign(
  150. $tagid,
  151. $this->GetArcList(
  152. $limitstart,
  153. $row,
  154. $ctag->GetAtt("col"),
  155. $ctag->GetAtt("titlelen"),
  156. $ctag->GetAtt("infolen"),
  157. $ctag->GetAtt("imgwidth"),
  158. $ctag->GetAtt("imgheight"),
  159. $ctag->GetAtt("listtype"),
  160. $ctag->GetAtt("orderby"),
  161. $InnerText,
  162. $ctag->GetAtt("tablewidth")
  163. )
  164. );
  165. } else if ($ctag->GetName() == "pagelist") {
  166. $list_len = trim($ctag->GetAtt("listsize"));
  167. if ($list_len == "") {
  168. $list_len = 3;
  169. }
  170. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len));
  171. }
  172. }
  173. $this->dtp->Display();
  174. }
  175. /**
  176. * 开始创建列表
  177. *
  178. * @access public
  179. * @param int $isremote 是否远程
  180. * @return string
  181. */
  182. function MakeHtml($isremote = 0)
  183. {
  184. //初步给固定值的标记赋值
  185. $this->ParseTempletsFirst();
  186. $totalpage = ceil($this->TotalResult / $this->PageSize);
  187. if ($totalpage == 0) {
  188. $totalpage = 1;
  189. }
  190. CreateDir($GLOBALS['cfg_special']);
  191. $murl = "";
  192. for ($this->PageNo = 1; $this->PageNo <= $totalpage; $this->PageNo++) {
  193. foreach ($this->dtp->CTags as $tagid => $ctag) {
  194. if ($ctag->GetName() == "list") {
  195. $limitstart = ($this->PageNo - 1) * $this->PageSize;
  196. $row = $this->PageSize;
  197. if (trim($ctag->GetInnerText()) == "") {
  198. $InnerText = GetSysTemplets("spec_list.htm");
  199. } else {
  200. $InnerText = trim($ctag->GetInnerText());
  201. }
  202. $this->dtp->Assign(
  203. $tagid,
  204. $this->GetArcList(
  205. $limitstart,
  206. $row,
  207. $ctag->GetAtt("col"),
  208. $ctag->GetAtt("titlelen"),
  209. $ctag->GetAtt("infolen"),
  210. $ctag->GetAtt("imgwidth"),
  211. $ctag->GetAtt("imgheight"),
  212. "spec",
  213. $ctag->GetAtt("orderby"),
  214. $InnerText,
  215. $ctag->GetAtt("tablewidth")
  216. )
  217. );
  218. } else if ($ctag->GetName() == "pagelist") {
  219. $list_len = trim($ctag->GetAtt("listsize"));
  220. if ($list_len == "") {
  221. $list_len = 3;
  222. }
  223. $this->dtp->Assign($tagid, $this->GetPageListST($list_len));
  224. }
  225. } //End foreach
  226. $makeFile = $GLOBALS['cfg_special'] . "/spec_" . $this->PageNo . $GLOBALS['art_shortname'];
  227. $murl = $makeFile;
  228. $makeFile = $GLOBALS['cfg_basedir'] . $makeFile;
  229. $this->dtp->SaveTo($makeFile);
  230. echo "成功创建:$murl<br/>";
  231. }
  232. copy($GLOBALS['cfg_basedir'] . $GLOBALS['cfg_special'] . "/spec_1" . $GLOBALS['art_shortname'], $GLOBALS['cfg_basedir'] . $GLOBALS['cfg_special'] . "/index.html");
  233. $murl = $GLOBALS['cfg_special'] . "/index.html";
  234. return $murl;
  235. }
  236. /**
  237. * 解析模板,对固定的标记进行初始给值
  238. *
  239. * @access private
  240. * @return void
  241. */
  242. function ParseTempletsFirst()
  243. {
  244. MakeOneTag($this->dtp, $this);
  245. }
  246. /**
  247. * 获取内容列表
  248. *
  249. * @access public
  250. * @param int $limitstart 限制开始
  251. * @param int $row 行数
  252. * @param int $col 列数
  253. * @param int $titlelen 标题长度
  254. * @param int $infolen 描述长度
  255. * @param int $imgwidth 图片宽度
  256. * @param int $imgheight 图片高度
  257. * @param string $listtype 列表类型
  258. * @param string $orderby 排列顺序
  259. * @param string $innertext 底层模板
  260. * @param string $tablewidth 表格宽度
  261. * @return string
  262. */
  263. function GetArcList(
  264. $limitstart = 0,
  265. $row = 10,
  266. $col = 1,
  267. $titlelen = 30,
  268. $infolen = 250,
  269. $imgwidth = 120,
  270. $imgheight = 90,
  271. $listtype = "all",
  272. $orderby = "default",
  273. $innertext = "",
  274. $tablewidth = "100"
  275. ) {
  276. $typeid = $this->TypeID;
  277. if ($row == "") {
  278. $row = 10;
  279. }
  280. if ($limitstart == "") {
  281. $limitstart = 0;
  282. }
  283. if ($titlelen == "") {
  284. $titlelen = 30;
  285. }
  286. if ($infolen == "") {
  287. $infolen = 250;
  288. }
  289. if ($imgwidth == "") {
  290. $imgwidth = 120;
  291. }
  292. if ($imgheight == "") {
  293. $imgheight = 120;
  294. }
  295. if ($listtype == "") {
  296. $listtype = "all";
  297. }
  298. if ($orderby == "") {
  299. $orderby = "default";
  300. } else {
  301. $orderby = strtolower($orderby);
  302. }
  303. $tablewidth = str_replace("%", "", $tablewidth);
  304. if ($tablewidth == "") {
  305. $tablewidth = 100;
  306. }
  307. if ($col == "") {
  308. $col = 1;
  309. }
  310. $colWidth = ceil(100 / $col);
  311. $tablewidth = $tablewidth . "%";
  312. $colWidth = $colWidth . "%";
  313. $innertext = trim($innertext);
  314. if ($innertext == "") {
  315. $innertext = GetSysTemplets("spec_list.htm");
  316. }
  317. //按不同情况设定SQL条件
  318. $orwhere = " arc.arcrank > -1 AND arc.channel = -1 ";
  319. if ($this->StartTime > 0) {
  320. $orwhere .= " AND arc.senddate>'" . $this->StartTime . "'";
  321. }
  322. //排序方式
  323. $ordersql = '';
  324. if ($orderby == 'senddate') {
  325. $ordersql = " ORDER BY arc.senddate desc";
  326. } else if ($orderby == 'pubdate') {
  327. $ordersql = " ORDER BY arc.pubdate desc";
  328. } else if ($orderby == 'id') {
  329. $ordersql = " ORDER BY arc.id desc";
  330. } else {
  331. $ordersql = " ORDER BY arc.sortrank desc";
  332. }
  333. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,arc.money,
  334. 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' border='0' 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/defaultpic.gif';
  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"] . "' border='0' width='$imgwidth' height='$imgheight'></a>";
  386. $row["image"] = "<img src='" . $row["picname"] . "' border='0' 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\">共 <strong>1</strong>页<strong>" . $this->TotalResult . "</strong>条记录</span>";
  448. }
  449. if ($this->TotalResult == 0) {
  450. return "<span class=\"pageinfo\">共 <strong>0</strong>页<strong>" . $this->TotalResult . "</strong>条记录</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