4 * Copyright 2010 Sébastien Le Callonnec
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This class is a poor-man Atom parser, it does no validation of the feed.
24 * The content of an entry ("payload") is not parsed but rather returned "as-is",
25 * as its format can be text, html or xhtml.
27 * @author: Sébastien Le Callonnec
29 require_once('lib/XmlParser.php');
37 var $feed_links = array();
38 var $feed_subtitle = '';
40 var $feed_updated = '';
41 var $feed_authors = array();
42 var $feed_contributors = array();
48 var $categories = array();
50 var $authors = array();
51 var $contributors = array();
53 // Author, Contributor
59 var $entries = array();
60 var $inside_entry = false;
68 var $inside_content = false;
71 function tag_open($parser, $name, $attrs='') {
72 global $current_tag, $current_attrs;
75 $current_attrs = $attrs;
77 if ($name == "ENTRY") {
78 $this->inside_entry = true;
79 } elseif ($this->inside_content) {
80 $this->content .= $this->serialize_tag(strtolower($name), $attrs);
81 } elseif ($name == "CONTENT") {
82 $this->inside_content = true;
86 function tag_close($parser, $name, $attrs='') {
87 if ($name == "AUTHOR") {
88 $an_author = $this->trim_data(array(
89 "name" => $this->name,
90 "email" => $this->email,
93 if ($this->inside_entry) {
94 $this->authors[] = $an_author;
96 $this->feed_authors[] = $an_author;
101 } elseif ($name == "FEED") {
102 $this->feed[] = $this->trim_data(array(
103 "id" => $this->feed_id,
104 "title" => $this->feed_title,
105 "links" => $this->feed_links,
106 "subtitle" => $this->feed_subtitle,
107 "updated" => $this->feed_updated,
108 "generator" => $this->generator,
109 "icon" => $this->icon,
110 "rights" => $this->rights,
111 "logo" => $this->logo,
112 "authors" => $this->feed_authors,
113 "contributors" => $this->feed_contributors
115 $this->feed_title = '';
117 $this->feed_links = array();
118 $this->feed_subtitle = '';
119 $this->feed_updated = '';
120 $this->feed_authors = array();
121 $this->feed_contributors = array();
122 $this->generator = '';
126 } elseif ($name == "ENTRY") {
127 $this->entries[] = $this->trim_data(array(
129 "title" => $this->title,
130 "updated" => $this->updated,
131 "links" => $this->links,
132 "published" => $this->published,
133 "content" => $this->content,
134 "summary" => $this->summary,
135 "authors" => $this->authors,
136 "contributors" => $this->contributors
142 $this->published = '';
144 $this->authors = array();
145 $this->contributors = array();
146 $this->inside_entry = false;
147 } elseif ($name == "CONTENT") {
148 $this->inside_content = false;
149 } elseif ($name == "CONTRIBUTOR") {
150 $a_contributor = $this->trim_data(array(
151 "name" => $this->name,
152 "email" => $this->email
154 if ($this->inside_entry) {
155 $this->contributors[] = $a_contributor;
157 $this->feed_contributors[] = $a_contributor;
161 } elseif ($this->inside_content) {
162 $this->content .= "</" . strtolower($name) . ">";
166 function cdata($parser, $data) {
167 global $current_tag, $current_attrs;
169 if ($this->inside_content) {
170 $this->content .= $data;
172 switch ($current_tag) {
174 if ($this->inside_entry)
177 $this->feed_id .= $data;
181 foreach ($current_attrs as $k => $v) {
182 $a_link[strtolower($k)] = $v;
184 if ($this->inside_entry) {
185 $this->links[] = $a_link;
187 $this->feed_links[] = $a_link;
191 $this->name .= $data;
194 $this->email .= $data;
197 if ($this->inside_entry)
198 $this->title .= $data;
200 $this->feed_title .= $data;
203 if ($this->inside_entry)
204 $this->updated .= $data;
206 $this->feed_updated .= $data;
209 $this->feed_subtitle .= $data;
212 $this->published .= $data;
215 $this->summary .= $data;
221 $this->generator .= $data;
224 $this->icon .= $data;
227 $this->logo .= $data;
230 $this->rights .= $data;
236 function trim_data($array) {
237 return array_map(array("self", "trim_element"), $array);
240 function trim_element($element) {
241 if (is_array($element)) {
242 return $this->trim_data($element);
243 } elseif (is_string($element)) {
244 return trim($element);
248 function serialize_tag($tag_name, $attributes) {
249 $tag = "<" . $tag_name;
250 foreach ($attributes as $k => $v) {
251 $tag .= " " . strtolower($k). "=\"$v\"";