Author: chabotc
Date: Mon Jul 20 19:18:07 2009
New Revision: 795961
URL: http://svn.apache.org/viewvc?rev=795961&view=rev
Log:
SHINDIG-1120 by Eiji Kitamura - Fixes RDF parsing
Modified:
incubator/shindig/trunk/php/external/Zend/Feed/Rss.php
Modified: incubator/shindig/trunk/php/external/Zend/Feed/Rss.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/Zend/Feed/Rss.php?rev=795961&r1=795960&r2=795961&view=diff
==============================================================================
--- incubator/shindig/trunk/php/external/Zend/Feed/Rss.php (original)
+++ incubator/shindig/trunk/php/external/Zend/Feed/Rss.php Mon Jul 20 19:18:07
2009
@@ -1,5 +1,4 @@
<?php
-
/**
* Zend Framework
*
@@ -51,14 +50,14 @@
* @var string
*/
protected $_entryClassName = 'Zend_Feed_Entry_Rss';
-
+
/**
* The element name for individual channel elements (RSS <item>s).
*
* @var string
*/
protected $_entryElementName = 'item';
-
+
/**
* The default namespace for RSS channels.
*
@@ -74,17 +73,29 @@
*/
public function __wakeup() {
parent::__wakeup();
-
+
// Find the base channel element and create an alias to it.
- $this->_element =
$this->_element->getElementsByTagName('channel')->item(0);
+ $rdf =
$this->_element->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'RDF')->item(0);
+ if ($rdf) {
+ $this->_element = $rdf;
+ $channel = $this->_element->getElementsByTagName('channel')->item(0);
+ if ($channel->getElementsByTagName('title')->item(0))
+
$this->_element->appendChild($channel->getElementsByTagName('title')->item(0));
+ if ($channel->getElementsByTagName('link')->item(0))
+
$this->_element->appendChild($channel->getElementsByTagName('link')->item(0));
+ if ($channel->getElementsByTagName('description')->item(0))
+
$this->_element->appendChild($channel->getElementsByTagName('description')->item(0));
+ } else {
+ $this->_element =
$this->_element->getElementsByTagName('channel')->item(0);
+ }
if (! $this->_element) {
- /**
+ /**
* @see Zend_Feed_Exception
*/
require_once 'external/Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('No root <channel> element found, cannot
parse channel.');
}
-
+
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
@@ -104,10 +115,10 @@
public function __get($var) {
switch ($var) {
case 'item':
- // fall through to the next case
+ // fall through to the next case
case 'items':
return $this;
-
+
default:
return parent::__get($var);
}
@@ -121,27 +132,27 @@
*/
protected function _mapFeedHeaders($array) {
$channel = $this->_element->createElement('channel');
-
+
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($array->title));
$channel->appendChild($title);
-
+
$link = $this->_element->createElement('link', $array->link);
$channel->appendChild($link);
-
+
$desc = isset($array->description) ? $array->description : '';
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($desc));
$channel->appendChild($description);
-
+
$pubdate = isset($array->lastUpdate) ? $array->lastUpdate : time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r',
$pubdate));
$channel->appendChild($pubdate);
-
+
if (isset($array->published)) {
$lastBuildDate = $this->_element->createElement('lastBuildDate',
gmdate('r', $array->published));
}
-
+
$editor = '';
if (! empty($array->email)) {
$editor .= $array->email;
@@ -156,12 +167,12 @@
if (isset($array->webmaster)) {
$channel->appendChild($this->_element->createElement('webMaster',
$array->webmaster));
}
-
+
if (! empty($array->copyright)) {
$copyright = $this->_element->createElement('copyright',
$array->copyright);
$channel->appendChild($copyright);
}
-
+
if (! empty($array->image)) {
$image = $this->_element->createElement('image');
$url = $this->_element->createElement('url', $array->image);
@@ -170,22 +181,22 @@
$image->appendChild($imagetitle);
$imagelink = $this->_element->createElement('link', $array->link);
$image->appendChild($imagelink);
-
+
$channel->appendChild($image);
}
-
+
$generator = ! empty($array->generator) ? $array->generator : 'Zend_Feed';
$generator = $this->_element->createElement('generator', $generator);
$channel->appendChild($generator);
-
+
if (! empty($array->language)) {
$language = $this->_element->createElement('language', $array->language);
$channel->appendChild($language);
}
-
+
$doc = $this->_element->createElement('docs',
'http://blogs.law.harvard.edu/tech/rss');
$channel->appendChild($doc);
-
+
if (isset($array->cloud)) {
$cloud = $this->_element->createElement('cloud');
$cloud->setAttribute('domain', $array->cloud['uri']->getHost());
@@ -195,12 +206,12 @@
$cloud->setAttribute('protocol', $array->cloud['protocol']);
$channel->appendChild($cloud);
}
-
+
if (isset($array->rating)) {
$rating = $this->_element->createElement('rating', $array->rating);
$channel->appendChild($rating);
}
-
+
if (isset($array->textInput)) {
$textinput = $this->_element->createElement('textInput');
$textinput->appendChild($this->_element->createElement('title',
$array->textInput['title']));
@@ -209,7 +220,7 @@
$textinput->appendChild($this->_element->createElement('link',
$array->textInput['link']));
$channel->appendChild($textinput);
}
-
+
if (isset($array->skipHours)) {
$skipHours = $this->_element->createElement('skipHours');
foreach ($array->skipHours as $hour) {
@@ -217,7 +228,7 @@
}
$channel->appendChild($skipHours);
}
-
+
if (isset($array->skipDays)) {
$skipDays = $this->_element->createElement('skipDays');
foreach ($array->skipDays as $day) {
@@ -225,11 +236,11 @@
}
$channel->appendChild($skipDays);
}
-
+
if (isset($array->itunes)) {
$this->_buildiTunes($channel, $array);
}
-
+
return $channel;
}
@@ -252,7 +263,7 @@
$node =
$this->_element->createElementNS('http://www.itunes.com/DTDs/Podcast-1.0.dtd',
'itunes:author', $author);
$root->appendChild($node);
}
-
+
/* owner node */
$author = '';
$email = '';
@@ -367,36 +378,36 @@
*/
protected function _mapFeedEntries(DOMElement $root, $array) {
Zend_Feed::registerNamespace('content',
'http://purl.org/rss/1.0/modules/content/');
-
+
foreach ($array as $dataentry) {
$item = $this->_element->createElement('item');
-
+
$title = $this->_element->createElement('title');
$title->appendChild($this->_element->createCDATASection($dataentry->title));
$item->appendChild($title);
-
+
$link = $this->_element->createElement('link', $dataentry->link);
$item->appendChild($link);
-
+
if (isset($dataentry->guid)) {
$guid = $this->_element->createElement('guid', $dataentry->guid);
$item->appendChild($guid);
}
-
+
$description = $this->_element->createElement('description');
$description->appendChild($this->_element->createCDATASection($dataentry->description));
$item->appendChild($description);
-
+
if (isset($dataentry->content)) {
$content = $this->_element->createElement('content:encoded');
$content->appendChild($this->_element->createCDATASection($dataentry->content));
$item->appendChild($content);
}
-
+
$pubdate = isset($dataentry->lastUpdate) ? $dataentry->lastUpdate :
time();
$pubdate = $this->_element->createElement('pubDate', gmdate('r',
$pubdate));
$item->appendChild($pubdate);
-
+
if (isset($dataentry->category)) {
foreach ($dataentry->category as $category) {
$node = $this->_element->createElement('category',
$category['term']);
@@ -406,13 +417,13 @@
$item->appendChild($node);
}
}
-
+
if (isset($dataentry->source)) {
$source = $this->_element->createElement('source',
$dataentry->source['title']);
$source->setAttribute('url', $dataentry->source['url']);
$item->appendChild($source);
}
-
+
if (isset($dataentry->comments)) {
$comments = $this->_element->createElement('comments',
$dataentry->comments);
$item->appendChild($comments);
@@ -421,7 +432,7 @@
$comments =
$this->_element->createElementNS('http://wellformedweb.org/CommentAPI/',
'wfw:commentRss', $dataentry->commentRss);
$item->appendChild($comments);
}
-
+
if (isset($dataentry->enclosure)) {
foreach ($dataentry->enclosure as $enclosure) {
$node = $this->_element->createElement('enclosure');
@@ -435,7 +446,7 @@
$item->appendChild($node);
}
}
-
+
$root->appendChild($item);
}
}
@@ -449,20 +460,20 @@
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$root = $doc->createElement('rss');
-
+
// Use rss version 2.0
$root->setAttribute('version', '2.0');
-
+
// Content namespace
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:content',
'http://purl.org/rss/1.0/modules/content/');
$root->appendChild($doc->importNode($this->_element, true));
-
+
// Append root node
$doc->appendChild($root);
-
+
// Format output
$doc->formatOutput = true;
-
+
return $doc->saveXML();
}
@@ -474,15 +485,15 @@
*/
public function send() {
if (headers_sent()) {
- /**
+ /**
* @see Zend_Feed_Exception
*/
require_once 'external/Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Cannot send RSS because headers have
already been sent.');
}
-
+
header('Content-type: application/rss+xml; charset: ' .
$this->_element->ownerDocument->actualEncoding);
-
+
echo $this->saveXml();
}