/libraries/joomla/document/feed/feed.php

https://github.com/MaBelleEcole/Main · PHP · 502 lines · 85 code · 53 blank · 364 comment · 1 complexity · 7e821e14939646040ba10a1679047687 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id: feed.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla.Framework
  5. * @subpackage Document
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is within the rest of the framework
  15. defined('JPATH_BASE') or die();
  16. /**
  17. * DocumentFeed class, provides an easy interface to parse and display any feed document
  18. *
  19. * @package Joomla.Framework
  20. * @subpackage Document
  21. * @since 1.5
  22. */
  23. class JDocumentFeed extends JDocument
  24. {
  25. /**
  26. * Syndication URL feed element
  27. *
  28. * optional
  29. *
  30. * @var string
  31. * @access public
  32. */
  33. var $syndicationURL = "";
  34. /**
  35. * Image feed element
  36. *
  37. * optional
  38. *
  39. * @var object
  40. * @access public
  41. */
  42. var $image = null;
  43. /**
  44. * Copyright feed elememnt
  45. *
  46. * optional
  47. *
  48. * @var string
  49. * @access public
  50. */
  51. var $copyright = "";
  52. /**
  53. * Published date feed element
  54. *
  55. * optional
  56. *
  57. * @var string
  58. * @access public
  59. */
  60. var $pubDate = "";
  61. /**
  62. * Lastbuild date feed element
  63. *
  64. * optional
  65. *
  66. * @var string
  67. * @access public
  68. */
  69. var $lastBuildDate = "";
  70. /**
  71. * Editor feed element
  72. *
  73. * optional
  74. *
  75. * @var string
  76. * @access public
  77. */
  78. var $editor = "";
  79. /**
  80. * Docs feed element
  81. *
  82. * @var string
  83. * @access public
  84. */
  85. var $docs = "";
  86. /**
  87. * Editor email feed element
  88. *
  89. * optional
  90. *
  91. * @var string
  92. * @access public
  93. */
  94. var $editorEmail = "";
  95. /**
  96. * Webmaster email feed element
  97. *
  98. * optional
  99. *
  100. * @var string
  101. * @access public
  102. */
  103. var $webmaster = "";
  104. /**
  105. * Category feed element
  106. *
  107. * optional
  108. *
  109. * @var string
  110. * @access public
  111. */
  112. var $category = "";
  113. /**
  114. * TTL feed attribute
  115. *
  116. * optional
  117. *
  118. * @var string
  119. * @access public
  120. */
  121. var $ttl = "";
  122. /**
  123. * Rating feed element
  124. *
  125. * optional
  126. *
  127. * @var string
  128. * @access public
  129. */
  130. var $rating = "";
  131. /**
  132. * Skiphours feed element
  133. *
  134. * optional
  135. *
  136. * @var string
  137. * @access public
  138. */
  139. var $skipHours = "";
  140. /**
  141. * Skipdays feed element
  142. *
  143. * optional
  144. *
  145. * @var string
  146. * @access public
  147. */
  148. var $skipDays = "";
  149. /**
  150. * The feed items collection
  151. *
  152. * @var array
  153. * @access public
  154. */
  155. var $items = array();
  156. /**
  157. * Class constructor
  158. *
  159. * @access protected
  160. * @param array $options Associative array of options
  161. */
  162. function __construct($options = array())
  163. {
  164. parent::__construct($options);
  165. //set document type
  166. $this->_type = 'feed';
  167. }
  168. /**
  169. * Render the document
  170. *
  171. * @access public
  172. * @param boolean $cache If true, cache the output
  173. * @param array $params Associative array of attributes
  174. * @return The rendered data
  175. */
  176. function render( $cache = false, $params = array())
  177. {
  178. global $option;
  179. // Get the feed type
  180. $type = JRequest::getCmd('type', 'rss');
  181. /*
  182. * Cache TODO In later release
  183. */
  184. $cache = 0;
  185. $cache_time = 3600;
  186. $cache_path = JPATH_BASE.DS.'cache';
  187. // set filename for rss feeds
  188. $file = strtolower( str_replace( '.', '', $type ) );
  189. $file = $cache_path.DS.$file.'_'.$option.'.xml';
  190. // Instantiate feed renderer and set the mime encoding
  191. $renderer =& $this->loadRenderer(($type) ? $type : 'rss');
  192. if (!is_a($renderer, 'JDocumentRenderer')) {
  193. JError::raiseError(404, JText::_('Resource Not Found'));
  194. }
  195. $this->setMimeEncoding($renderer->getContentType());
  196. //output
  197. // Generate prolog
  198. $data = "<?xml version=\"1.0\" encoding=\"".$this->_charset."\"?>\n";
  199. $data .= "<!-- generator=\"".$this->getGenerator()."\" -->\n";
  200. // Generate stylesheet links
  201. foreach ($this->_styleSheets as $src => $attr ) {
  202. $data .= "<?xml-stylesheet href=\"$src\" type=\"".$attr['mime']."\"?>\n";
  203. }
  204. // Render the feed
  205. $data .= $renderer->render();
  206. parent::render();
  207. return $data;
  208. }
  209. /**
  210. * Adds an JFeedItem to the feed.
  211. *
  212. * @param object JFeedItem $item The feeditem to add to the feed.
  213. * @access public
  214. */
  215. function addItem( &$item )
  216. {
  217. $item->source = $this->link;
  218. $this->items[] = $item;
  219. }
  220. }
  221. /**
  222. * JFeedItem is an internal class that stores feed item information
  223. *
  224. * @package Joomla.Framework
  225. * @subpackage Document
  226. * @since 1.5
  227. */
  228. class JFeedItem extends JObject
  229. {
  230. /**
  231. * Title item element
  232. *
  233. * required
  234. *
  235. * @var string
  236. * @access public
  237. */
  238. var $title;
  239. /**
  240. * Link item element
  241. *
  242. * required
  243. *
  244. * @var string
  245. * @access public
  246. */
  247. var $link;
  248. /**
  249. * Description item element
  250. *
  251. * required
  252. *
  253. * @var string
  254. * @access public
  255. */
  256. var $description;
  257. /**
  258. * Author item element
  259. *
  260. * optional
  261. *
  262. * @var string
  263. * @access public
  264. */
  265. var $author;
  266. /**
  267. * Author email element
  268. *
  269. * optional
  270. *
  271. * @var string
  272. * @access public
  273. */
  274. var $authorEmail;
  275. /**
  276. * Category element
  277. *
  278. * optional
  279. *
  280. * @var string
  281. * @access public
  282. */
  283. var $category;
  284. /**
  285. * Comments element
  286. *
  287. * optional
  288. *
  289. * @var string
  290. * @access public
  291. */
  292. var $comments;
  293. /**
  294. * Enclosure element
  295. *
  296. * @var object
  297. * @access public
  298. */
  299. var $enclosure = null;
  300. /**
  301. * Guid element
  302. *
  303. * optional
  304. *
  305. * @var string
  306. * @access public
  307. */
  308. var $guid;
  309. /**
  310. * Published date
  311. *
  312. * optional
  313. *
  314. * May be in one of the following formats:
  315. *
  316. * RFC 822:
  317. * "Mon, 20 Jan 03 18:05:41 +0400"
  318. * "20 Jan 03 18:05:41 +0000"
  319. *
  320. * ISO 8601:
  321. * "2003-01-20T18:05:41+04:00"
  322. *
  323. * Unix:
  324. * 1043082341
  325. *
  326. * @var string
  327. * @access public
  328. */
  329. var $pubDate;
  330. /**
  331. * Source element
  332. *
  333. * optional
  334. *
  335. * @var string
  336. * @access public
  337. */
  338. var $source;
  339. /**
  340. * Set the JFeedEnclosure for this item
  341. *
  342. * @access public
  343. * @param object $enclosure The JFeedItem to add to the feed.
  344. */
  345. function setEnclosure($enclosure) {
  346. $this->enclosure = $enclosure;
  347. }
  348. }
  349. /**
  350. * JFeedEnclosure is an internal class that stores feed enclosure information
  351. *
  352. * @package Joomla.Framework
  353. * @subpackage Document
  354. * @since 1.5
  355. */
  356. class JFeedEnclosure extends JObject
  357. {
  358. /**
  359. * URL enclosure element
  360. *
  361. * required
  362. *
  363. * @var string
  364. * @access public
  365. */
  366. var $url = "";
  367. /**
  368. * Lenght enclosure element
  369. *
  370. * required
  371. *
  372. * @var string
  373. * @access public
  374. */
  375. var $length = "";
  376. /**
  377. * Type enclosure element
  378. *
  379. * required
  380. *
  381. * @var string
  382. * @access public
  383. */
  384. var $type = "";
  385. }
  386. /**
  387. * JFeedImage is an internal class that stores feed image information
  388. *
  389. * @package Joomla.Framework
  390. * @subpackage Document
  391. * @since 1.5
  392. */
  393. class JFeedImage extends JObject
  394. {
  395. /**
  396. * Title image attribute
  397. *
  398. * required
  399. *
  400. * @var string
  401. * @access public
  402. */
  403. var $title = "";
  404. /**
  405. * URL image attribute
  406. *
  407. * required
  408. *
  409. * @var string
  410. * @access public
  411. */
  412. var $url = "";
  413. /**
  414. * Link image attribute
  415. *
  416. * required
  417. *
  418. * @var string
  419. * @access public
  420. */
  421. var $link = "";
  422. /**
  423. * witdh image attribute
  424. *
  425. * optional
  426. *
  427. * @var string
  428. * @access public
  429. */
  430. var $width;
  431. /**
  432. * Title feed attribute
  433. *
  434. * optional
  435. *
  436. * @var string
  437. * @access public
  438. */
  439. var $height;
  440. /**
  441. * Title feed attribute
  442. *
  443. * optional
  444. *
  445. * @var string
  446. * @access public
  447. */
  448. var $description;
  449. }