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

233 lines
7.8KB

  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) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.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 http://www.dedecms.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. global $cfg_remote_site;
  95. $murl = $GLOBALS['cfg_cmspath']."/data/rss/".$this->TypeID.".xml";
  96. $mfile = $GLOBALS['cfg_basedir'].$murl;
  97. $this->dtp->SaveTo($mfile);
  98. //如果启用远程站点则上传
  99. if($cfg_remote_site=='Y' && $isremote == 1)
  100. {
  101. //分析远程文件路径
  102. $remotefile = $murl;
  103. $localfile = '..'.$remotefile;
  104. $remotedir = preg_replace('/[^\/]*\.xml/', '',$remotefile);
  105. //不相等则说明已经切换目录则可以创建镜像
  106. $this->ftp->rmkdir($remotedir);
  107. $this->ftp->upload($localfile, $remotefile, 'acii');
  108. }
  109. return $murl;
  110. }
  111. /**
  112. * 解析模板
  113. *
  114. * @access public
  115. * @return void
  116. */
  117. function ParseTemplet()
  118. {
  119. foreach($this->dtp->CTags as $tid => $ctag)
  120. {
  121. if($ctag->GetName()=="field")
  122. {
  123. $this->dtp->Assign($tid,$this->TypeFields[$ctag->GetAtt('name')]);
  124. }
  125. else if($ctag->GetName()=="rssitem")
  126. {
  127. $this->dtp->Assign($tid,
  128. $this->GetArcList($ctag->GetInnerText())
  129. );
  130. }
  131. }
  132. }
  133. /**
  134. * 获得文档列表
  135. *
  136. * @access public
  137. * @param string $innertext 底层模板
  138. * @return string
  139. */
  140. function GetArcList($innertext="")
  141. {
  142. $typeid=$this->TypeID;
  143. $innertext = trim($innertext);
  144. if($innertext=="")
  145. {
  146. $innertext = GetSysTemplets("rss.htm");
  147. }
  148. $orwhere = " arc.arcrank > -1 ";
  149. $orwhere .= " AND (arc.typeid in (".GetSonIds($this->TypeID,$this->TypeFields['channeltype']).") ) ";
  150. $ordersql=" ORDER BY arc.id desc";
  151. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,
  152. tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  153. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  154. WHERE $orwhere $ordersql LIMIT 0,".$this->MaxRow;
  155. $this->dsql->SetQuery($query);
  156. $this->dsql->Execute('al');
  157. $artlist = '';
  158. $dtp2 = new DedeTagParse();
  159. $dtp2->SetNameSpace('field','[',']');
  160. $dtp2->LoadSource($innertext);
  161. while($row = $this->dsql->GetArray('al'))
  162. {
  163. //处理一些特殊字段
  164. if($row['litpic'] == '-' || $row['litpic'] == '')
  165. {
  166. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  167. }
  168. if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  169. {
  170. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  171. }
  172. $row['picname'] = $row['litpic'];
  173. $row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"],
  174. $row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]);
  175. $row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"],
  176. $row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]);
  177. $row["info"] = $row["description"];
  178. $row["filename"] = $row["arcurl"];
  179. $row["stime"] = GetDateMK($row["pubdate"]);
  180. $row["image"] = "<img src='".$row["picname"]."' border='0'>";
  181. $row["fullurl"] = $GLOBALS["cfg_basehost"].$row["arcurl"];
  182. if($GLOBALS['cfg_multi_site'] == 'Y') $row["fullurl"] = $row["arcurl"];
  183. $row["phpurl"] = $GLOBALS["cfg_plus_dir"];
  184. $row["templeturl"] = $GLOBALS["cfg_templets_dir"];
  185. if($row["source"]=='')
  186. {
  187. $row["source"] = $GLOBALS['cfg_webname'];
  188. }
  189. if($row["writer"]=='')
  190. {
  191. $row["writer"] = "秩名";
  192. }
  193. foreach($row as $k=>$v)
  194. {
  195. $row[$k] = dede_htmlspecialchars($v);
  196. }
  197. if(is_array($dtp2->CTags))
  198. {
  199. foreach($dtp2->CTags as $k=>$ctag)
  200. {
  201. if($ctag->GetName()=='array')
  202. {
  203. //传递整个数组,在runphp模式中有特殊作用
  204. $dtp2->Assign($k,$row);
  205. }
  206. else
  207. {
  208. if(isset($row[$ctag->GetName()]))
  209. {
  210. $dtp2->Assign($k,$row[$ctag->GetName()]);
  211. }
  212. else
  213. {
  214. $dtp2->Assign($k,'');
  215. }
  216. }
  217. }
  218. }
  219. $artlist .= $dtp2->GetResult()."\r\n";
  220. }
  221. $this->dsql->FreeResult('al');
  222. return $artlist;
  223. }
  224. }//End Class