00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 require_once dirname(__FILE__) . "/feedwriter/feedwriter.cls.php";
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class RSSWriter extends FeedWriter {
00030
00031
00032
00033
00034
00035 public function get_mime_type() {
00036 return 'application/rss+xml';
00037 }
00038
00039
00040
00041
00042
00043
00044
00045 protected function render_item(FeedWriterItem $item) {
00046 $tags = array();
00047 if (empty($item->baseurl)) {
00048 $item->baseurl = $item->link;
00049 }
00050
00051
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
00065 $content = $this->relative_to_absolute($item->content, $item->baseurl);
00066 $content = '<![CDATA[' . $content . ']]>';
00067 $tags[] = html::tag('content:encoded', $content);
00068
00069
00070 foreach($item->categories as $cat) {
00071 $tags[] = html::tag('category', $this->escape($cat->title), array('domain' => $cat->domain));
00072 }
00073
00074
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 }
00085
00086
00087
00088
00089
00090
00091
00092 protected function render_title(FeedWriterTitle $title) {
00093
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
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 }
00134
00135
00136
00137
00138
00139
00140
00141
00142 protected function render_end($title, $items) {
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 }
00159 }