AtomWriter Class Reference
[Feeds]
Build Atom file, targeted by FeedWriter class. More...
Inheritance diagram for AtomWriter:
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 Atom file, targeted by FeedWriter class.
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 atomwriter.cls.php.
Member Function Documentation
AtomWriter::get_mime_type | ( | ) |
Return mime type of feed.
- Returns:
- string
Reimplemented from FeedWriter.
Definition at line 42 of file atomwriter.cls.php.
AtomWriter::render_end | ( | $ | title, | |
$ | items | |||
) | [protected] |
Render feed closing.
- Parameters:
-
string $title string $items
- Returns:
- string
Reimplemented from FeedWriter.
Definition at line 145 of file atomwriter.cls.php.
00145 { 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 }
AtomWriter::render_item | ( | FeedWriterItem $ | item | ) | [protected] |
Render an item.
- Parameters:
-
FeedWriterItem $item
- Returns:
- string
Reimplemented from FeedWriter.
Definition at line 52 of file atomwriter.cls.php.
00052 { 00053 $tags = array(); 00054 00055 // We misuse html class to generate tags :) 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 // Author 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 // HTML content 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 // Categories 00086 foreach($item->categories as $cat) { 00087 $tags[] = html::tag_selfclosing('category', array('scheme' => $cat->domain, 'term' => $cat->title)); 00088 } 00089 00090 // Enclosures 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 }
AtomWriter::render_title | ( | FeedWriterTitle $ | title | ) | [protected] |
Render feed title section.
- Parameters:
-
FeedWriterTitle $title
- Returns:
- string
Reimplemented from FeedWriter.
Definition at line 104 of file atomwriter.cls.php.
00104 { 00105 // We misuse html class to generate tags :) 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 // This is recommend 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 }
The documentation for this class was generated from the following file:
- contributions/feeds/lib/components/atomwriter.cls.php