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 AtomWriter extends FeedWriter {
00030
00031
00032
00033
00034
00035 private $last_mod_date = 0;
00036
00037
00038
00039
00040
00041
00042 public function get_mime_type() {
00043 return 'application/atom+xml';
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 protected function render_item(FeedWriterItem $item) {
00053 $tags = array();
00054
00055
00056 $tags[] = html::tag('title', $this->escape($item->title));
00057 $tags[] = html::tag_selfclosing('link', array('href' => $item->link));
00058 $tags[] = html::tag('id', $this->escape($item->guid));
00059 $tags[] = html::tag('summary', $this->strip_html($item->description));
00060
00061 $updated = $item->last_update ? $item->last_update : $item->pubdate;
00062 $tags[] = html::tag('updated', GyroDate::iso_date($updated));
00063 $tags[] = html::tag('published', GyroDate::iso_date($item->pubdate));
00064 if ($updated > $this->last_mod_date) {
00065 $this->last_mod_date = $updated;
00066 }
00067
00068
00069 $author_tags = array();
00070 if ($item->author_name) {
00071 $author_tags[] = html::tag('name', $this->escape($item->author_name));
00072 }
00073 if ($item->author_email) {
00074 $author_tags[] = html::tag('email', $this->escape($item->author_email));
00075 }
00076 if (count($author_tags)) {
00077 $tags[] = html::tag('author', implode("\n", $author_tags));
00078 }
00079
00080
00081 $content = $this->relative_to_absolute($item->content, $item->baseurl);
00082 $content = String::escape($content, String::XML);
00083 $tags[] = html::tag('content', $content, array('type' => 'html'));
00084
00085
00086 foreach($item->categories as $cat) {
00087 $tags[] = html::tag_selfclosing('category', array('scheme' => $cat->domain, 'term' => $cat->title));
00088 }
00089
00090
00091 foreach($item->enclosures as $enc) {
00092 $tags[] = html::tag_selfclosing('content', array('type' => $enc->type, 'src' => $enc->url));
00093 }
00094
00095 return html::tag('entry', implode("\n", $tags));
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 protected function render_title(FeedWriterTitle $title) {
00105
00106 $tags = array();
00107 $tags[] = html::tag('title', $this->escape($title->title));
00108 $tags[] = html::tag('subtitle', $this->strip_html($title->description));
00109 $tags[] = html::tag('id', $this->escape($title->link));
00110 $tags[] = html::tag_selfclosing('link', array('rel' => 'alternate', 'type' => 'text/html', 'href' => $title->link));
00111
00112 if ($title->selfurl) {
00113 $tags[] = html::tag_selfclosing('link', array('href' => $title->selfurl, 'rel' => 'self', 'type' => $this->get_mime_type()));
00114 }
00115
00116 if ($title->last_updated) {
00117 $tags[] = html::tag('updated', GyroDate::iso_date($title->last_updated));
00118 }
00119 else {
00120 $tags[] = html::tag('updated', GyroDate::iso_date($this->last_mod_date));
00121 }
00122
00123 $tags[] = html::tag('generator', $this->escape($title->generator));
00124 $tags[] = html::tag('rights', $this->escape('Copyright ' . $title->copyright));
00125 $tags[] = html::tag('author', html::tag('name', $this->escape($title->editor)));
00126
00127 if (!empty($title->imageurl)) {
00128 $tags[] = html::tag('logo', $this->escape($title->imageurl));
00129 }
00130
00131 $ret = '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="' . $this->escape($title->language) . '">';
00132 $ret .= "\n";
00133 $ret .= implode("\n", $tags);
00134 return $ret;
00135
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 protected function render_end($title, $items) {
00146 $ret = '<?xml version="1.0" encoding="' . GyroLocale::get_charset() . '"?>';
00147 $ret .= "\n";
00148 $ret .= $title;
00149 $ret .= "\n";
00150 $ret .= $items;
00151 $ret .= "\n";
00152 $ret .= '</feed>';
00153 return $ret;
00154 }
00155 }