2 rcs_id('$Id: RssParser.php,v 1.1 2004-04-09 17:46:40 rurban Exp $');
4 * RSSParser Class, requires the expat extension
5 * Based on Duncan Gough RSSParser class
6 * Copyleft Arnaud Fontaine
9 This file is part of PhpWiki.
11 PhpWiki is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 PhpWiki is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with PhpWiki; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * 2004-04-09 16:30:50 rurban:
28 * added fsockopen allow_url_fopen = Off workaround
34 var $description = "";
35 var $inside_item = false;
37 var $channel = array();
41 function startElement($parser, $name, $attrs=''){
45 if ($current_tag == "ITEM")
46 $this->inside_item = true;
49 function endElement($parser, $tagName, $attrs=''){
52 if ($tagName == "ITEM") {
53 $this->items[] = array("title" => $this->title,
54 "description" => $this->description,
55 "link" => $this->link);
57 $this->description = "";
59 $this->inside_item = false;
61 } elseif ($tagName == "CHANNEL") {
63 $this->channel = array("title" => $this->title,
64 "description" => $this->description,
65 "link" => $this->link,
66 "date" => $this->date,
67 "divers" => $this->divers);
69 $this->description = "";
76 function characterData($parser, $data){
79 if ($this->inside_item){
80 switch ($current_tag){
83 $this->title .= trim($data);
86 $this->description .= trim($data);
89 $this->link .= trim($data);
99 $this->title .= trim($data);
102 $this->description .= trim($data);
105 $this->link .= trim($data);
108 $this->date .= trim($data);
110 $this->divers .= $current_tag."/".$data;
116 function parse_results($xml_parser, $rss_parser, $file) {
117 xml_set_object($xml_parser, &$rss_parser);
118 xml_set_element_handler($xml_parser, "startElement", "endElement");
119 xml_set_character_data_handler($xml_parser, "characterData");
121 if (ini_get('allow_url_fopen')) {
122 $fp = fopen("$file","r") or die("Error reading XML file, $file");
123 while ($data = fread($fp, 4096)) {
124 xml_parse($xml_parser, $data, feof($fp)) or
125 die(sprintf("XML error: %s at line %d",
126 xml_error_string(xml_get_error_code($xml_parser)),
127 xml_get_current_line_number($xml_parser)));
131 // other url_fopen workarounds: curl, socket (http 80 only)
132 require_once("lib/HttpClient.php");
133 $data = HttpClient::quickGet($file);
134 xml_parse($xml_parser, $data, true) or
135 die(sprintf("XML error: %s at line %d",
136 xml_error_string(xml_get_error_code($xml_parser)),
137 xml_get_current_line_number($xml_parser)));
139 xml_parser_free($xml_parser);
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil