db backup prior to drupal security update
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / Extension / Syndication / Feed.php
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      * Get update frequency
48      *
49      * @return int
50      */
51     public function getUpdateFrequency()
52     {
53         $name = 'updateFrequency';
54         $freq = $this->getData($name, 'number');
55
56         if (! $freq || $freq < 1) {
57             $this->data[$name] = 1;
58             return 1;
59         }
60
61         return $freq;
62     }
63
64     /**
65      * Get update frequency as ticks
66      *
67      * @return int
68      */
69     public function getUpdateFrequencyAsTicks()
70     {
71         $name = 'updateFrequency';
72         $freq = $this->getData($name, 'number');
73
74         if (! $freq || $freq < 1) {
75             $this->data[$name] = 1;
76             $freq = 1;
77         }
78
79         $period = $this->getUpdatePeriod();
80         $ticks = 1;
81
82         switch ($period) {
83             case 'yearly':
84                 $ticks *= 52; //TODO: fix generalisation, how?
85                 // no break
86             case 'weekly':
87                 $ticks *= 7;
88                 // no break
89             case 'daily':
90                 $ticks *= 24;
91                 // no break
92             case 'hourly':
93                 $ticks *= 3600;
94                 break;
95             default: //Never arrive here, exception thrown in getPeriod()
96                 break;
97         }
98
99         return $ticks / $freq;
100     }
101
102     /**
103      * Get update base
104      *
105      * @return DateTime|null
106      */
107     public function getUpdateBase()
108     {
109         $updateBase = $this->getData('updateBase');
110         $date = null;
111         if ($updateBase) {
112             $date = DateTime::createFromFormat(DateTime::W3C, $updateBase);
113         }
114         return $date;
115     }
116
117     /**
118      * Get the entry data specified by name
119      *
120      * @param string $name
121      * @param string $type
122      * @return mixed|null
123      */
124     private function getData($name, $type = 'string')
125     {
126         if (array_key_exists($name, $this->data)) {
127             return $this->data[$name];
128         }
129
130         $data = $this->xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')');
131
132         if (! $data) {
133             $data = null;
134         }
135
136         $this->data[$name] = $data;
137
138         return $data;
139     }
140
141     /**
142      * Register Syndication namespaces
143      *
144      * @return void
145      */
146     protected function registerNamespaces()
147     {
148         $this->xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/');
149     }
150 }