diff -r 000000000000 -r 4eba9c11703f web/Zend/Feed/Reader/FeedSet.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/Zend/Feed/Reader/FeedSet.php Mon Dec 13 18:29:26 2010 +0100 @@ -0,0 +1,148 @@ +getAttribute('rel')) !== 'alternate' + || !$link->getAttribute('type') || !$link->getAttribute('href')) { + continue; + } + if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') { + $this->rss = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri); + } elseif(!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') { + $this->atom = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri); + } elseif(!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') { + $this->rdf = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri); + } + $this[] = new self(array( + 'rel' => 'alternate', + 'type' => $link->getAttribute('type'), + 'href' => $this->_absolutiseUri(trim($link->getAttribute('href')), $uri), + )); + } + } + + /** + * Attempt to turn a relative URI into an absolute URI + */ + protected function _absolutiseUri($link, $uri = null) + { + if (!Zend_Uri::check($link)) { + if ($uri !== null) { + $uri = Zend_Uri::factory($uri); + + if ($link[0] !== '/') { + $link = $uri->getPath() . '/' . $link; + } + + $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link); + if (!Zend_Uri::check($link)) { + $link = null; + } + } + } + return $link; + } + + /** + * Canonicalize relative path + */ + protected function _canonicalizePath($path) + { + $parts = array_filter(explode('/', $path)); + $absolutes = array(); + foreach ($parts as $part) { + if ('.' == $part) { + continue; + } + if ('..' == $part) { + array_pop($absolutes); + } else { + $absolutes[] = $part; + } + } + return implode('/', $absolutes); + } + + /** + * Supports lazy loading of feeds using Zend_Feed_Reader::import() but + * delegates any other operations to the parent class. + * + * @param string $offset + * @return mixed + * @uses Zend_Feed_Reader + */ + public function offsetGet($offset) + { + if ($offset == 'feed' && !$this->offsetExists('feed')) { + if (!$this->offsetExists('href')) { + return null; + } + $feed = Zend_Feed_Reader::import($this->offsetGet('href')); + $this->offsetSet('feed', $feed); + return $feed; + } + return parent::offsetGet($offset); + } + +}