File indexing completed on 2025-01-19 05:21:05
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Feed_Reader 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Feed_Reader_Extension_FeedAbstract 0024 */ 0025 // require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; 0026 0027 // require_once 'Zend/Date.php'; 0028 0029 /** 0030 * @category Zend 0031 * @package Zend_Feed_Reader 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Feed_Reader_Extension_Syndication_Feed 0036 extends Zend_Feed_Reader_Extension_FeedAbstract 0037 { 0038 /** 0039 * Get update period 0040 * @return string 0041 */ 0042 public function getUpdatePeriod() 0043 { 0044 $name = 'updatePeriod'; 0045 $period = $this->_getData($name); 0046 0047 if ($period === null) { 0048 $this->_data[$name] = 'daily'; 0049 return 'daily'; //Default specified by spec 0050 } 0051 0052 switch ($period) 0053 { 0054 case 'hourly': 0055 case 'daily': 0056 case 'weekly': 0057 case 'yearly': 0058 return $period; 0059 default: 0060 throw new Zend_Feed_Exception("Feed specified invalid update period: '$period'." 0061 . " Must be one of hourly, daily, weekly or yearly" 0062 ); 0063 } 0064 } 0065 0066 /** 0067 * Get update frequency 0068 * @return int 0069 */ 0070 public function getUpdateFrequency() 0071 { 0072 $name = 'updateFrequency'; 0073 $freq = $this->_getData($name, 'number'); 0074 0075 if (!$freq || $freq < 1) { 0076 $this->_data[$name] = 1; 0077 return 1; 0078 } 0079 0080 return $freq; 0081 } 0082 0083 /** 0084 * Get update frequency as ticks 0085 * @return int 0086 */ 0087 public function getUpdateFrequencyAsTicks() 0088 { 0089 $name = 'updateFrequency'; 0090 $freq = $this->_getData($name, 'number'); 0091 0092 if (!$freq || $freq < 1) { 0093 $this->_data[$name] = 1; 0094 $freq = 1; 0095 } 0096 0097 $period = $this->getUpdatePeriod(); 0098 $ticks = 1; 0099 0100 switch ($period) 0101 { 0102 //intentional fall through 0103 case 'yearly': 0104 $ticks *= 52; //TODO: fix generalisation, how? 0105 case 'weekly': 0106 $ticks *= 7; 0107 case 'daily': 0108 $ticks *= 24; 0109 case 'hourly': 0110 $ticks *= 3600; 0111 break; 0112 default: //Never arrive here, exception thrown in getPeriod() 0113 break; 0114 } 0115 0116 return $ticks / $freq; 0117 } 0118 0119 /** 0120 * Get update base 0121 * 0122 * @return Zend_Date|null 0123 */ 0124 public function getUpdateBase() 0125 { 0126 $updateBase = $this->_getData('updateBase'); 0127 $date = null; 0128 if ($updateBase) { 0129 $date = new Zend_Date; 0130 $date->set($updateBase, Zend_Date::W3C); 0131 } 0132 return $date; 0133 } 0134 0135 /** 0136 * Get the entry data specified by name 0137 * 0138 * @param string $name 0139 * @param string $type 0140 * @return mixed|null 0141 */ 0142 private function _getData($name, $type = 'string') 0143 { 0144 if (array_key_exists($name, $this->_data)) { 0145 return $this->_data[$name]; 0146 } 0147 0148 $data = $this->_xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')'); 0149 0150 if (!$data) { 0151 $data = null; 0152 } 0153 0154 $this->_data[$name] = $data; 0155 0156 return $data; 0157 } 0158 0159 /** 0160 * Register Syndication namespaces 0161 * 0162 * @return void 0163 */ 0164 protected function _registerNamespaces() 0165 { 0166 $this->_xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/'); 0167 } 0168 }