Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Source code for file /joomla/document/feed/renderer/rss.php

Documentation is available at rss.php

  1. <?php
  2. /**
  3.  * @version        $Id: rss.php 9919 2008-01-10 18:31:25Z willebil $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Document
  6.  * @copyright    Copyright (C) 2005 - 2008 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.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. jimport'joomla.utilities.date' );
  19.  
  20.  /**
  21.  * JDocumentRenderer_RSS is a feed that implements RSS 2.0 Specification
  22.  *
  23.  * @author    Johan Janssens <johan.janssens@joomla.org>
  24.  *
  25.  * @package     Joomla.Framework
  26.  * @subpackage        Document
  27.  * @see http://www.rssboard.org/rss-specification
  28.  * @since    1.5
  29.  */
  30.  
  31. {
  32.     /**
  33.      * Renderer mime type
  34.      *
  35.      * @var        string 
  36.      * @access    private
  37.      */
  38.     var $_mime "application/rss+xml";
  39.  
  40.     /**
  41.      * Render the feed
  42.      *
  43.      * @access public
  44.      * @return    string 
  45.      */
  46.     function render()
  47.     {
  48.         $now    new JDate();
  49.         $data    =$this->_doc;
  50.  
  51.         $uri =JFactory::getURI();
  52.         $url $uri->toString(array('scheme''user''pass''host''port'));
  53.  
  54.         $feed "<rss version=\"2.0\">\n";
  55.         $feed.= "    <channel>\n";
  56.         $feed.= "        <title>".$data->title."</title>\n";
  57.         $feed.= "        <description>".$data->description."</description>\n";
  58.         $feed.= "        <link>".$url.$data->link."</link>\n";
  59.         $feed.= "        <lastBuildDate>".htmlspecialchars($now->toRFC822()ENT_COMPAT'UTF-8')."</lastBuildDate>\n";
  60.         $feed.= "        <generator>".$data->getGenerator()."</generator>\n";
  61.  
  62.         if ($data->image!=null)
  63.         {
  64.             $feed.= "        <image>\n";
  65.             $feed.= "            <url>".$data->image->url."</url>\n";
  66.             $feed.= "            <title>".htmlspecialchars($data->image->titleENT_COMPAT'UTF-8')."</title>\n";
  67.             $feed.= "            <link>".$data->image->link."</link>\n";
  68.             if ($data->image->width != ""{
  69.                 $feed.= "            <width>".$data->image->width."</width>\n";
  70.             }
  71.             if ($data->image->height!=""{
  72.                 $feed.= "            <height>".$data->image->height."</height>\n";
  73.             }
  74.             if ($data->image->description!=""{
  75.                 $feed.= "            <description><![CDATA[".$data->image->description."]]></description>\n";
  76.             }
  77.             $feed.= "        </image>\n";
  78.         }
  79.         if ($data->language!=""{
  80.             $feed.= "        <language>".$data->language."</language>\n";
  81.         }
  82.         if ($data->copyright!=""{
  83.             $feed.= "        <copyright>".htmlspecialchars($data->copyright,ENT_COMPAT'UTF-8')."</copyright>\n";
  84.         }
  85.         if ($data->editor!=""{
  86.             $feed.= "        <managingEditor>".htmlspecialchars($data->editorENT_COMPAT'UTF-8')."</managingEditor>\n";
  87.         }
  88.         if ($data->webmaster!=""{
  89.             $feed.= "        <webMaster>".htmlspecialchars($data->webmasterENT_COMPAT'UTF-8')."</webMaster>\n";
  90.         }
  91.         if ($data->pubDate!=""{
  92.             $pubDate new JDate($data->pubDate);
  93.             $feed.= "        <pubDate>".htmlspecialchars($pubDate->toRFC822(),ENT_COMPAT'UTF-8')."</pubDate>\n";
  94.         }
  95.         if ($data->category!=""{
  96.             $feed.= "        <category>".htmlspecialchars($data->categoryENT_COMPAT'UTF-8')."</category>\n";
  97.         }
  98.         if ($data->docs!=""{
  99.             $feed.= "        <docs>".htmlspecialchars($data->docsENT_COMPAT'UTF-8')."</docs>\n";
  100.         }
  101.         if ($data->ttl!=""{
  102.             $feed.= "        <ttl>".htmlspecialchars($data->ttlENT_COMPAT'UTF-8')."</ttl>\n";
  103.         }
  104.         if ($data->rating!=""{
  105.             $feed.= "        <rating>".htmlspecialchars($data->ratingENT_COMPAT'UTF-8')."</rating>\n";
  106.         }
  107.         if ($data->skipHours!=""{
  108.             $feed.= "        <skipHours>".htmlspecialchars($data->skipHoursENT_COMPAT'UTF-8')."</skipHours>\n";
  109.         }
  110.         if ($data->skipDays!=""{
  111.             $feed.= "        <skipDays>".htmlspecialchars($data->skipDaysENT_COMPAT'UTF-8')."</skipDays>\n";
  112.         }
  113.  
  114.         for ($i=0$i<count($data->items)$i++)
  115.         {
  116.             $feed.= "        <item>\n";
  117.             $feed.= "            <title>".htmlspecialchars(strip_tags($data->items[$i]->title)ENT_COMPAT'UTF-8')."</title>\n";
  118.             $feed.= "            <link>".$url.$data->items[$i]->link."</link>\n";
  119.             $feed.= "            <description><![CDATA[".$this->_relToAbs($data->items[$i]->description)."]]></description>\n";
  120.  
  121.             if ($data->items[$i]->author!=""{
  122.                 $feed.= "            <author>".htmlspecialchars($data->items[$i]->authorENT_COMPAT'UTF-8')."</author>\n";
  123.             }
  124.             /*
  125.             // on hold
  126.             if ($data->items[$i]->source!="") {
  127.                     $data.= "            <source>".htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8')."</source>\n";
  128.             }
  129.             */
  130.             if ($data->items[$i]->category!=""{
  131.                 $feed.= "            <category>".htmlspecialchars($data->items[$i]->categoryENT_COMPAT'UTF-8')."</category>\n";
  132.             }
  133.             if ($data->items[$i]->comments!=""{
  134.                 $feed.= "            <comments>".htmlspecialchars($data->items[$i]->commentsENT_COMPAT'UTF-8')."</comments>\n";
  135.             }
  136.             if ($data->items[$i]->date!=""{
  137.             $itemDate new JDate($data->items[$i]->date);
  138.                 $feed.= "            <pubDate>".htmlspecialchars($itemDate->toRFC822()ENT_COMPAT'UTF-8')."</pubDate>\n";
  139.             }
  140.             if ($data->items[$i]->guid!=""{
  141.                 $feed.= "            <guid>".htmlspecialchars($data->items[$i]->guidENT_COMPAT'UTF-8')."</guid>\n";
  142.             }
  143.             if ($data->items[$i]->enclosure != NULL)
  144.             {
  145.                     $feed.= "            <enclosure url=\"";
  146.                     $feed.= $data->items[$i]->enclosure->url;
  147.                     $feed.= "\" length=\"";
  148.                     $feed.= $data->items[$i]->enclosure->length;
  149.                     $feed.= "\" type=\"";
  150.                     $feed.= $data->items[$i]->enclosure->type;
  151.                     $feed.= "\"/>\n";
  152.             }
  153.  
  154.             $feed.= "        </item>\n";
  155.         }
  156.         $feed.= "    </channel>\n";
  157.         $feed.= "</rss>\n";
  158.         return $feed;
  159.     }
  160.  
  161.     /**
  162.      * Convert links in a text from relative to absolute
  163.      *
  164.      * @access public
  165.      * @return    string 
  166.      */
  167.     function _relToAbs($text)
  168.     {
  169.         $base JURI::base();
  170.           $text preg_replace("/(href|src)=\"(?!http|ftp|https)([^\"]*)\"/""$1=\"$base\$2\""$text);
  171.  
  172.         return $text;
  173.     }
  174. }

Documentation generated on Tue, 29 Jan 2008 18:50:14 +0000 by phpDocumentor 1.3.1