]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/RssParser.php
renamed DB_Session to DbSession (in CVS also)
[SourceForge/phpwiki.git] / lib / RssParser.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RssParser.php,v 1.7 2004-05-24 17:31:31 rurban Exp $');
3 /**
4  * Simple RSSParser Class
5  * Based on Duncan Gough RSSParser class
6  * Copyleft Arnaud Fontaine
7  * Licence : GPL
8  * See lib/plugin/RssFeed.php and lib/XmlParser.php
9  */
10
11 /*
12  This file is part of PhpWiki.
13
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.
18
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.
23
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
27  */
28
29 /**
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)
34  */
35
36 require_once('lib/XmlParser.php');
37
38 class RSSParser 
39 extends XmlParser {
40
41     var $title = "";
42     var $link  = "";
43     var $description = "";
44     var $inside_item = false;
45     var $item  = array();
46     var $items = array();
47     var $channel = array();
48     var $divers = "";
49     var $date = "";
50
51     function tag_open($parser, $name, $attrs=''){
52         global $current_tag;
53
54         $current_tag = $name;
55         if ($name == "ITEM")
56             $this->inside_item = true;
57         elseif ($name == "IMAGE")
58             $this->inside_item = true;
59     }
60
61     function tag_close($parser, $tagName, $attrs=''){
62         global $current_tag;
63
64         if ($tagName == "ITEM") {
65             $this->items[] = array("title"       => $this->item['TITLE'],
66                                    "description" => $this->item['DESCRIPTION'],
67                                    "link"        => $this->item['LINK']);
68             $this->item['TITLE']       = "";
69             $this->item['DESCRIPTION'] = "";
70             $this->item['LINK']        = "";
71             $this->inside_item = false;
72         } elseif ($tagName == "IMAGE") {
73             $this->item['TITLE']       = "";
74             $this->item['DESCRIPTION'] = "";
75             $this->item['LINK']        = "";
76             $this->inside_item = false;
77         } elseif ($tagName == "CHANNEL") {
78             $this->channel = array("title" => $this->title,
79                                    "description" => $this->description,
80                                    "link" => $this->link,
81                                    "date" => $this->date,
82                                    "divers" => $this->divers);
83             $this->title       = "";
84             $this->description = "";
85             $this->link        = "";
86             $this->divers      = "";
87             $this->date        = "";
88         }
89     }
90
91     function cdata($parser, $data){
92         global $current_tag;
93
94         if ($this->inside_item) {
95             if (empty($this->item[$current_tag]))
96                 $this->item[$current_tag] = '';
97             if ($current_tag == 'LINK') {
98                 if (trim($data))
99                     $this->item[$current_tag] = trim($data);
100             } else {
101                 $this->item[$current_tag] .= trim($data);
102             }
103         } else {
104             switch ($current_tag) {
105             case "TITLE":
106                 if (trim($data))
107                     $this->title .= " " . trim($data);
108                 break;
109             case "DESCRIPTION":
110                 if (trim($data))
111                     $this->description .= trim($data);
112                 break;
113             case "LINK":
114                 if (trim($data))
115                     $this->link = trim($data);
116                 break;
117             case "DC:DATE":
118                 if (trim($data))
119                     $this->date .= " " . trim($data);
120             default:
121                 if (trim($data))
122                     $this->divers .= " " . $current_tag."/".$data;
123                 break;
124             }
125         }
126     } // characterData
127 }
128
129 // $Log: not supported by cvs2svn $
130 // Revision 1.6  2004/05/18 16:18:36  rurban
131 // AutoSplit at subpage seperators
132 // RssFeed stability fix for empty feeds or broken connections
133 //
134 // Revision 1.5  2004/04/26 20:44:34  rurban
135 // locking table specific for better databases
136 //
137 // Revision 1.4  2004/04/18 01:11:51  rurban
138 // more numeric pagename fixes.
139 // fixed action=upload with merge conflict warnings.
140 // charset changed from constant to global (dynamic utf-8 switching)
141 //
142
143 // For emacs users
144 // Local Variables:
145 // mode: php
146 // tab-width: 8
147 // c-basic-offset: 4
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil
150 // End:
151 ?>