|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Validate |
|
17 * @subpackage Sitemap |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Loc.php 22668 2010-07-25 14:50:46Z thomas $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Validate_Abstract |
|
25 */ |
|
26 require_once 'Zend/Validate/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * @see Zend_Uri |
|
30 */ |
|
31 require_once 'Zend/Uri.php'; |
|
32 |
|
33 /** |
|
34 * Validates whether a given value is valid as a sitemap <loc> value |
|
35 * |
|
36 * @link http://www.sitemaps.org/protocol.php Sitemaps XML format |
|
37 * |
|
38 * @category Zend |
|
39 * @package Zend_Validate |
|
40 * @subpackage Sitemap |
|
41 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
42 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
43 */ |
|
44 class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract |
|
45 { |
|
46 /** |
|
47 * Validation key for not valid |
|
48 * |
|
49 */ |
|
50 const NOT_VALID = 'sitemapLocNotValid'; |
|
51 const INVALID = 'sitemapLocInvalid'; |
|
52 |
|
53 /** |
|
54 * Validation failure message template definitions |
|
55 * |
|
56 * @var array |
|
57 */ |
|
58 protected $_messageTemplates = array( |
|
59 self::NOT_VALID => "'%value%' is no valid sitemap location", |
|
60 self::INVALID => "Invalid type given. String expected", |
|
61 ); |
|
62 |
|
63 /** |
|
64 * Validates if a string is valid as a sitemap location |
|
65 * |
|
66 * @link http://www.sitemaps.org/protocol.php#locdef <loc> |
|
67 * |
|
68 * @param string $value value to validate |
|
69 * @return boolean |
|
70 */ |
|
71 public function isValid($value) |
|
72 { |
|
73 if (!is_string($value)) { |
|
74 $this->_error(self::INVALID); |
|
75 return false; |
|
76 } |
|
77 |
|
78 $this->_setValue($value); |
|
79 $result = Zend_Uri::check($value); |
|
80 if ($result !== true) { |
|
81 $this->_error(self::NOT_VALID); |
|
82 return false; |
|
83 } |
|
84 |
|
85 return true; |
|
86 } |
|
87 } |