/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS1Element.php |
---|
File deleted |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS11Element.php |
---|
File deleted |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS1.php |
---|
File deleted |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS11.php |
---|
File deleted |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS09Element.php |
---|
File deleted |
\ No newline at end of file |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/RSS09.php |
---|
File deleted |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss09.php |
---|
New file |
0,0 → 1,215 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS0.9 class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS09.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/** |
* This class handles RSS0.9 feeds. |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
* @todo Find a Relax NG URI we can use |
*/ |
class XmlFeedParserRss09 extends XmlFeedParserType { |
/** |
* The URI of the RelaxNG schema used to (optionally) validate the feed |
* @var string |
*/ |
protected $relax = ''; |
/** |
* We're likely to use XPath, so let's keep it global |
* @var DOMXPath |
*/ |
protected $xpath; |
/** |
* The feed type we are parsing |
* @var string |
*/ |
public $version = 'RSS 0.9'; |
/** |
* The class used to represent individual items |
* @var string |
*/ |
protected $itemClass = 'XmlFeedParserRss09Element'; |
/** |
* The element containing entries |
* @var string |
*/ |
protected $itemElement = 'item'; |
/** |
* Here we map those elements we're not going to handle individually |
* to the constructs they are. The optional second parameter in the array |
* tells the parser whether to 'fall back' (not apt. at the feed level) or |
* fail if the element is missing. If the parameter is not set, the function |
* will simply return false and leave it to the client to decide what to do. |
* @var array |
*/ |
protected $map = array( |
'title' => array('Text'), |
'link' => array('Text'), |
'description' => array('Text'), |
'image' => array('Image'), |
'textinput' => array('TextInput')); |
/** |
* Here we map some elements to their atom equivalents. This is going to be |
* quite tricky to pull off effectively (and some users' methods may vary) |
* but is worth trying. The key is the atom version, the value is RSS2. |
* @var array |
*/ |
protected $compatMap = array( |
'title' => array('title'), |
'link' => array('link'), |
'subtitle' => array('description')); |
/** |
* We will be working with multiple namespaces and it is useful to |
* keep them together |
* @var array |
*/ |
protected $namespaces = array( |
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
/** |
* Our constructor does nothing more than its parent. |
* |
* @todo RelaxNG validation |
* @param DOMDocument $xml A DOM object representing the feed |
* @param bool (optional) $string Whether or not to validate this feed |
*/ |
function __construct(DOMDocument $model, $strict = false) { |
$this->model = $model; |
$this->xpath = new DOMXPath($model); |
foreach ($this->namespaces as $key => $value) { |
$this->xpath->registerNamespace($key, $value); |
} |
$this->numberEntries = $this->count('item'); |
} |
/** |
* Included for compatibility -- will not work with RSS 0.9 |
* |
* This is not something that will work with RSS0.9 as it does not have |
* clear restrictions on the global uniqueness of IDs. |
* |
* @param string $id any valid ID. |
* @return false |
*/ |
function getEntryById($id) { |
return false; |
} |
/** |
* Get details of the image associated with the feed. |
* |
* @return array|false an array simply containing the child elements |
*/ |
protected function getImage() { |
$images = $this->model->getElementsByTagName('image'); |
if ($images->length > 0) { |
$image = $images->item(0); |
$details = array(); |
if ($image->hasChildNodes()) { |
$details = array( |
'title' => $image->getElementsByTagName('title')->item(0)->value, |
'link' => $image->getElementsByTagName('link')->item(0)->value, |
'url' => $image->getElementsByTagName('url')->item(0)->value); |
} else { |
$details = array('title' => false, |
'link' => false, |
'url' => $image->attributes->getNamedItem('resource')->nodeValue); |
} |
$details = array_merge($details, |
array('description' => false, 'height' => false, 'width' => false)); |
if (! empty($details)) { |
return $details; |
} |
} |
return false; |
} |
/** |
* The textinput element is little used, but in the interests of |
* completeness we will support it. |
* |
* @return array|false |
*/ |
protected function getTextInput() { |
$inputs = $this->model->getElementsByTagName('textinput'); |
if ($inputs->length > 0) { |
$input = $inputs->item(0); |
$results = array(); |
$results['title'] = isset( |
$input->getElementsByTagName('title')->item(0)->value) ? |
$input->getElementsByTagName('title')->item(0)->value : null; |
$results['description'] = isset( |
$input->getElementsByTagName('description')->item(0)->value) ? |
$input->getElementsByTagName('description')->item(0)->value : null; |
$results['name'] = isset( |
$input->getElementsByTagName('name')->item(0)->value) ? |
$input->getElementsByTagName('name')->item(0)->value : null; |
$results['link'] = isset( |
$input->getElementsByTagName('link')->item(0)->value) ? |
$input->getElementsByTagName('link')->item(0)->value : null; |
if (empty($results['link']) && |
$input->attributes->getNamedItem('resource')) { |
$results['link'] = $input->attributes->getNamedItem('resource')->nodeValue; |
} |
if (! empty($results)) { |
return $results; |
} |
} |
return false; |
} |
/** |
* Get details of a link from the feed. |
* |
* In RSS1 a link is a text element but in order to ensure that we resolve |
* URLs properly we have a special function for them. |
* |
* @return string |
*/ |
function getLink($offset = 0, $attribute = 'href', $params = false) { |
$links = $this->model->getElementsByTagName('link'); |
if ($links->length <= $offset) { |
return false; |
} |
$link = $links->item($offset); |
return $this->addBase($link->nodeValue, $link); |
} |
/** |
* Not implemented - no available validation. |
*/ |
public function relaxNGValidate() { |
return true; |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss1Element.php |
---|
New file |
0,0 → 1,111 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS1 Element class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS1Element.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/* |
* This class provides support for RSS 1.0 entries. It will usually be called by |
* XML_Feed_Parser_RSS1 with which it shares many methods. |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
*/ |
class XmlFeedParserRss1Element extends XmlFeedParserRss1 { |
/** |
* This will be a reference to the parent object for when we want |
* to use a 'fallback' rule |
* @var XML_Feed_Parser_RSS1 |
*/ |
protected $parent; |
/** |
* Our specific element map |
* @var array |
*/ |
protected $map = array( |
'id' => array('Id'), |
'title' => array('Text'), |
'link' => array('Link'), |
'description' => array('Text'), # or dc:description |
'category' => array('Category'), |
'rights' => array('Text'), # dc:rights |
'creator' => array('Text'), # dc:creator |
'publisher' => array('Text'), # dc:publisher |
'contributor' => array('Text'), # dc:contributor |
'date' => array('Date'), # dc:date |
'content' => array('Content') |
); |
/** |
* Here we map some elements to their atom equivalents. This is going to be |
* quite tricky to pull off effectively (and some users' methods may vary) |
* but is worth trying. The key is the atom version, the value is RSS1. |
* @var array |
*/ |
protected $compatMap = array( |
'content' => array('content'), |
'updated' => array('lastBuildDate'), |
'published' => array('date'), |
'subtitle' => array('description'), |
'updated' => array('date'), |
'author' => array('creator'), |
'contributor' => array('contributor') |
); |
/** |
* Store useful information for later. |
* |
* @param DOMElement $element - this item as a DOM element |
* @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member |
*/ |
function __construct(DOMElement $element, $parent, $xmlBase = '') { |
$this->model = $element; |
$this->parent = $parent; |
} |
/** |
* If an rdf:about attribute is specified, return it as an ID |
* |
* There is no established way of showing an ID for an RSS1 entry. We will |
* simulate it using the rdf:about attribute of the entry element. This cannot |
* be relied upon for unique IDs but may prove useful. |
* |
* @return string|false |
*/ |
function getId() { |
if ($this->model->attributes->getNamedItem('about')) { |
return $this->model->attributes->getNamedItem('about')->nodeValue; |
} |
return false; |
} |
/** |
* How RSS1 should support for enclosures is not clear. For now we will return |
* false. |
* |
* @return false |
*/ |
function getEnclosure() { |
return false; |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss11Element.php |
---|
New file |
0,0 → 1,145 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS1 Element class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS11Element.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/* |
* This class provides support for RSS 1.1 entries. It will usually be called by |
* XML_Feed_Parser_RSS11 with which it shares many methods. |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
*/ |
class XmlFeedParserRss11Element extends XmlFeedParserRss11 { |
/** |
* This will be a reference to the parent object for when we want |
* to use a 'fallback' rule |
* @var XML_Feed_Parser_RSS1 |
*/ |
protected $parent; |
/** |
* Our specific element map |
* @var array |
*/ |
protected $map = array( |
'id' => array('Id'), |
'title' => array('Text'), |
'link' => array('Link'), |
'description' => array('Text'), # or dc:description |
'category' => array('Category'), |
'rights' => array('Text'), # dc:rights |
'creator' => array('Text'), # dc:creator |
'publisher' => array('Text'), # dc:publisher |
'contributor' => array('Text'), # dc:contributor |
'date' => array('Date'), # dc:date |
'content' => array('Content') |
); |
/** |
* Here we map some elements to their atom equivalents. This is going to be |
* quite tricky to pull off effectively (and some users' methods may vary) |
* but is worth trying. The key is the atom version, the value is RSS1. |
* @var array |
*/ |
protected $compatMap = array( |
'content' => array('content'), |
'updated' => array('lastBuildDate'), |
'published' => array('date'), |
'subtitle' => array('description'), |
'updated' => array('date'), |
'author' => array('creator'), |
'contributor' => array('contributor') |
); |
/** |
* Store useful information for later. |
* |
* @param DOMElement $element - this item as a DOM element |
* @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member |
*/ |
function __construct(DOMElement $element, $parent, $xmlBase = '') { |
$this->model = $element; |
$this->parent = $parent; |
} |
/** |
* If an rdf:about attribute is specified, return that as an ID |
* |
* There is no established way of showing an ID for an RSS1 entry. We will |
* simulate it using the rdf:about attribute of the entry element. This cannot |
* be relied upon for unique IDs but may prove useful. |
* |
* @return string|false |
*/ |
function getId() { |
if ($this->model->attributes->getNamedItem('about')) { |
return $this->model->attributes->getNamedItem('about')->nodeValue; |
} |
return false; |
} |
/** |
* Return the entry's content |
* |
* The official way to include full content in an RSS1 entry is to use |
* the content module's element 'encoded'. Often, however, the 'description' |
* element is used instead. We will offer that as a fallback. |
* |
* @return string|false |
*/ |
function getContent() { |
$options = array('encoded', 'description'); |
foreach ($options as $element) { |
$test = $this->model->getElementsByTagName($element); |
if ($test->length == 0) { |
continue; |
} |
if ($test->item(0)->hasChildNodes()) { |
$value = ''; |
foreach ($test->item(0)->childNodes as $child) { |
if ($child instanceof DOMText) { |
$value .= $child->nodeValue; |
} else { |
$simple = simplexml_import_dom($child); |
$value .= $simple->asXML(); |
} |
} |
return $value; |
} else if ($test->length > 0) { |
return $test->item(0)->nodeValue; |
} |
} |
return false; |
} |
/** |
* How RSS1.1 should support for enclosures is not clear. For now we will return |
* false. |
* |
* @return false |
*/ |
function getEnclosure() { |
return false; |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss1.php |
---|
New file |
0,0 → 1,267 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS1 class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS1.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/** |
* This class handles RSS1.0 feeds. |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
* @todo Find a Relax NG URI we can use |
*/ |
class XmlFeedParserRss1 extends XmlFeedParserType { |
/** |
* The URI of the RelaxNG schema used to (optionally) validate the feed |
* @var string |
*/ |
protected $relax = 'rss10.rng'; |
/** |
* We're likely to use XPath, so let's keep it global |
* @var DOMXPath |
*/ |
protected $xpath; |
/** |
* The feed type we are parsing |
* @var string |
*/ |
public $version = 'RSS 1.0'; |
/** |
* The class used to represent individual items |
* @var string |
*/ |
protected $itemClass = 'XmlFeedParserRss1Element'; |
/** |
* The element containing entries |
* @var string |
*/ |
protected $itemElement = 'item'; |
/** |
* Here we map those elements we're not going to handle individually |
* to the constructs they are. The optional second parameter in the array |
* tells the parser whether to 'fall back' (not apt. at the feed level) or |
* fail if the element is missing. If the parameter is not set, the function |
* will simply return false and leave it to the client to decide what to do. |
* @var array |
*/ |
protected $map = array( |
'title' => array('Text'), |
'link' => array('Text'), |
'description' => array('Text'), |
'image' => array('Image'), |
'textinput' => array('TextInput'), |
'updatePeriod' => array('Text'), |
'updateFrequency' => array('Text'), |
'updateBase' => array('Date'), |
'rights' => array('Text'), # dc:rights |
'description' => array('Text'), # dc:description |
'creator' => array('Text'), # dc:creator |
'publisher' => array('Text'), # dc:publisher |
'contributor' => array('Text'), # dc:contributor |
'date' => array('Date') # dc:contributor |
); |
/** |
* Here we map some elements to their atom equivalents. This is going to be |
* quite tricky to pull off effectively (and some users' methods may vary) |
* but is worth trying. The key is the atom version, the value is RSS2. |
* @var array |
*/ |
protected $compatMap = array( |
'title' => array('title'), |
'link' => array('link'), |
'subtitle' => array('description'), |
'author' => array('creator'), |
'updated' => array('date')); |
/** |
* We will be working with multiple namespaces and it is useful to |
* keep them together |
* @var array |
*/ |
protected $namespaces = array( |
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
'rss' => 'http://purl.org/rss/1.0/', |
'dc' => 'http://purl.org/rss/1.0/modules/dc/', |
'content' => 'http://purl.org/rss/1.0/modules/content/', |
'sy' => 'http://web.resource.org/rss/1.0/modules/syndication/'); |
/** |
* Our constructor does nothing more than its parent. |
* |
* @param DOMDocument $xml A DOM object representing the feed |
* @param bool (optional) $string Whether or not to validate this feed |
*/ |
function __construct(DOMDocument $model, $strict = false) { |
$this->model = $model; |
if ($strict) { |
if (! $this->relaxNGValidate()) { |
throw new XML_Feed_Parser_Exception('Failed required validation'); |
} |
} |
$this->xpath = new DOMXPath($model); |
foreach ($this->namespaces as $key => $value) { |
$this->xpath->registerNamespace($key, $value); |
} |
$this->numberEntries = $this->count('item'); |
} |
/** |
* Allows retrieval of an entry by ID where the rdf:about attribute is used |
* |
* This is not really something that will work with RSS1 as it does not have |
* clear restrictions on the global uniqueness of IDs. We will employ the |
* _very_ hit and miss method of selecting entries based on the rdf:about |
* attribute. If DOMXPath::evaluate is available, we also use that to store |
* a reference to the entry in the array used by getEntryByOffset so that |
* method does not have to seek out the entry if it's requested that way. |
* |
* @param string $id any valid ID. |
* @return XML_Feed_Parser_RSS1Element |
*/ |
function getEntryById($id) { |
if (isset($this->idMappings[$id])) { |
return $this->entries[$this->idMappings[$id]]; |
} |
$entries = $this->xpath->query("//rss:item[@rdf:about='$id']"); |
if ($entries->length > 0) { |
$classname = $this->itemClass; |
$entry = new $classname($entries->item(0), $this); |
if (in_array('evaluate', get_class_methods($this->xpath))) { |
$offset = $this->xpath->evaluate("count(preceding-sibling::rss:item)", $entries->item(0)); |
$this->entries[$offset] = $entry; |
} |
$this->idMappings[$id] = $entry; |
return $entry; |
} |
return false; |
} |
/** |
* Get details of the image associated with the feed. |
* |
* @return array|false an array simply containing the child elements |
*/ |
protected function getImage() { |
$images = $this->model->getElementsByTagName('image'); |
if ($images->length > 0) { |
$image = $images->item(0); |
$details = array(); |
if ($image->hasChildNodes()) { |
$details = array( |
'title' => $image->getElementsByTagName('title')->item(0)->value, |
'link' => $image->getElementsByTagName('link')->item(0)->value, |
'url' => $image->getElementsByTagName('url')->item(0)->value); |
} else { |
$details = array('title' => false, |
'link' => false, |
'url' => $image->attributes->getNamedItem('resource')->nodeValue); |
} |
$details = array_merge($details, array('description' => false, 'height' => false, 'width' => false)); |
if (! empty($details)) { |
return $details; |
} |
} |
return false; |
} |
/** |
* The textinput element is little used, but in the interests of |
* completeness we will support it. |
* |
* @return array|false |
*/ |
protected function getTextInput() { |
$inputs = $this->model->getElementsByTagName('textinput'); |
if ($inputs->length > 0) { |
$input = $inputs->item(0); |
$results = array(); |
$results['title'] = isset( |
$input->getElementsByTagName('title')->item(0)->value) ? |
$input->getElementsByTagName('title')->item(0)->value : null; |
$results['description'] = isset( |
$input->getElementsByTagName('description')->item(0)->value) ? |
$input->getElementsByTagName('description')->item(0)->value : null; |
$results['name'] = isset( |
$input->getElementsByTagName('name')->item(0)->value) ? |
$input->getElementsByTagName('name')->item(0)->value : null; |
$results['link'] = isset( |
$input->getElementsByTagName('link')->item(0)->value) ? |
$input->getElementsByTagName('link')->item(0)->value : null; |
if (empty($results['link']) and |
$input->attributes->getNamedItem('resource')) { |
$results['link'] = |
$input->attributes->getNamedItem('resource')->nodeValue; |
} |
if (! empty($results)) { |
return $results; |
} |
} |
return false; |
} |
/** |
* Employs various techniques to identify the author |
* |
* Dublin Core provides the dc:creator, dc:contributor, and dc:publisher |
* elements for defining authorship in RSS1. We will try each of those in |
* turn in order to simulate the atom author element and will return it |
* as text. |
* |
* @return array|false |
*/ |
function getAuthor() { |
$options = array('creator', 'contributor', 'publisher'); |
foreach ($options as $element) { |
$test = $this->model->getElementsByTagName($element); |
if ($test->length > 0) { |
return $test->item(0)->value; |
} |
} |
return false; |
} |
/** |
* Retrieve a link |
* |
* In RSS1 a link is a text element but in order to ensure that we resolve |
* URLs properly we have a special function for them. |
* |
* @return string |
*/ |
function getLink($offset = 0, $attribute = 'href', $params = false) { |
$links = $this->model->getElementsByTagName('link'); |
if ($links->length <= $offset) { |
return false; |
} |
$link = $links->item($offset); |
return $this->addBase($link->nodeValue, $link); |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss11.php |
---|
New file |
0,0 → 1,266 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS1.1 class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS11.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/** |
* This class handles RSS1.1 feeds. RSS1.1 is documented at: |
* http://inamidst.com/rss1.1/ |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
* @todo Support for RDF:List |
* @todo Ensure xml:lang is accessible to users |
*/ |
class XmlFeedParserRss11 extends XmlFeedParserType { |
/** |
* The URI of the RelaxNG schema used to (optionally) validate the feed |
* @var string |
*/ |
protected $relax = 'rss11.rng'; |
/** |
* We're likely to use XPath, so let's keep it global |
* @var DOMXPath |
*/ |
protected $xpath; |
/** |
* The feed type we are parsing |
* @var string |
*/ |
public $version = 'RSS 1.0'; |
/** |
* The class used to represent individual items |
* @var string |
*/ |
protected $itemClass = 'XmlFeedParserRss11Element'; |
/** |
* The element containing entries |
* @var string |
*/ |
protected $itemElement = 'item'; |
/** |
* Here we map those elements we're not going to handle individually |
* to the constructs they are. The optional second parameter in the array |
* tells the parser whether to 'fall back' (not apt. at the feed level) or |
* fail if the element is missing. If the parameter is not set, the function |
* will simply return false and leave it to the client to decide what to do. |
* @var array |
*/ |
protected $map = array( |
'title' => array('Text'), |
'link' => array('Text'), |
'description' => array('Text'), |
'image' => array('Image'), |
'updatePeriod' => array('Text'), |
'updateFrequency' => array('Text'), |
'updateBase' => array('Date'), |
'rights' => array('Text'), # dc:rights |
'description' => array('Text'), # dc:description |
'creator' => array('Text'), # dc:creator |
'publisher' => array('Text'), # dc:publisher |
'contributor' => array('Text'), # dc:contributor |
'date' => array('Date') # dc:contributor |
); |
/** |
* Here we map some elements to their atom equivalents. This is going to be |
* quite tricky to pull off effectively (and some users' methods may vary) |
* but is worth trying. The key is the atom version, the value is RSS2. |
* @var array |
*/ |
protected $compatMap = array( |
'title' => array('title'), |
'link' => array('link'), |
'subtitle' => array('description'), |
'author' => array('creator'), |
'updated' => array('date')); |
/** |
* We will be working with multiple namespaces and it is useful to |
* keep them together. We will retain support for some common RSS1.0 modules |
* @var array |
*/ |
protected $namespaces = array( |
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
'rss' => 'http://purl.org/net/rss1.1#', |
'dc' => 'http://purl.org/rss/1.0/modules/dc/', |
'content' => 'http://purl.org/rss/1.0/modules/content/', |
'sy' => 'http://web.resource.org/rss/1.0/modules/syndication/'); |
/** |
* Our constructor does nothing more than its parent. |
* |
* @param DOMDocument $xml A DOM object representing the feed |
* @param bool (optional) $string Whether or not to validate this feed |
*/ |
function __construct(DOMDocument $model, $strict = false) { |
$this->model = $model; |
if ($strict) { |
if (! $this->relaxNGValidate()) { |
throw new XML_Feed_Parser_Exception('Failed required validation'); |
} |
} |
$this->xpath = new DOMXPath($model); |
foreach ($this->namespaces as $key => $value) { |
$this->xpath->registerNamespace($key, $value); |
} |
$this->numberEntries = $this->count('item'); |
} |
/** |
* Attempts to identify an element by ID given by the rdf:about attribute |
* |
* This is not really something that will work with RSS1.1 as it does not have |
* clear restrictions on the global uniqueness of IDs. We will employ the |
* _very_ hit and miss method of selecting entries based on the rdf:about |
* attribute. Please note that this is even more hit and miss with RSS1.1 than |
* with RSS1.0 since RSS1.1 does not require the rdf:about attribute for items. |
* |
* @param string $id any valid ID. |
* @return XML_Feed_Parser_RSS1Element |
*/ |
function getEntryById($id) { |
if (isset($this->idMappings[$id])) { |
return $this->entries[$this->idMappings[$id]]; |
} |
$entries = $this->xpath->query("//rss:item[@rdf:about='$id']"); |
if ($entries->length > 0) { |
$classname = $this->itemClass; |
$entry = new $classname($entries->item(0), $this); |
return $entry; |
} |
return false; |
} |
/** |
* Get details of the image associated with the feed. |
* |
* @return array|false an array simply containing the child elements |
*/ |
protected function getImage() { |
$images = $this->model->getElementsByTagName('image'); |
if ($images->length > 0) { |
$image = $images->item(0); |
$details = array(); |
if ($image->hasChildNodes()) { |
$details = array( |
'title' => $image->getElementsByTagName('title')->item(0)->value, |
'url' => $image->getElementsByTagName('url')->item(0)->value); |
if ($image->getElementsByTagName('link')->length > 0) { |
$details['link'] = |
$image->getElementsByTagName('link')->item(0)->value; |
} |
} else { |
$details = array('title' => false, |
'link' => false, |
'url' => $image->attributes->getNamedItem('resource')->nodeValue); |
} |
$details = array_merge($details, |
array('description' => false, 'height' => false, 'width' => false)); |
if (! empty($details)) { |
return $details; |
} |
} |
return false; |
} |
/** |
* The textinput element is little used, but in the interests of |
* completeness we will support it. |
* |
* @return array|false |
*/ |
protected function getTextInput() { |
$inputs = $this->model->getElementsByTagName('textinput'); |
if ($inputs->length > 0) { |
$input = $inputs->item(0); |
$results = array(); |
$results['title'] = isset( |
$input->getElementsByTagName('title')->item(0)->value) ? |
$input->getElementsByTagName('title')->item(0)->value : null; |
$results['description'] = isset( |
$input->getElementsByTagName('description')->item(0)->value) ? |
$input->getElementsByTagName('description')->item(0)->value : null; |
$results['name'] = isset( |
$input->getElementsByTagName('name')->item(0)->value) ? |
$input->getElementsByTagName('name')->item(0)->value : null; |
$results['link'] = isset( |
$input->getElementsByTagName('link')->item(0)->value) ? |
$input->getElementsByTagName('link')->item(0)->value : null; |
if (empty($results['link']) and |
$input->attributes->getNamedItem('resource')) { |
$results['link'] = $input->attributes->getNamedItem('resource')->nodeValue; |
} |
if (! empty($results)) { |
return $results; |
} |
} |
return false; |
} |
/** |
* Attempts to discern authorship |
* |
* Dublin Core provides the dc:creator, dc:contributor, and dc:publisher |
* elements for defining authorship in RSS1. We will try each of those in |
* turn in order to simulate the atom author element and will return it |
* as text. |
* |
* @return array|false |
*/ |
function getAuthor() { |
$options = array('creator', 'contributor', 'publisher'); |
foreach ($options as $element) { |
$test = $this->model->getElementsByTagName($element); |
if ($test->length > 0) { |
return $test->item(0)->value; |
} |
} |
return false; |
} |
/** |
* Retrieve a link |
* |
* In RSS1 a link is a text element but in order to ensure that we resolve |
* URLs properly we have a special function for them. |
* |
* @return string |
*/ |
function getLink($offset = 0, $attribute = 'href', $params = false) { |
$links = $this->model->getElementsByTagName('link'); |
if ($links->length <= $offset) { |
return false; |
} |
$link = $links->item($offset); |
return $this->addBase($link->nodeValue, $link); |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/widget/modules/photo/bibliotheque/xml_feed_parser/1.0.4/parsers/XmlFeedParserRss09Element.php |
---|
New file |
0,0 → 1,59 |
<?php |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
/** |
* RSS0.9 Element class for XML_Feed_Parser |
* |
* PHP versions 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of |
* the PHP License and are unable to obtain it through the web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category XML |
* @package XML_Feed_Parser |
* @author James Stewart <james@jystewart.net> |
* @copyright 2005 James Stewart <james@jystewart.net> |
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1 |
* @version CVS: $Id: RSS09Element.php 304308 2010-10-11 12:05:50Z clockwerx $ |
* @link http://pear.php.net/package/XML_Feed_Parser/ |
*/ |
/* |
* This class provides support for RSS 0.9 entries. It will usually be called by |
* XML_Feed_Parser_RSS09 with which it shares many methods. |
* |
* @author James Stewart <james@jystewart.net> |
* @version Release: @package_version@ |
* @package XML_Feed_Parser |
*/ |
class XmlFeedParserRss09Element extends XmlFeedParserRss09 { |
/** |
* This will be a reference to the parent object for when we want |
* to use a 'fallback' rule |
* @var XML_Feed_Parser_RSS09 |
*/ |
protected $parent; |
/** |
* Our specific element map |
* @var array |
*/ |
protected $map = array( |
'title' => array('Text'), |
'link' => array('Link')); |
/** |
* Store useful information for later. |
* |
* @param DOMElement $element - this item as a DOM element |
* @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member |
*/ |
function __construct(DOMElement $element, $parent, $xmlBase = '') { |
$this->model = $element; |
$this->parent = $parent; |
} |
} |
?> |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |