Subversion Repositories eFlore/Applications.cel

Rev

Rev 1328 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1328 aurelien 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
4
/**
5
 * RSS0.9 class for XML_Feed_Parser
6
 *
7
 * PHP versions 5
8
 *
9
 * LICENSE: This source file is subject to version 3.0 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   XML
16
 * @package    XML_Feed_Parser
17
 * @author     James Stewart <james@jystewart.net>
18
 * @copyright  2005 James Stewart <james@jystewart.net>
19
 * @license    http://www.gnu.org/copyleft/lesser.html  GNU LGPL 2.1
20
 * @version    CVS: $Id: RSS09.php 304308 2010-10-11 12:05:50Z clockwerx $
21
 * @link       http://pear.php.net/package/XML_Feed_Parser/
22
 */
23
 
24
/**
25
 * This class handles RSS0.9 feeds.
26
 *
27
 * @author    James Stewart <james@jystewart.net>
28
 * @version    Release: @package_version@
29
 * @package XML_Feed_Parser
30
 * @todo    Find a Relax NG URI we can use
31
 */
32
class XmlFeedParserRss09 extends XmlFeedParserType {
33
    /**
34
     * The URI of the RelaxNG schema used to (optionally) validate the feed
35
     * @var string
36
     */
37
    protected $relax = '';
38
 
39
    /**
40
     * We're likely to use XPath, so let's keep it global
41
     * @var DOMXPath
42
     */
43
    protected $xpath;
44
 
45
    /**
46
     * The feed type we are parsing
47
     * @var string
48
     */
49
    public $version = 'RSS 0.9';
50
 
51
    /**
52
     * The class used to represent individual items
53
     * @var string
54
     */
55
    protected $itemClass = 'XmlFeedParserRss09Element';
56
 
57
    /**
58
     * The element containing entries
59
     * @var string
60
     */
61
    protected $itemElement = 'item';
62
 
63
    /**
64
     * Here we map those elements we're not going to handle individually
65
     * to the constructs they are. The optional second parameter in the array
66
     * tells the parser whether to 'fall back' (not apt. at the feed level) or
67
     * fail if the element is missing. If the parameter is not set, the function
68
     * will simply return false and leave it to the client to decide what to do.
69
     * @var array
70
     */
71
    protected $map = array(
72
        'title' => array('Text'),
73
        'link' => array('Text'),
74
        'description' => array('Text'),
75
        'image' => array('Image'),
76
        'textinput' => array('TextInput'));
77
 
78
    /**
79
     * Here we map some elements to their atom equivalents. This is going to be
80
     * quite tricky to pull off effectively (and some users' methods may vary)
81
     * but is worth trying. The key is the atom version, the value is RSS2.
82
     * @var array
83
     */
84
    protected $compatMap = array(
85
        'title' => array('title'),
86
        'link' => array('link'),
87
        'subtitle' => array('description'));
88
 
89
    /**
90
     * We will be working with multiple namespaces and it is useful to
91
     * keep them together
92
     * @var array
93
     */
94
    protected $namespaces = array(
95
        'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
96
 
97
    /**
98
     * Our constructor does nothing more than its parent.
99
     *
100
     * @todo    RelaxNG validation
101
     * @param    DOMDocument    $xml    A DOM object representing the feed
102
     * @param    bool (optional) $string    Whether or not to validate this feed
103
     */
104
    function __construct(DOMDocument $model, $strict = false) {
105
        $this->model = $model;
106
 
107
        $this->xpath = new DOMXPath($model);
108
        foreach ($this->namespaces as $key => $value) {
109
            $this->xpath->registerNamespace($key, $value);
110
        }
111
        $this->numberEntries = $this->count('item');
112
    }
113
 
114
    /**
115
     * Included for compatibility -- will not work with RSS 0.9
116
     *
117
     * This is not something that will work with RSS0.9 as it does not have
118
     * clear restrictions on the global uniqueness of IDs.
119
     *
120
     * @param    string    $id    any valid ID.
121
     * @return    false
122
     */
123
    function getEntryById($id) {
124
        return false;
125
    }
126
 
127
    /**
128
     * Get details of the image associated with the feed.
129
     *
130
     * @return  array|false an array simply containing the child elements
131
     */
132
    protected function getImage() {
133
        $images = $this->model->getElementsByTagName('image');
134
        if ($images->length > 0) {
135
            $image = $images->item(0);
136
            $details = array();
137
            if ($image->hasChildNodes()) {
138
                $details = array(
139
                    'title' => $image->getElementsByTagName('title')->item(0)->value,
140
                    'link' => $image->getElementsByTagName('link')->item(0)->value,
141
                    'url' => $image->getElementsByTagName('url')->item(0)->value);
142
            } else {
143
                $details = array('title' => false,
144
                    'link' => false,
145
                    'url' => $image->attributes->getNamedItem('resource')->nodeValue);
146
            }
147
            $details = array_merge($details,
148
                array('description' => false, 'height' => false, 'width' => false));
149
            if (! empty($details)) {
150
                return $details;
151
            }
152
        }
153
        return false;
154
    }
155
 
156
    /**
157
     * The textinput element is little used, but in the interests of
158
     * completeness we will support it.
159
     *
160
     * @return  array|false
161
     */
162
    protected function getTextInput() {
163
        $inputs = $this->model->getElementsByTagName('textinput');
164
        if ($inputs->length > 0) {
165
            $input = $inputs->item(0);
166
            $results = array();
167
            $results['title'] = isset(
168
                $input->getElementsByTagName('title')->item(0)->value) ?
169
                $input->getElementsByTagName('title')->item(0)->value : null;
170
            $results['description'] = isset(
171
                $input->getElementsByTagName('description')->item(0)->value) ?
172
                $input->getElementsByTagName('description')->item(0)->value : null;
173
            $results['name'] = isset(
174
                $input->getElementsByTagName('name')->item(0)->value) ?
175
                $input->getElementsByTagName('name')->item(0)->value : null;
176
            $results['link'] = isset(
177
                   $input->getElementsByTagName('link')->item(0)->value) ?
178
                   $input->getElementsByTagName('link')->item(0)->value : null;
179
            if (empty($results['link']) &&
180
                $input->attributes->getNamedItem('resource')) {
181
                $results['link'] = $input->attributes->getNamedItem('resource')->nodeValue;
182
            }
183
            if (! empty($results)) {
184
                return $results;
185
            }
186
        }
187
        return false;
188
    }
189
 
190
    /**
191
     * Get details of a link from the feed.
192
     *
193
     * In RSS1 a link is a text element but in order to ensure that we resolve
194
     * URLs properly we have a special function for them.
195
     *
196
     * @return  string
197
     */
198
    function getLink($offset = 0, $attribute = 'href', $params = false) {
199
        $links = $this->model->getElementsByTagName('link');
200
        if ($links->length <= $offset) {
201
            return false;
202
        }
203
        $link = $links->item($offset);
204
        return $this->addBase($link->nodeValue, $link);
205
    }
206
 
207
    /**
208
     * Not implemented - no available validation.
209
     */
210
    public function relaxNGValidate() {
211
        return true;
212
    }
213
}
214
 
215
?>