Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Reader / FeedSet.php
blobc9476208d28cdc02744c485c67a9b68ba47a8a64
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Feed\Reader;
12 use ArrayObject;
13 use DOMNodeList;
14 use Zend\Feed\Uri;
16 /**
18 class FeedSet extends ArrayObject
21 public $rss = null;
23 public $rdf = null;
25 public $atom = null;
27 /**
28 * Import a DOMNodeList from any document containing a set of links
29 * for alternate versions of a document, which will normally refer to
30 * RSS/RDF/Atom feeds for the current document.
32 * All such links are stored internally, however the first instance of
33 * each RSS, RDF or Atom type has its URI stored as a public property
34 * as a shortcut where the use case is simply to get a quick feed ref.
36 * Note that feeds are not loaded at this point, but will be lazy
37 * loaded automatically when each links 'feed' array key is accessed.
39 * @param DOMNodeList $links
40 * @param string $uri
41 * @return void
43 public function addLinks(DOMNodeList $links, $uri)
45 foreach ($links as $link) {
46 if (strtolower($link->getAttribute('rel')) !== 'alternate'
47 || !$link->getAttribute('type') || !$link->getAttribute('href')) {
48 continue;
50 if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') {
51 $this->rss = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
52 } elseif (!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') {
53 $this->atom = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
54 } elseif (!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') {
55 $this->rdf = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
57 $this[] = new static(array(
58 'rel' => 'alternate',
59 'type' => $link->getAttribute('type'),
60 'href' => $this->absolutiseUri(trim($link->getAttribute('href')), $uri),
61 ));
65 /**
66 * Attempt to turn a relative URI into an absolute URI
68 protected function absolutiseUri($link, $uri = null)
70 $linkUri = Uri::factory($link);
71 if (!$linkUri->isAbsolute() or !$linkUri->isValid()) {
72 if ($uri !== null) {
73 $uri = Uri::factory($uri);
75 if ($link[0] !== '/') {
76 $link = $uri->getPath() . '/' . $link;
79 $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->canonicalizePath($link);
80 if (!Uri::factory($link)->isValid()) {
81 $link = null;
85 return $link;
88 /**
89 * Canonicalize relative path
91 protected function canonicalizePath($path)
93 $parts = array_filter(explode('/', $path));
94 $absolutes = array();
95 foreach ($parts as $part) {
96 if ('.' == $part) {
97 continue;
99 if ('..' == $part) {
100 array_pop($absolutes);
101 } else {
102 $absolutes[] = $part;
105 return implode('/', $absolutes);
109 * Supports lazy loading of feeds using Reader::import() but
110 * delegates any other operations to the parent class.
112 * @param string $offset
113 * @return mixed
115 public function offsetGet($offset)
117 if ($offset == 'feed' && !$this->offsetExists('feed')) {
118 if (!$this->offsetExists('href')) {
119 return null;
121 $feed = Reader::import($this->offsetGet('href'));
122 $this->offsetSet('feed', $feed);
123 return $feed;
125 return parent::offsetGet($offset);