Actions

API15

JDocumentRendererRSS/render

From Joomla! Documentation

< API15:JDocumentRendererRSS
Revision as of 16:18, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Render the feed

[Edit Descripton]

Description:JDocumentRendererRSS/render

Syntax

render()


Returns

string

Defined in

libraries/joomla/document/feed/renderer/rss.php

Importing

jimport( 'joomla.document.feed.renderer.rss' );

Source Body

function render()
{
        $now    =& JFactory::getDate();
        $data   =& $this->_doc;
 
        $uri =& JFactory::getURI();
        $url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
        $syndicationURL =& JRoute::_('&format=feed&type=rss');
 
        $feed = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
        $feed.= "       <channel>\n";
        $feed.= "               <title>".$data->title."</title>\n";
        $feed.= "               <description>".htmlspecialchars($data->description)."</description>\n";
        $feed.= "               <link>".str_replace(' ','%20',$url.$data->link)."</link>\n";
        $feed.= "               <lastBuildDate>".htmlspecialchars($now->toRFC822(), ENT_COMPAT, 'UTF-8')."</lastBuildDate>\n";
        $feed.= "               <generator>".$data->getGenerator()."</generator>\n";
 
        if ($data->image!=null)
        {
                $feed.= "               <image>\n";
                $feed.= "                       <url>".$data->image->url."</url>\n";
                $feed.= "                       <title>".htmlspecialchars($data->image->title, ENT_COMPAT, 'UTF-8')."</title>\n";
                $feed.= "                       <link>".str_replace(' ','%20',$data->image->link)."</link>\n";
                if ($data->image->width != "") {
                        $feed.= "                       <width>".$data->image->width."</width>\n";
                }
                if ($data->image->height!="") {
                        $feed.= "                       <height>".$data->image->height."</height>\n";
                }
                if ($data->image->description!="") {
                        $feed.= "                       <description><![CDATA[".$data->image->description."]]></description>\n";
                }
                $feed.= "               </image>\n";
        }
        if ($data->language!="") {
                $feed.= "               <language>".$data->language."</language>\n";
        }
        if ($data->copyright!="") {
                $feed.= "               <copyright>".htmlspecialchars($data->copyright,ENT_COMPAT, 'UTF-8')."</copyright>\n";
        }
        if ($data->editorEmail!="") {
                $feed.= "               <managingEditor>".htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8').' ('.
                        htmlspecialchars($data->editor, ENT_COMPAT, 'UTF-8').")</managingEditor>\n";
        }
        if ($data->webmaster!="") {
                $feed.= "               <webMaster>".htmlspecialchars($data->webmaster, ENT_COMPAT, 'UTF-8')."</webMaster>\n";
        }
        if ($data->pubDate!="") {
                $pubDate =& JFactory::getDate($data->pubDate);
                $feed.= "               <pubDate>".htmlspecialchars($pubDate->toRFC822(),ENT_COMPAT, 'UTF-8')."</pubDate>\n";
        }
        if ($data->category!="") {
                $feed.= "               <category>".htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8')."</category>\n";
        }
        if ($data->docs!="") {
                $feed.= "               <docs>".htmlspecialchars($data->docs, ENT_COMPAT, 'UTF-8')."</docs>\n";
        }
        if ($data->ttl!="") {
                $feed.= "               <ttl>".htmlspecialchars($data->ttl, ENT_COMPAT, 'UTF-8')."</ttl>\n";
        }
        if ($data->rating!="") {
                $feed.= "               <rating>".htmlspecialchars($data->rating, ENT_COMPAT, 'UTF-8')."</rating>\n";
        }
        if ($data->skipHours!="") {
                $feed.= "               <skipHours>".htmlspecialchars($data->skipHours, ENT_COMPAT, 'UTF-8')."</skipHours>\n";
        }
        if ($data->skipDays!="") {
                $feed.= "               <skipDays>".htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8')."</skipDays>\n";
        }
 
        for ($i=0; $i<count($data->items); $i++)
        {
                if ((strpos($data->items[$i]->link, 'http://') === false) and (strpos($data->items[$i]->link, 'https://') === false)) {
                        $data->items[$i]->link = str_replace(' ','%20',$url.$data->items[$i]->link);
                }
                $feed.= "               <item>\n";
                $feed.= "                       <title>".htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8')."</title>\n";
                $feed.= "                       <link>".str_replace(' ','%20',$data->items[$i]->link)."</link>\n";
                $feed.= "                       <guid>".str_replace(' ','%20',$data->items[$i]->link)."</guid>\n";
                $feed.= "                       <description><![CDATA[".$this->_relToAbs($data->items[$i]->description)."]]></description>\n";
 
                if ($data->items[$i]->authorEmail!="") {
                        $feed.= "                       <author>".htmlspecialchars($data->items[$i]->authorEmail . ' (' . 
                                                                        $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8')."</author>\n";
                }
                /*
                // on hold
                if ($data->items[$i]->source!="") {
                                $data.= "                       <source>".htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8')."

\n";

               }
               */
               if ($data->items[$i]->category!="") {
                       $feed.= "                       <category>".htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8')."</category>\n";
               }
               if ($data->items[$i]->comments!="") {
                       $feed.= "                       <comments>".htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8')."</comments>\n";
               }
               if ($data->items[$i]->date!="") {
               $itemDate =& JFactory::getDate($data->items[$i]->date);
                       $feed.= "                       <pubDate>".htmlspecialchars($itemDate->toRFC822(), ENT_COMPAT, 'UTF-8')."</pubDate>\n";
               }
               if ($data->items[$i]->guid!="") {
                       $feed.= "                       <guid>".htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8')."</guid>\n";
               }
               if ($data->items[$i]->enclosure != NULL)
               {
                               $feed.= "                       <enclosure url=\"";
                               $feed.= $data->items[$i]->enclosure->url;
                               $feed.= "\" length=\"";
                               $feed.= $data->items[$i]->enclosure->length;
                               $feed.= "\" type=\"";
                               $feed.= $data->items[$i]->enclosure->type;
                               $feed.= "\"/>\n";
               }
               $feed.= "               </item>\n";
       }
       $feed.= "       </channel>\n";
       $feed.= "</rss>\n";
       return $feed;

} </source>

[Edit See Also] SeeAlso:JDocumentRendererRSS/render

Examples

<CodeExamplesForm />