File indexing completed on 2024-12-22 05:37:12

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  * @see Zend_Uri
0030  */
0031 // require_once 'Zend/Uri.php';
0032 
0033 /**
0034  * Validates whether a given value is valid as a sitemap <loc> value
0035  *
0036  * @link       http://www.sitemaps.org/protocol.php Sitemaps XML format
0037  *
0038  * @category   Zend
0039  * @package    Zend_Validate
0040  * @subpackage Sitemap
0041  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0042  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0043  */
0044 class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract
0045 {
0046     /**
0047      * Validation key for not valid
0048      *
0049      */
0050     const NOT_VALID = 'sitemapLocNotValid';
0051     const INVALID   = 'sitemapLocInvalid';
0052 
0053     /**
0054      * Validation failure message template definitions
0055      *
0056      * @var array
0057      */
0058     protected $_messageTemplates = array(
0059         self::NOT_VALID => "'%value%' is not a valid sitemap location",
0060         self::INVALID   => "Invalid type given. String expected",
0061     );
0062 
0063     /**
0064      * Validates if a string is valid as a sitemap location
0065      *
0066      * @link http://www.sitemaps.org/protocol.php#locdef <loc>
0067      *
0068      * @param  string  $value  value to validate
0069      * @return boolean
0070      */
0071     public function isValid($value)
0072     {
0073         if (!is_string($value)) {
0074             $this->_error(self::INVALID);
0075             return false;
0076         }
0077 
0078         $this->_setValue($value);
0079         $result = Zend_Uri::check($value);
0080         if ($result !== true) {
0081             $this->_error(self::NOT_VALID);
0082             return false;
0083         }
0084 
0085         return true;
0086     }
0087 }