File indexing completed on 2024-06-16 05:30:33

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 <lastmod> 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_Lastmod extends Zend_Validate_Abstract
0040 {
0041     /**
0042      * Regular expression to use when validating
0043      *
0044      */
0045     const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9])(:[0-5][0-9])?(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/';
0046 
0047     /**
0048      * Validation key for not valid
0049      *
0050      */
0051     const NOT_VALID = 'sitemapLastmodNotValid';
0052     const INVALID   = 'sitemapLastmodInvalid';
0053 
0054     /**
0055      * Validation failure message template definitions
0056      *
0057      * @var array
0058      */
0059     protected $_messageTemplates = array(
0060         self::NOT_VALID => "'%value%' is not a valid sitemap lastmod",
0061         self::INVALID   => "Invalid type given. String expected",
0062     );
0063 
0064     /**
0065      * Validates if a string is valid as a sitemap lastmod
0066      *
0067      * @link http://www.sitemaps.org/protocol.php#lastmoddef <lastmod>
0068      *
0069      * @param  string  $value  value to validate
0070      * @return boolean
0071      */
0072     public function isValid($value)
0073     {
0074         if (!is_string($value)) {
0075             $this->_error(self::INVALID);
0076             return false;
0077         }
0078 
0079         $this->_setValue($value);
0080         $result = @preg_match(self::LASTMOD_REGEX, $value);
0081         if ($result != 1) {
0082             $this->_error(self::NOT_VALID);
0083             return false;
0084         }
0085 
0086         return true;
0087     }
0088 }