Source for file rss.php

Documentation is available at rss.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.  * JDocumentRenderer_RSS is a feed that implements RSS 2.0 Specification
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Document
  17.  * @see         http://www.rssboard.org/rss-specification
  18.  * @since       11.1
  19.  */
  20. {
  21.     /**
  22.      * Renderer mime type
  23.      *
  24.      * @var    string 
  25.      * @since  11.1
  26.      */
  27.     protected $_mime = "application/rss+xml";
  28.  
  29.     /**
  30.      * Render the feed.
  31.      *
  32.      * @param   string  $name     The name of the element to render
  33.      * @param   array   $params   Array of values
  34.      * @param   string  $content  Override the output of the renderer
  35.      *
  36.      * @return  string  The output of the script
  37.      *
  38.      * @see JDocumentRenderer::render()
  39.      * @since   11.1
  40.      */
  41.     public function render($name ''$params null$content null)
  42.     {
  43.         $app JFactory::getApplication();
  44.  
  45.         // Gets and sets timezone offset from site configuration
  46.         $tz new DateTimeZone($app->getCfg('offset'));
  47.         $now JFactory::getDate();
  48.         $now->setTimeZone($tz);
  49.  
  50.         $data $this->_doc;
  51.  
  52.         $uri JUri::getInstance();
  53.         $url $uri->toString(array('scheme''user''pass''host''port'));
  54.         $syndicationURL JRoute::_('&format=feed&type=rss');
  55.  
  56.         if ($app->getCfg('sitename_pagetitles'0== 1)
  57.         {
  58.             $title JText::sprintf('JPAGETITLE'$app->getCfg('sitename')$data->title);
  59.         }
  60.         elseif ($app->getCfg('sitename_pagetitles'0== 2)
  61.         {
  62.             $title JText::sprintf('JPAGETITLE'$data->title$app->getCfg('sitename'));
  63.         }
  64.         else
  65.         {
  66.             $title $data->title;
  67.         }
  68.  
  69.         $feed_title htmlspecialchars($titleENT_COMPAT'UTF-8');
  70.  
  71.         $feed "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
  72.         $feed .= "    <channel>\n";
  73.         $feed .= "        <title>" $feed_title "</title>\n";
  74.         $feed .= "        <description><![CDATA[" $data->description "]]></description>\n";
  75.         $feed .= "        <link>" str_replace(' ''%20'$url $data->link"</link>\n";
  76.         $feed .= "        <lastBuildDate>" htmlspecialchars($now->toRFC822(true)ENT_COMPAT'UTF-8'"</lastBuildDate>\n";
  77.         $feed .= "        <generator>" $data->getGenerator("</generator>\n";
  78.         $feed .= '        <atom:link rel="self" type="application/rss+xml" href="' str_replace(' ''%20'$url $syndicationURL"\"/>\n";
  79.  
  80.         if ($data->image != null)
  81.         {
  82.             $feed .= "        <image>\n";
  83.             $feed .= "            <url>" $data->image->url "</url>\n";
  84.             $feed .= "            <title>" htmlspecialchars($data->image->titleENT_COMPAT'UTF-8'"</title>\n";
  85.             $feed .= "            <link>" str_replace(' ''%20'$data->image->link"</link>\n";
  86.             if ($data->image->width != "")
  87.             {
  88.                 $feed .= "            <width>" $data->image->width "</width>\n";
  89.             }
  90.             if ($data->image->height != "")
  91.             {
  92.                 $feed .= "            <height>" $data->image->height "</height>\n";
  93.             }
  94.             if ($data->image->description != "")
  95.             {
  96.                 $feed .= "            <description><![CDATA[" $data->image->description "]]></description>\n";
  97.             }
  98.             $feed .= "        </image>\n";
  99.         }
  100.         if ($data->language != "")
  101.         {
  102.             $feed .= "        <language>" $data->language "</language>\n";
  103.         }
  104.         if ($data->copyright != "")
  105.         {
  106.             $feed .= "        <copyright>" htmlspecialchars($data->copyrightENT_COMPAT'UTF-8'"</copyright>\n";
  107.         }
  108.         if ($data->editorEmail != "")
  109.         {
  110.             $feed .= "        <managingEditor>" htmlspecialchars($data->editorEmailENT_COMPAT'UTF-8'' ('
  111.                 . htmlspecialchars($data->editorENT_COMPAT'UTF-8'")</managingEditor>\n";
  112.         }
  113.         if ($data->webmaster != "")
  114.         {
  115.             $feed .= "        <webMaster>" htmlspecialchars($data->webmasterENT_COMPAT'UTF-8'"</webMaster>\n";
  116.         }
  117.         if ($data->pubDate != "")
  118.         {
  119.             $pubDate JFactory::getDate($data->pubDate);
  120.             $pubDate->setTimeZone($tz);
  121.             $feed .= "        <pubDate>" htmlspecialchars($pubDate->toRFC822(true)ENT_COMPAT'UTF-8'"</pubDate>\n";
  122.         }
  123.         if (empty($data->category=== false)
  124.         {
  125.             if (is_array($data->category))
  126.             {
  127.                 foreach ($data->category as $cat)
  128.                 {
  129.                     $feed .= "        <category>" htmlspecialchars($catENT_COMPAT'UTF-8'"</category>\n";
  130.                 }
  131.             }
  132.             else
  133.             {
  134.                 $feed .= "        <category>" htmlspecialchars($data->categoryENT_COMPAT'UTF-8'"</category>\n";
  135.             }
  136.         }
  137.         if ($data->docs != "")
  138.         {
  139.             $feed .= "        <docs>" htmlspecialchars($data->docsENT_COMPAT'UTF-8'"</docs>\n";
  140.         }
  141.         if ($data->ttl != "")
  142.         {
  143.             $feed .= "        <ttl>" htmlspecialchars($data->ttlENT_COMPAT'UTF-8'"</ttl>\n";
  144.         }
  145.         if ($data->rating != "")
  146.         {
  147.             $feed .= "        <rating>" htmlspecialchars($data->ratingENT_COMPAT'UTF-8'"</rating>\n";
  148.         }
  149.         if ($data->skipHours != "")
  150.         {
  151.             $feed .= "        <skipHours>" htmlspecialchars($data->skipHoursENT_COMPAT'UTF-8'"</skipHours>\n";
  152.         }
  153.         if ($data->skipDays != "")
  154.         {
  155.             $feed .= "        <skipDays>" htmlspecialchars($data->skipDaysENT_COMPAT'UTF-8'"</skipDays>\n";
  156.         }
  157.  
  158.         for ($i 0$count count($data->items)$i $count$i++)
  159.         {
  160.             if ((strpos($data->items[$i]->link'http://'=== false&& (strpos($data->items[$i]->link'https://'=== false))
  161.             {
  162.                 $data->items[$i]->link str_replace(' ''%20'$url $data->items[$i]->link);
  163.             }
  164.             $feed .= "        <item>\n";
  165.             $feed .= "            <title>" htmlspecialchars(strip_tags($data->items[$i]->title)ENT_COMPAT'UTF-8'"</title>\n";
  166.             $feed .= "            <link>" str_replace(' ''%20'$data->items[$i]->link"</link>\n";
  167.  
  168.             if (empty($data->items[$i]->guid=== true)
  169.             {
  170.                 $feed .= "            <guid isPermaLink=\"true\">" str_replace(' ''%20'$data->items[$i]->link"</guid>\n";
  171.             }
  172.             else
  173.             {
  174.                 $feed .= "            <guid isPermaLink=\"false\">" htmlspecialchars($data->items[$i]->guidENT_COMPAT'UTF-8'"</guid>\n";
  175.             }
  176.  
  177.             $feed .= "            <description><![CDATA[" $this->_relToAbs($data->items[$i]->description"]]></description>\n";
  178.  
  179.             if ($data->items[$i]->authorEmail != "")
  180.             {
  181.                 $feed .= "            <author>"
  182.                     . htmlspecialchars($data->items[$i]->authorEmail ' (' $data->items[$i]->author ')'ENT_COMPAT'UTF-8'"</author>\n";
  183.             }
  184.  
  185.             /*
  186.              * @todo: On hold
  187.              * if ($data->items[$i]->source!="") {
  188.              *   $data.= "            <source>".htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8')."</source>\n";
  189.              * }
  190.              */
  191.  
  192.             if (empty($data->items[$i]->category=== false)
  193.             {
  194.                 if (is_array($data->items[$i]->category))
  195.                 {
  196.                     foreach ($data->items[$i]->category as $cat)
  197.                     {
  198.                         $feed .= "            <category>" htmlspecialchars($catENT_COMPAT'UTF-8'"</category>\n";
  199.                     }
  200.                 }
  201.                 else
  202.                 {
  203.                     $feed .= "            <category>" htmlspecialchars($data->items[$i]->categoryENT_COMPAT'UTF-8'"</category>\n";
  204.                 }
  205.             }
  206.             if ($data->items[$i]->comments != "")
  207.             {
  208.                 $feed .= "            <comments>" htmlspecialchars($data->items[$i]->commentsENT_COMPAT'UTF-8'"</comments>\n";
  209.             }
  210.             if ($data->items[$i]->date != "")
  211.             {
  212.                 $itemDate JFactory::getDate($data->items[$i]->date);
  213.                 $itemDate->setTimeZone($tz);
  214.                 $feed .= "            <pubDate>" htmlspecialchars($itemDate->toRFC822(true)ENT_COMPAT'UTF-8'"</pubDate>\n";
  215.             }
  216.             if ($data->items[$i]->enclosure != null)
  217.             {
  218.                 $feed .= "            <enclosure url=\"";
  219.                 $feed .= $data->items[$i]->enclosure->url;
  220.                 $feed .= "\" length=\"";
  221.                 $feed .= $data->items[$i]->enclosure->length;
  222.                 $feed .= "\" type=\"";
  223.                 $feed .= $data->items[$i]->enclosure->type;
  224.                 $feed .= "\"/>\n";
  225.             }
  226.  
  227.             $feed .= "        </item>\n";
  228.         }
  229.         $feed .= "    </channel>\n";
  230.         $feed .= "</rss>\n";
  231.         return $feed;
  232.     }
  233.  
  234.     /**
  235.      * Convert links in a text from relative to absolute
  236.      *
  237.      * @param   string  $text  The text processed
  238.      *
  239.      * @return  string   Text with converted links
  240.      *
  241.      * @since   11.1
  242.      */
  243.     public function _relToAbs($text)
  244.     {
  245.         $base JUri::base();
  246.         $text preg_replace("/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/""$1=\"$base\$2\""$text);
  247.  
  248.         return $text;
  249.     }
  250. }

Documentation generated on Tue, 19 Nov 2013 15:12:30 +0100 by phpDocumentor 1.4.3