2 rcs_id('$Id: RssParser.php,v 1.8 2004-06-08 21:03:20 rurban Exp $');
4 * Simple RSSParser Class
5 * Based on Duncan Gough RSSParser class
6 * Copyleft Arnaud Fontaine
8 * See lib/plugin/RssFeed.php and lib/XmlParser.php
12 This file is part of PhpWiki.
14 PhpWiki is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 PhpWiki is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with PhpWiki; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * 2004-04-09 16:30:50 rurban:
31 * added fsockopen allow_url_fopen = Off workaround
32 * 2004-04-12 20:04:12 rurban:
33 * fixes for IMAGE element (sf.net)
36 require_once('lib/XmlParser.php');
43 var $description = "";
44 var $inside_item = false;
51 function tag_open($parser, $name, $attrs=''){
56 $this->inside_item = true;
57 elseif ($name == "IMAGE")
58 $this->inside_item = true;
61 function tag_close($parser, $tagName, $attrs=''){
64 if ($tagName == "ITEM") {
65 if (empty($this->items)) {
66 $this->items = array();
67 $GLOBALS['rss_parser_items'] =& $this->items;
69 $this->items[] = array("title" => $this->item['TITLE'],
70 "description" => $this->item['DESCRIPTION'],
71 "link" => $this->item['LINK']);
72 $this->item['TITLE'] = "";
73 $this->item['DESCRIPTION'] = "";
74 $this->item['LINK'] = "";
75 $this->inside_item = false;
76 } elseif ($tagName == "IMAGE") {
77 $this->item['TITLE'] = "";
78 $this->item['DESCRIPTION'] = "";
79 $this->item['LINK'] = "";
80 $this->inside_item = false;
81 } elseif ($tagName == "CHANNEL") {
82 $this->channel = array("title" => $this->title,
83 "description" => $this->description,
84 "link" => $this->link,
85 "date" => $this->date,
86 "divers" => $this->divers);
87 $GLOBALS['rss_parser_channel'] =& $this->channel;
89 $this->description = "";
96 function cdata($parser, $data){
99 if ($this->inside_item) {
100 if (empty($this->item[$current_tag]))
101 $this->item[$current_tag] = '';
102 if ($current_tag == 'LINK') {
104 $this->item[$current_tag] = trim($data);
106 $this->item[$current_tag] .= trim($data);
109 switch ($current_tag) {
112 $this->title .= " " . trim($data);
116 $this->description .= trim($data);
120 $this->link = trim($data);
124 $this->date .= " " . trim($data);
127 $this->divers .= " " . $current_tag."/".$data;
133 function parse($content, $is_final = true) {
134 xml_parse($this->_parser, $content, $is_final) or
135 trigger_error(sprintf("XML error: %s at line %d",
136 xml_error_string(xml_get_error_code($this->_parser)),
137 xml_get_current_line_number($this->_parser)),
139 //OO workaround: parser object looses its params. we have to store them in globals
140 if (empty($this->items)) {
141 $this->items = $GLOBALS['rss_parser_items'];
142 $this->channel = $GLOBALS['rss_parser_channel'];
144 unset($GLOBALS['rss_parser_items']);
145 unset($GLOBALS['rss_parser_channel']);
149 // $Log: not supported by cvs2svn $
150 // Revision 1.7 2004/05/24 17:31:31 rurban
151 // new XmlParser and HtmlParser, RssParser based on that.
153 // Revision 1.6 2004/05/18 16:18:36 rurban
154 // AutoSplit at subpage seperators
155 // RssFeed stability fix for empty feeds or broken connections
157 // Revision 1.5 2004/04/26 20:44:34 rurban
158 // locking table specific for better databases
160 // Revision 1.4 2004/04/18 01:11:51 rurban
161 // more numeric pagename fixes.
162 // fixed action=upload with merge conflict warnings.
163 // charset changed from constant to global (dynamic utf-8 switching)
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil