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

210 lines
7.1KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * RSS视图类
  5. *
  6. * @version $id:rssview.class.php 15:21 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."/dedetag.class.php");
  13. require_once(DEDEINC."/typelink/typelink.class.php");
  14. require_once(DEDEINC."/channelunit.func.php");
  15. @set_time_limit(0);
  16. /**
  17. * RSS视图类
  18. *
  19. * @package RssView
  20. * @subpackage DedeBIZ.Libraries
  21. * @link https://www.dedebiz.com
  22. */
  23. class RssView
  24. {
  25. var $dsql;
  26. var $TypeID;
  27. var $TypeLink;
  28. var $TypeFields;
  29. var $MaxRow;
  30. var $dtp;
  31. var $remoteDir;
  32. /**
  33. * php5构造函数
  34. *
  35. * @access public
  36. * @param int $typeid 栏目id
  37. * @param int $max_row 最大显示行数
  38. * @return string
  39. */
  40. function __construct($typeid, $max_row = 50)
  41. {
  42. $this->TypeID = $typeid;
  43. $this->dtp = new DedeTagParse();
  44. $this->dtp->refObj = $this;
  45. $templetfiles = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/plus/rss.htm";
  46. $this->dtp->LoadTemplate($templetfiles);
  47. $this->dsql = $GLOBALS['dsql'];
  48. $this->TypeLink = new TypeLink($typeid);
  49. $this->TypeFields = $this->TypeLink->TypeInfos;
  50. $this->MaxRow = $max_row;
  51. $this->TypeFields['title'] = $this->TypeLink->GetPositionLink(false);
  52. $this->TypeFields['title'] = preg_replace("/[<>]/", " / ", $this->TypeFields['title']);
  53. $this->TypeFields['typelink'] = $GLOBALS['cfg_basehost'].$this->TypeLink->GetOneTypeUrl($this->TypeFields);
  54. $this->TypeFields['powerby'] = $GLOBALS['cfg_powerby'];
  55. $this->TypeFields['adminemail'] = $GLOBALS['cfg_adminemail'];
  56. $this->remoteDir = '';
  57. foreach ($this->TypeFields as $k => $v) {
  58. $this->TypeFields[$k] = dede_htmlspecialchars($v);
  59. }
  60. $this->ParseTemplet();
  61. }
  62. //php4构造函数
  63. function RssView($typeid, $max_row = 50)
  64. {
  65. $this->__construct($typeid, $max_row);
  66. }
  67. //关闭相关资源
  68. function Close()
  69. {
  70. }
  71. /**
  72. * 显示列表
  73. *
  74. * @access public
  75. * @return void
  76. */
  77. function Display()
  78. {
  79. $this->dtp->Display();
  80. }
  81. /**
  82. * 开始创建列表
  83. *
  84. * @access public
  85. * @param string $isremote 是否远程
  86. * @return string
  87. */
  88. function MakeRss($isremote = 0)
  89. {
  90. $murl = $GLOBALS['cfg_cmspath']."/static/rss/".$this->TypeID.".xml";
  91. $mfile = $GLOBALS['cfg_basedir'].$murl;
  92. $this->dtp->SaveTo($mfile);
  93. return $murl;
  94. }
  95. /**
  96. * 解析模板
  97. *
  98. * @access public
  99. * @return void
  100. */
  101. function ParseTemplet()
  102. {
  103. foreach ($this->dtp->CTags as $tid => $ctag) {
  104. if ($ctag->GetName() == "field") {
  105. $this->dtp->Assign($tid, $this->TypeFields[$ctag->GetAtt('name')]);
  106. } else if ($ctag->GetName() == "rssitem") {
  107. $this->dtp->Assign(
  108. $tid,
  109. $this->GetArcList($ctag->GetInnerText())
  110. );
  111. }
  112. }
  113. }
  114. /**
  115. * 获得文档列表
  116. *
  117. * @access public
  118. * @param string $innertext 底层模板
  119. * @return string
  120. */
  121. function GetArcList($innertext = "")
  122. {
  123. $typeid = $this->TypeID;
  124. $innertext = trim($innertext);
  125. if ($innertext == "") {
  126. $innertext = GetSysTemplets("rss.htm");
  127. }
  128. $orwhere = " arc.arcrank > -1 ";
  129. $orwhere .= " AND (arc.typeid in (".GetSonIds($this->TypeID, $this->TypeFields['channeltype']).") ) ";
  130. $ordersql = " ORDER BY arc.id desc";
  131. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE $orwhere $ordersql LIMIT 0,".$this->MaxRow;
  132. $this->dsql->SetQuery($query);
  133. $this->dsql->Execute('al');
  134. $artlist = '';
  135. $dtp2 = new DedeTagParse();
  136. $dtp2->SetNameSpace('field', '[', ']');
  137. $dtp2->LoadSource($innertext);
  138. while ($row = $this->dsql->GetArray('al')) {
  139. //处理一些特殊字段
  140. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  141. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  142. }
  143. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  144. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  145. }
  146. $row['picname'] = $row['litpic'];
  147. $row["arcurl"] = GetFileUrl(
  148. $row["id"],
  149. $row["typeid"],
  150. $row["senddate"],
  151. $row["title"],
  152. $row["ismake"],
  153. $row["arcrank"],
  154. $row["namerule"],
  155. $row["typedir"],
  156. $row["money"],
  157. $row['filename'],
  158. $row["moresite"],
  159. $row["siteurl"],
  160. $row["sitepath"]
  161. );
  162. $row["typeurl"] = GetTypeUrl(
  163. $row["typeid"],
  164. $row["typedir"],
  165. $row["isdefault"],
  166. $row["defaultname"],
  167. $row["ispart"],
  168. $row["namerule2"],
  169. $row["moresite"],
  170. $row["siteurl"],
  171. $row["sitepath"]
  172. );
  173. $row["info"] = $row["description"];
  174. $row["filename"] = $row["arcurl"];
  175. $row["stime"] = GetDateMK($row["pubdate"]);
  176. $row["image"] = "<img src='".$row["picname"]."'>";
  177. $row["fullurl"] = $GLOBALS["cfg_basehost"].$row["arcurl"];
  178. if ($GLOBALS['cfg_multi_site'] == 'Y') $row["fullurl"] = $row["arcurl"];
  179. $row["phpurl"] = $GLOBALS["cfg_plus_dir"];
  180. $row["templeturl"] = $GLOBALS["cfg_templets_dir"];
  181. if ($row["source"] == '') {
  182. $row["source"] = $GLOBALS['cfg_webname'];
  183. }
  184. if ($row["writer"] == '') {
  185. $row["writer"] = "张生";
  186. }
  187. foreach ($row as $k => $v) {
  188. $row[$k] = dede_htmlspecialchars($v);
  189. }
  190. if (is_array($dtp2->CTags)) {
  191. foreach ($dtp2->CTags as $k => $ctag) {
  192. if ($ctag->GetName() == 'array') {
  193. //传递整个数组,在runphp模式中有特殊作用
  194. $dtp2->Assign($k, $row);
  195. } else {
  196. if (isset($row[$ctag->GetName()])) {
  197. $dtp2->Assign($k, $row[$ctag->GetName()]);
  198. } else {
  199. $dtp2->Assign($k, '');
  200. }
  201. }
  202. }
  203. }
  204. $artlist .= $dtp2->GetResult()."\r\n";
  205. }
  206. $this->dsql->FreeResult('al');
  207. return $artlist;
  208. }
  209. }//End Class
  210. ?>