PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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