Source for file feed.php

Documentation is available at feed.php

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

Documentation generated on Tue, 19 Nov 2013 15:02:55 +0100 by phpDocumentor 1.4.3