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

224 lines
7.5KB

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