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

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