.

RSSWriter Class Reference
[Feeds]

Build RSS file, targeted by FeedWriter class. More...

Inheritance diagram for RSSWriter:
FeedWriter IRenderer

List of all members.

Public Member Functions

  get_mime_type ()
  Return mime type of feed.

Protected Member Functions

  render_end ($title, $items)
  Render feed closing.
  render_item (FeedWriterItem $item)
  Render an item.
  render_title (FeedWriterTitle $title)
  Render feed title section.

Detailed Description

Build RSS file, targeted by FeedWriter class.

Author:
Gerd Riesselmann

Based upon http://www.gerd-riesselmann.net/archives/2005/05/a-braindead-simple-php-feed-writer-class but rewritten to fit Gyro style

Definition at line 29 of file rsswriter.cls.php.


Member Function Documentation

RSSWriter::get_mime_type (  ) 

Return mime type of feed.

Returns:
string

Reimplemented from FeedWriter.

Definition at line 35 of file rsswriter.cls.php.

00035                                         {
00036                 return 'application/rss+xml';
00037         }
RSSWriter::render_end ( title,
items  
) [protected]

Render feed closing.

Parameters:
string  $title
string  $items
Returns:
string

Reimplemented from FeedWriter.

Definition at line 142 of file rsswriter.cls.php.

00142                                                       {
00143                 $channel = html::tag('channel', $title . $items);
00144                 $rss = html::tag(
00145                         'rss',
00146                         $channel,
00147                         array(
00148                                 'version' => '2.0', 
00149                                 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/',
00150                                 'xmlns:wfw' => 'http://wellformedweb.org/CommentAPI/',
00151                                 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
00152                                 'xmlns:atom' => 'http://www.w3.org/2005/Atom'
00153                         )
00154                 );
00155                 
00156                 $ret = '<?xml version="1.0" encoding="' . GyroLocale::get_charset() . '"?>' . "\n" . $rss;
00157                 return $ret;
00158         }
RSSWriter::render_item ( FeedWriterItem item  )  [protected]

Render an item.

Parameters:
FeedWriterItem  $item
Returns:
string

Reimplemented from FeedWriter.

Definition at line 45 of file rsswriter.cls.php.

00045                                                              {
00046                 $tags = array();
00047                 if (empty($item->baseurl)) {
00048                         $item->baseurl = $item->link;
00049                 }
00050                 
00051                 // We misuse html class to generate tags :)
00052                 $tags[] = html::tag('title', $this->escape($item->title));
00053                 $tags[] = html::tag('link', $this->escape($item->link));
00054                 $tags[] = html::tag('description', $this->strip_html($item->description));
00055                 $tags[] = html::tag('pubDate', GyroDate::http_date($item->pubdate));
00056                 $tags[] = html::tag('guid', $this->escape($item->guid), array('isPermaLink' => 'true'));
00057                 if (!empty($item->author_email)) {
00058                         $tags[] = html::tag('author', $this->escape($item->author_email));
00059                 }
00060                 if (!empty($item->author_name)) {
00061                         $tags[] = html::tag('dc:creator', $this->escape($item->author_name));
00062                 }
00063                 
00064                 // HTML content
00065                 $content = $this->relative_to_absolute($item->content, $item->baseurl);
00066                 $content = '<![CDATA[' . $content . ']]>';
00067                 $tags[] = html::tag('content:encoded', $content);
00068                 
00069                 // Categories
00070                 foreach($item->categories as $cat) {
00071                         $tags[] = html::tag('category', $this->escape($cat->title), array('domain' => $cat->domain));
00072                 }
00073 
00074                 // Enclosures
00075                 foreach($item->enclosures as $enc) {
00076                         $tags[] = html::tag_selfclosing('enclosure', array(
00077                                 'url' => $enc->url,
00078                                 'length' => $enc->length,
00079                                 'type' => $enc->type
00080                         ));
00081                 }
00082                 
00083                 return html::tag('item', implode("\n", $tags));
00084         }
RSSWriter::render_title ( FeedWriterTitle title  )  [protected]

Render feed title section.

Parameters:
FeedWriterTitle  $title
Returns:
string

Reimplemented from FeedWriter.

Definition at line 92 of file rsswriter.cls.php.

00092                                                                 {
00093                 // We misuse html class to generate tags :)
00094                 $tags = array();
00095                 $tags[] = html::tag('title', $this->escape($title->title));
00096                 $tags[] = html::tag('link', $this->escape($title->link));
00097                 $tags[] = html::tag('description', $this->strip_html($title->description));
00098                 if ($title->last_updated) {
00099                         $tags[] = html::tag('pubDate', GyroDate::http_date($title->last_updated));
00100                 }
00101                 $tags[] = html::tag('language', $this->escape($title->language));
00102                 $tags[] = html::tag('generator', $this->escape($title->generator));
00103                 $tags[] = html::tag('copyright', $this->escape($title->copyright));
00104                 $tags[] = html::tag('managingEditor', $this->escape($title->editor));
00105                 
00106                 if (!empty($title->imageurl)) {
00107                         $image = '';
00108                         $image .= html::tag('title', $this->escape($title->title));
00109                         $image .= html::tag('link', $this->escape($title->link));
00110                         $image .= html::tag('url', $this->escape($title->imageurl));
00111                         if (!empty($title->image_width) && !empty($title->image_height)) {
00112                                 $image .= html::tag('width', Cast::int($title->image_width));
00113                                 $image .= html::tag('height', Cast::int($title->image_height));
00114                         }                       
00115                         
00116                         $tags[] = html::tag('image', $image);
00117                 }
00118 
00119                 // This is recommend
00120                 if ($title->selfurl) {
00121                         $tags[] = html::tag_selfclosing(
00122                                 'atom:link',
00123                                 array(
00124                                         'href' => $title->selfurl,
00125                                         'rel' => 'self',
00126                                         'type' => $this->get_mime_type()
00127                                 )
00128                         );
00129                 }
00130                 
00131                 $ret = implode("\n", $tags);
00132                 return $ret;
00133         }

The documentation for this class was generated from the following file: