Development

/branches/1.0/lib/validator/sfHtmlValidator.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/validator/sfHtmlValidator.class.php

Revision 7791, 1.7 kB (checked in by fabien, 6 years ago)

updated Sean Kerr email address

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @author     Sean Kerr <sean@code-box.org>
18  * @version    SVN: $Id$
19  */
20 class sfHtmlValidator extends sfValidator
21 {
22   /**
23    * Executes this validator.
24    *
25    * @param mixed A file or parameter value/array
26    * @param error An error message reference
27    *
28    * @return bool true, if this validator executes successfully, otherwise false
29    */
30   public function execute(&$value, &$error)
31   {
32     if (trim(strip_tags($value)) == '')
33     {
34       // If page contains an object or an image, it's ok
35       if (preg_match('/<img/i', $value) || preg_match('/<object/i', $value))
36         return true;
37       else
38       {
39         $error = $this->getParameterHolder()->get('html_error');
40         return false;
41       }
42     }
43
44     return true;
45   }
46
47   /**
48    * Initializes this validator.
49    *
50    * @param sfContext The current application context
51    * @param array   An associative array of initialization parameters
52    *
53    * @return bool true, if initialization completes successfully, otherwise false
54    */
55   public function initialize($context, $parameters = null)
56   {
57     // initialize parent
58     parent::initialize($context);
59
60     // set defaults
61     $this->getParameterHolder()->set('html_error', 'Invalid input');
62
63     $this->getParameterHolder()->add($parameters);
64
65     return true;
66   }
67 }
68
Note: See TracBrowser for help on using the browser.