File indexing completed on 2025-01-19 05:21:38
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_Validate 0017 * @subpackage Sitemap 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Validate_Abstract 0025 */ 0026 // require_once 'Zend/Validate/Abstract.php'; 0027 0028 /** 0029 * Validates whether a given value is valid as a sitemap <changefreq> value 0030 * 0031 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 0032 * 0033 * @category Zend 0034 * @package Zend_Validate 0035 * @subpackage Sitemap 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract 0040 { 0041 /** 0042 * Validation key for not valid 0043 * 0044 */ 0045 const NOT_VALID = 'sitemapChangefreqNotValid'; 0046 const INVALID = 'sitemapChangefreqInvalid'; 0047 0048 /** 0049 * Validation failure message template definitions 0050 * 0051 * @var array 0052 */ 0053 protected $_messageTemplates = array( 0054 self::NOT_VALID => "'%value%' is not a valid sitemap changefreq", 0055 self::INVALID => "Invalid type given. String expected", 0056 ); 0057 0058 /** 0059 * Valid change frequencies 0060 * 0061 * @var array 0062 */ 0063 protected $_changeFreqs = array( 0064 'always', 'hourly', 'daily', 'weekly', 0065 'monthly', 'yearly', 'never' 0066 ); 0067 0068 /** 0069 * Validates if a string is valid as a sitemap changefreq 0070 * 0071 * @link http://www.sitemaps.org/protocol.php#changefreqdef <changefreq> 0072 * 0073 * @param string $value value to validate 0074 * @return boolean 0075 */ 0076 public function isValid($value) 0077 { 0078 if (!is_string($value)) { 0079 $this->_error(self::INVALID); 0080 return false; 0081 } 0082 0083 $this->_setValue($value); 0084 if (!is_string($value)) { 0085 return false; 0086 } 0087 0088 if (!in_array($value, $this->_changeFreqs, true)) { 0089 $this->_error(self::NOT_VALID); 0090 return false; 0091 } 0092 0093 return true; 0094 } 0095 }