Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-feed/src/Reader/Extension/Syndication/Feed.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Zend Framework (http://framework.zend.com/) | |
4 * | |
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 */ | |
9 | |
10 namespace Zend\Feed\Reader\Extension\Syndication; | |
11 | |
12 use DateTime; | |
13 use Zend\Feed\Reader; | |
14 use Zend\Feed\Reader\Extension; | |
15 | |
16 class Feed extends Extension\AbstractFeed | |
17 { | |
18 /** | |
19 * Get update period | |
20 * | |
21 * @return string | |
22 * @throws Reader\Exception\InvalidArgumentException | |
23 */ | |
24 public function getUpdatePeriod() | |
25 { | |
26 $name = 'updatePeriod'; | |
27 $period = $this->getData($name); | |
28 | |
29 if ($period === null) { | |
30 $this->data[$name] = 'daily'; | |
31 return 'daily'; //Default specified by spec | |
32 } | |
33 | |
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" | |
43 ); | |
44 } | |
45 } | |
46 | |
47 /** | |
48 * Get update frequency | |
49 * | |
50 * @return int | |
51 */ | |
52 public function getUpdateFrequency() | |
53 { | |
54 $name = 'updateFrequency'; | |
55 $freq = $this->getData($name, 'number'); | |
56 | |
57 if (!$freq || $freq < 1) { | |
58 $this->data[$name] = 1; | |
59 return 1; | |
60 } | |
61 | |
62 return $freq; | |
63 } | |
64 | |
65 /** | |
66 * Get update frequency as ticks | |
67 * | |
68 * @return int | |
69 */ | |
70 public function getUpdateFrequencyAsTicks() | |
71 { | |
72 $name = 'updateFrequency'; | |
73 $freq = $this->getData($name, 'number'); | |
74 | |
75 if (!$freq || $freq < 1) { | |
76 $this->data[$name] = 1; | |
77 $freq = 1; | |
78 } | |
79 | |
80 $period = $this->getUpdatePeriod(); | |
81 $ticks = 1; | |
82 | |
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; | |
98 } | |
99 | |
100 return $ticks / $freq; | |
101 } | |
102 | |
103 /** | |
104 * Get update base | |
105 * | |
106 * @return DateTime|null | |
107 */ | |
108 public function getUpdateBase() | |
109 { | |
110 $updateBase = $this->getData('updateBase'); | |
111 $date = null; | |
112 if ($updateBase) { | |
113 $date = DateTime::createFromFormat(DateTime::W3C, $updateBase); | |
114 } | |
115 return $date; | |
116 } | |
117 | |
118 /** | |
119 * Get the entry data specified by name | |
120 * | |
121 * @param string $name | |
122 * @param string $type | |
123 * @return mixed|null | |
124 */ | |
125 private function getData($name, $type = 'string') | |
126 { | |
127 if (array_key_exists($name, $this->data)) { | |
128 return $this->data[$name]; | |
129 } | |
130 | |
131 $data = $this->xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')'); | |
132 | |
133 if (!$data) { | |
134 $data = null; | |
135 } | |
136 | |
137 $this->data[$name] = $data; | |
138 | |
139 return $data; | |
140 } | |
141 | |
142 /** | |
143 * Register Syndication namespaces | |
144 * | |
145 * @return void | |
146 */ | |
147 protected function registerNamespaces() | |
148 { | |
149 $this->xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/'); | |
150 } | |
151 } |