PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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

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