3 * Copyright 2010 Sébastien Le Callonnec
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * This class is a poor-man Atom parser, it does no validation of the feed.
23 * The content of an entry ("payload") is not parsed but rather returned "as-is",
24 * as its format can be text, html or xhtml.
26 * @author: Sébastien Le Callonnec
28 require_once 'lib/XmlParser.php';
34 public $feed = array();
35 public $feed_title = '';
36 public $feed_links = array();
37 public $feed_subtitle = '';
39 public $feed_updated = '';
40 public $feed_authors = array();
41 public $feed_contributors = array();
42 public $generator = '';
47 public $categories = array();
49 public $authors = array();
50 public $contributors = array();
52 // Author, Contributor
58 public $entries = array();
59 public $inside_entry = false;
62 public $published = '';
64 public $links = array();
67 public $inside_content = false;
70 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 = '')
88 if ($name == "AUTHOR") {
89 $an_author = $this->trim_data(array(
90 "name" => $this->name,
91 "email" => $this->email,
94 if ($this->inside_entry) {
95 $this->authors[] = $an_author;
97 $this->feed_authors[] = $an_author;
102 } elseif ($name == "FEED") {
103 $this->feed[] = $this->trim_data(array(
104 "id" => $this->feed_id,
105 "title" => $this->feed_title,
106 "links" => $this->feed_links,
107 "subtitle" => $this->feed_subtitle,
108 "updated" => $this->feed_updated,
109 "generator" => $this->generator,
110 "icon" => $this->icon,
111 "rights" => $this->rights,
112 "logo" => $this->logo,
113 "authors" => $this->feed_authors,
114 "contributors" => $this->feed_contributors
116 $this->feed_title = '';
118 $this->feed_links = array();
119 $this->feed_subtitle = '';
120 $this->feed_updated = '';
121 $this->feed_authors = array();
122 $this->feed_contributors = array();
123 $this->generator = '';
127 } elseif ($name == "ENTRY") {
128 $this->entries[] = $this->trim_data(array(
130 "title" => $this->title,
131 "updated" => $this->updated,
132 "links" => $this->links,
133 "published" => $this->published,
134 "content" => $this->content,
135 "summary" => $this->summary,
136 "authors" => $this->authors,
137 "contributors" => $this->contributors
143 $this->published = '';
145 $this->authors = array();
146 $this->contributors = array();
147 $this->inside_entry = false;
148 } elseif ($name == "CONTENT") {
149 $this->inside_content = false;
150 } elseif ($name == "CONTRIBUTOR") {
151 $a_contributor = $this->trim_data(array(
152 "name" => $this->name,
153 "email" => $this->email
155 if ($this->inside_entry) {
156 $this->contributors[] = $a_contributor;
158 $this->feed_contributors[] = $a_contributor;
162 } elseif ($this->inside_content) {
163 $this->content .= "</" . strtolower($name) . ">";
167 function cdata($parser, $data)
169 global $current_tag, $current_attrs;
171 if ($this->inside_content) {
172 $this->content .= $data;
174 switch ($current_tag) {
176 if ($this->inside_entry)
179 $this->feed_id .= $data;
183 foreach ($current_attrs as $k => $v) {
184 $a_link[strtolower($k)] = $v;
186 if ($this->inside_entry) {
187 $this->links[] = $a_link;
189 $this->feed_links[] = $a_link;
193 $this->name .= $data;
196 $this->email .= $data;
199 if ($this->inside_entry)
200 $this->title .= $data;
202 $this->feed_title .= $data;
205 if ($this->inside_entry)
206 $this->updated .= $data;
208 $this->feed_updated .= $data;
211 $this->feed_subtitle .= $data;
214 $this->published .= $data;
217 $this->summary .= $data;
223 $this->generator .= $data;
226 $this->icon .= $data;
229 $this->logo .= $data;
232 $this->rights .= $data;
238 function trim_data($array)
240 return array_map(array("self", "trim_element"), $array);
243 function trim_element($element)
245 if (is_array($element)) {
246 return $this->trim_data($element);
247 } elseif (is_string($element)) {
248 return trim($element);
252 function serialize_tag($tag_name, $attributes)
254 $tag = "<" . $tag_name;
255 foreach ($attributes as $k => $v) {
256 $tag .= " " . strtolower($k) . "=\"$v\"";