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

221 lines
7.3KB

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