Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
1527 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
4
/**
5
 * RSS1 Element 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: RSS11Element.php,v 1.2 2007-07-25 15:05:34 jp_milcent Exp $
21
 * @link       http://pear.php.net/package/XML_Feed_Parser/
22
 */
23
 
24
/*
25
 * This class provides support for RSS 1.1 entries. It will usually be called by
26
 * XML_Feed_Parser_RSS11 with which it shares many methods.
27
 *
28
 * @author    James Stewart <james@jystewart.net>
29
 * @version    Release: 1.0.2
30
 * @package XML_Feed_Parser
31
 */
32
class XML_Feed_Parser_RSS11Element extends XML_Feed_Parser_RSS11
33
{
34
    /**
35
     * This will be a reference to the parent object for when we want
36
     * to use a 'fallback' rule
37
     * @var XML_Feed_Parser_RSS1
38
     */
39
    protected $parent;
40
 
41
    /**
42
     * Our specific element map
43
     * @var array
44
     */
45
    protected $map = array(
46
        'id' => array('Id'),
47
        'title' => array('Text'),
48
        'link' => array('Link'),
49
        'description' => array('Text'), # or dc:description
50
        'category' => array('Category'),
51
        'rights' => array('Text'), # dc:rights
52
        'creator' => array('Text'), # dc:creator
53
        'publisher' => array('Text'), # dc:publisher
54
        'contributor' => array('Text'), # dc:contributor
55
        'date' => array('Date'), # dc:date
56
        'content' => array('Content')
57
        );
58
 
59
    /**
60
     * Here we map some elements to their atom equivalents. This is going to be
61
     * quite tricky to pull off effectively (and some users' methods may vary)
62
     * but is worth trying. The key is the atom version, the value is RSS1.
63
     * @var array
64
     */
65
    protected $compatMap = array(
66
        'content' => array('content'),
67
        'updated' => array('lastBuildDate'),
68
        'published' => array('pubdate'),
69
        'subtitle' => array('description'),
70
        'updated' => array('date'),
71
        'author' => array('creator'),
72
        'contributor' => array('contributor')
73
    );
74
 
75
    /**
76
     * Store useful information for later.
77
     *
78
     * @param   DOMElement  $element - this item as a DOM element
79
     * @param   XML_Feed_Parser_RSS1 $parent - the feed of which this is a member
80
     */
81
    function __construct(DOMElement $element, $parent, $xmlBase = '')
82
    {
83
        $this->model = $element;
84
        $this->parent = $parent;
85
    }
86
 
87
    /**
88
     * If an rdf:about attribute is specified, return that as an ID
89
     *
90
     * There is no established way of showing an ID for an RSS1 entry. We will
91
     * simulate it using the rdf:about attribute of the entry element. This cannot
92
     * be relied upon for unique IDs but may prove useful.
93
     *
94
     * @return  string|false
95
     */
96
    function getId()
97
    {
98
        if ($this->model->attributes->getNamedItem('about')) {
99
            return $this->model->attributes->getNamedItem('about')->nodeValue;
100
        }
101
        return false;
102
    }
103
 
104
    /**
105
     * Return the entry's content
106
     *
107
     * The official way to include full content in an RSS1 entry is to use
108
     * the content module's element 'encoded'. Often, however, the 'description'
109
     * element is used instead. We will offer that as a fallback.
110
     *
111
     * @return  string|false
112
     */
113
    function getContent()
114
    {
115
        $options = array('encoded', 'description');
116
        foreach ($options as $element) {
117
            $test = $this->model->getElementsByTagName($element);
118
            if ($test->length == 0) {
119
                continue;
120
            }
121
            if ($test->item(0)->hasChildNodes()) {
122
                $value = '';
123
                foreach ($test->item(0)->childNodes as $child) {
124
                    if ($child instanceof DOMText) {
125
                        $value .= $child->nodeValue;
126
                    } else {
127
                        $simple = simplexml_import_dom($child);
128
                        $value .= $simple->asXML();
129
                    }
130
                }
131
                return $value;
132
            } else if ($test->length > 0) {
133
                return $test->item(0)->nodeValue;
134
            }
135
        }
136
        return false;
137
    }
138
 
139
    /**
140
     * How RSS1.1 should support for enclosures is not clear. For now we will return
141
     * false.
142
     *
143
     * @return  false
144
     */
145
    function getEnclosure()
146
    {
147
        return false;
148
    }
149
}
150
 
151
?>