fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Reader / FeedSet.php
blob8fab2cbae8e0fdb611aded67d9ba181670739d3f
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-2015 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
20 public $rss = null;
22 public $rdf = null;
24 public $atom = null;
26 /**
27 * Import a DOMNodeList from any document containing a set of links
28 * for alternate versions of a document, which will normally refer to
29 * RSS/RDF/Atom feeds for the current document.
31 * All such links are stored internally, however the first instance of
32 * each RSS, RDF or Atom type has its URI stored as a public property
33 * as a shortcut where the use case is simply to get a quick feed ref.
35 * Note that feeds are not loaded at this point, but will be lazy
36 * loaded automatically when each links 'feed' array key is accessed.
38 * @param DOMNodeList $links
39 * @param string $uri
40 * @return void
42 public function addLinks(DOMNodeList $links, $uri)
44 foreach ($links as $link) {
45 if (strtolower($link->getAttribute('rel')) !== 'alternate'
46 || !$link->getAttribute('type') || !$link->getAttribute('href')) {
47 continue;
49 if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') {
50 $this->rss = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
51 } elseif (!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') {
52 $this->atom = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
53 } elseif (!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') {
54 $this->rdf = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
56 $this[] = new static(array(
57 'rel' => 'alternate',
58 'type' => $link->getAttribute('type'),
59 'href' => $this->absolutiseUri(trim($link->getAttribute('href')), $uri),
60 ));
64 /**
65 * Attempt to turn a relative URI into an absolute URI
67 protected function absolutiseUri($link, $uri = null)
69 $linkUri = Uri::factory($link);
70 if (!$linkUri->isAbsolute() or !$linkUri->isValid()) {
71 if ($uri !== null) {
72 $uri = Uri::factory($uri);
74 if ($link[0] !== '/') {
75 $link = $uri->getPath() . '/' . $link;
78 $link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->canonicalizePath($link);
79 if (!Uri::factory($link)->isValid()) {
80 $link = null;
84 return $link;
87 /**
88 * Canonicalize relative path
90 protected function canonicalizePath($path)
92 $parts = array_filter(explode('/', $path));
93 $absolutes = array();
94 foreach ($parts as $part) {
95 if ('.' == $part) {
96 continue;
98 if ('..' == $part) {
99 array_pop($absolutes);
100 } else {
101 $absolutes[] = $part;
104 return implode('/', $absolutes);
108 * Supports lazy loading of feeds using Reader::import() but
109 * delegates any other operations to the parent class.
111 * @param string $offset
112 * @return mixed
114 public function offsetGet($offset)
116 if ($offset == 'feed' && !$this->offsetExists('feed')) {
117 if (!$this->offsetExists('href')) {
118 return;
120 $feed = Reader::import($this->offsetGet('href'));
121 $this->offsetSet('feed', $feed);
122 return $feed;
124 return parent::offsetGet($offset);