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 / Extension / Syndication / Feed.php
blobae659d64f7a3fab3b0187d7b4d2ea76f27590bd3
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\Extension\Syndication;
12 use DateTime;
13 use Zend\Feed\Reader;
14 use Zend\Feed\Reader\Extension;
16 class Feed extends Extension\AbstractFeed
18 /**
19 * Get update period
21 * @return string
22 * @throws Reader\Exception\InvalidArgumentException
24 public function getUpdatePeriod()
26 $name = 'updatePeriod';
27 $period = $this->_getData($name);
29 if ($period === null) {
30 $this->data[$name] = 'daily';
31 return 'daily'; //Default specified by spec
34 switch ($period) {
35 case 'hourly':
36 case 'daily':
37 case 'weekly':
38 case 'yearly':
39 return $period;
40 default:
41 throw new Reader\Exception\InvalidArgumentException("Feed specified invalid update period: '$period'."
42 . " Must be one of hourly, daily, weekly or yearly"
47 /**
48 * Get update frequency
50 * @return int
52 public function getUpdateFrequency()
54 $name = 'updateFrequency';
55 $freq = $this->_getData($name, 'number');
57 if (!$freq || $freq < 1) {
58 $this->data[$name] = 1;
59 return 1;
62 return $freq;
65 /**
66 * Get update frequency as ticks
68 * @return int
70 public function getUpdateFrequencyAsTicks()
72 $name = 'updateFrequency';
73 $freq = $this->_getData($name, 'number');
75 if (!$freq || $freq < 1) {
76 $this->data[$name] = 1;
77 $freq = 1;
80 $period = $this->getUpdatePeriod();
81 $ticks = 1;
83 switch ($period) {
84 case 'yearly':
85 $ticks *= 52; //TODO: fix generalisation, how?
86 // no break
87 case 'weekly':
88 $ticks *= 7;
89 // no break
90 case 'daily':
91 $ticks *= 24;
92 // no break
93 case 'hourly':
94 $ticks *= 3600;
95 break;
96 default: //Never arrive here, exception thrown in getPeriod()
97 break;
100 return $ticks / $freq;
104 * Get update base
106 * @return DateTime|null
108 public function getUpdateBase()
110 $updateBase = $this->_getData('updateBase');
111 $date = null;
112 if ($updateBase) {
113 $date = DateTime::createFromFormat(DateTime::W3C, $updateBase);
115 return $date;
119 * Get the entry data specified by name
121 * @param string $name
122 * @param string $type
123 * @return mixed|null
125 private function _getData($name, $type = 'string')
127 if (array_key_exists($name, $this->data)) {
128 return $this->data[$name];
131 $data = $this->xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')');
133 if (!$data) {
134 $data = null;
137 $this->data[$name] = $data;
139 return $data;
143 * Register Syndication namespaces
145 * @return void
147 protected function registerNamespaces()
149 $this->xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/');