diff options
author | johmathe <johmathe@google.com> | 2008-04-11 17:38:22 +0400 |
---|---|---|
committer | johmathe <johmathe@google.com> | 2008-04-11 17:38:22 +0400 |
commit | d4f405b6550da50a4cb67b5b78a05f2117f56f2a (patch) | |
tree | 74d20e97ca1972049051ca40db57bbbb7d59b9dc /libs/HTML/QuickForm/Rule | |
parent | 333c624afd1493d7b7ec61896190a2c1d1aada67 (diff) |
Convert txt files to unix format
git-svn-id: http://dev.piwik.org/svn/trunk@444 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/HTML/QuickForm/Rule')
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Callback.php | 246 | ||||
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Compare.php | 210 | ||||
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Email.php | 144 | ||||
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Range.php | 148 | ||||
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Regex.php | 200 | ||||
-rwxr-xr-x | libs/HTML/QuickForm/Rule/Required.php | 126 |
6 files changed, 537 insertions, 537 deletions
diff --git a/libs/HTML/QuickForm/Rule/Callback.php b/libs/HTML/QuickForm/Rule/Callback.php index e35b79f223..d5dec846a6 100755 --- a/libs/HTML/QuickForm/Rule/Callback.php +++ b/libs/HTML/QuickForm/Rule/Callback.php @@ -1,124 +1,124 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Validates values using callback functions or methods
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Validates values using callback functions or methods
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule
-{
- /**
- * Array of callbacks
- *
- * Array is in the format:
- * $_data['rulename'] = array('functionname', 'classname');
- * If the callback is not a method, then the class name is not set.
- *
- * @var array
- * @access private
- */
- var $_data = array();
-
- /**
- * Whether to use BC mode for specific rules
- *
- * Previous versions of QF passed element's name as a first parameter
- * to validation functions, but not to validation methods. This behaviour
- * is emulated if you are using 'function' as rule type when registering.
- *
- * @var array
- * @access private
- */
- var $_BCMode = array();
-
- /**
- * Validates a value using a callback
- *
- * @param string $value Value to be checked
- * @param mixed $options Options for callback
- * @access public
- * @return boolean true if value is valid
- */
- function validate($value, $options = null)
- {
- if (isset($this->_data[$this->name])) {
- $callback = $this->_data[$this->name];
- if (isset($callback[1])) {
- return call_user_func(array($callback[1], $callback[0]), $value, $options);
- } elseif ($this->_BCMode[$this->name]) {
- return $callback[0]('', $value, $options);
- } else {
- return $callback[0]($value, $options);
- }
- } elseif (is_callable($options)) {
- return call_user_func($options, $value);
- } else {
- return true;
- }
- } // end func validate
-
- /**
- * Adds new callbacks to the callbacks list
- *
- * @param string $name Name of rule
- * @param string $callback Name of function or method
- * @param string $class Name of class containing the method
- * @param bool $BCMode Backwards compatibility mode
- * @access public
- */
- function addData($name, $callback, $class = null, $BCMode = false)
- {
- if (!empty($class)) {
- $this->_data[$name] = array($callback, $class);
- } else {
- $this->_data[$name] = array($callback);
- }
- $this->_BCMode[$name] = $BCMode;
- } // end func addData
-
-
- function getValidationScript($options = null)
- {
- if (isset($this->_data[$this->name])) {
- $callback = $this->_data[$this->name][0];
- $params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') .
- (isset($options)? ", '{$options}'": '');
- } else {
- $callback = is_array($options)? $options[1]: $options;
- $params = '{jsVar}';
- }
- return array('', "{jsVar} != '' && !{$callback}({$params})");
- } // end func getValidationScript
-
-} // end class HTML_QuickForm_Rule_Callback
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Validates values using callback functions or methods + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Validates values using callback functions or methods + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule +{ + /** + * Array of callbacks + * + * Array is in the format: + * $_data['rulename'] = array('functionname', 'classname'); + * If the callback is not a method, then the class name is not set. + * + * @var array + * @access private + */ + var $_data = array(); + + /** + * Whether to use BC mode for specific rules + * + * Previous versions of QF passed element's name as a first parameter + * to validation functions, but not to validation methods. This behaviour + * is emulated if you are using 'function' as rule type when registering. + * + * @var array + * @access private + */ + var $_BCMode = array(); + + /** + * Validates a value using a callback + * + * @param string $value Value to be checked + * @param mixed $options Options for callback + * @access public + * @return boolean true if value is valid + */ + function validate($value, $options = null) + { + if (isset($this->_data[$this->name])) { + $callback = $this->_data[$this->name]; + if (isset($callback[1])) { + return call_user_func(array($callback[1], $callback[0]), $value, $options); + } elseif ($this->_BCMode[$this->name]) { + return $callback[0]('', $value, $options); + } else { + return $callback[0]($value, $options); + } + } elseif (is_callable($options)) { + return call_user_func($options, $value); + } else { + return true; + } + } // end func validate + + /** + * Adds new callbacks to the callbacks list + * + * @param string $name Name of rule + * @param string $callback Name of function or method + * @param string $class Name of class containing the method + * @param bool $BCMode Backwards compatibility mode + * @access public + */ + function addData($name, $callback, $class = null, $BCMode = false) + { + if (!empty($class)) { + $this->_data[$name] = array($callback, $class); + } else { + $this->_data[$name] = array($callback); + } + $this->_BCMode[$name] = $BCMode; + } // end func addData + + + function getValidationScript($options = null) + { + if (isset($this->_data[$this->name])) { + $callback = $this->_data[$this->name][0]; + $params = ($this->_BCMode[$this->name]? "'', {jsVar}": '{jsVar}') . + (isset($options)? ", '{$options}'": ''); + } else { + $callback = is_array($options)? $options[1]: $options; + $params = '{jsVar}'; + } + return array('', "{jsVar} != '' && !{$callback}({$params})"); + } // end func getValidationScript + +} // end class HTML_QuickForm_Rule_Callback ?>
\ No newline at end of file diff --git a/libs/HTML/QuickForm/Rule/Compare.php b/libs/HTML/QuickForm/Rule/Compare.php index e7d491301d..7b8ed4a283 100755 --- a/libs/HTML/QuickForm/Rule/Compare.php +++ b/libs/HTML/QuickForm/Rule/Compare.php @@ -1,105 +1,105 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Rule to compare two form fields
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Alexey Borzov <avb@php.net>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Rule to compare two form fields
- *
- * The most common usage for this is to ensure that the password
- * confirmation field matches the password field
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Alexey Borzov <avb@php.net>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
-{
- /**
- * Possible operators to use
- * @var array
- * @access private
- */
- var $_operators = array(
- 'eq' => '===',
- 'neq' => '!==',
- 'gt' => '>',
- 'gte' => '>=',
- 'lt' => '<',
- 'lte' => '<=',
- '==' => '===',
- '!=' => '!=='
- );
-
-
- /**
- * Returns the operator to use for comparing the values
- *
- * @access private
- * @param string operator name
- * @return string operator to use for validation
- */
- function _findOperator($name)
- {
- if (empty($name)) {
- return '===';
- } elseif (isset($this->_operators[$name])) {
- return $this->_operators[$name];
- } elseif (in_array($name, $this->_operators)) {
- return $name;
- } else {
- return '===';
- }
- }
-
-
- function validate($values, $operator = null)
- {
- $operator = $this->_findOperator($operator);
- if ('===' != $operator && '!==' != $operator) {
- $compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
- } else {
- $compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
- }
-
- return $compareFn($values[0], $values[1]);
- }
-
-
- function getValidationScript($operator = null)
- {
- $operator = $this->_findOperator($operator);
- if ('===' != $operator && '!==' != $operator) {
- $check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
- } else {
- $check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
- }
- return array('', "'' != {jsVar}[0] && {$check}");
- }
-}
-?>
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Rule to compare two form fields + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Alexey Borzov <avb@php.net> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Rule to compare two form fields + * + * The most common usage for this is to ensure that the password + * confirmation field matches the password field + * + * @category HTML + * @package HTML_QuickForm + * @author Alexey Borzov <avb@php.net> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule +{ + /** + * Possible operators to use + * @var array + * @access private + */ + var $_operators = array( + 'eq' => '===', + 'neq' => '!==', + 'gt' => '>', + 'gte' => '>=', + 'lt' => '<', + 'lte' => '<=', + '==' => '===', + '!=' => '!==' + ); + + + /** + * Returns the operator to use for comparing the values + * + * @access private + * @param string operator name + * @return string operator to use for validation + */ + function _findOperator($name) + { + if (empty($name)) { + return '==='; + } elseif (isset($this->_operators[$name])) { + return $this->_operators[$name]; + } elseif (in_array($name, $this->_operators)) { + return $name; + } else { + return '==='; + } + } + + + function validate($values, $operator = null) + { + $operator = $this->_findOperator($operator); + if ('===' != $operator && '!==' != $operator) { + $compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);'); + } else { + $compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);'); + } + + return $compareFn($values[0], $values[1]); + } + + + function getValidationScript($operator = null) + { + $operator = $this->_findOperator($operator); + if ('===' != $operator && '!==' != $operator) { + $check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))"; + } else { + $check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))"; + } + return array('', "'' != {jsVar}[0] && {$check}"); + } +} +?> diff --git a/libs/HTML/QuickForm/Rule/Email.php b/libs/HTML/QuickForm/Rule/Email.php index bb30c6546c..06ca30f172 100755 --- a/libs/HTML/QuickForm/Rule/Email.php +++ b/libs/HTML/QuickForm/Rule/Email.php @@ -1,73 +1,73 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Email validation rule
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Email validation rule
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
-{
- var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
-
- /**
- * Validates an email address
- *
- * @param string $email Email address
- * @param boolean $checkDomain True if dns check should be performed
- * @access public
- * @return boolean true if email is valid
- */
- function validate($email, $checkDomain = false)
- {
- // Fix for bug #10799: add 'D' modifier to regex
- if (preg_match($this->regex . 'D', $email)) {
- if ($checkDomain && function_exists('checkdnsrr')) {
- $tokens = explode('@', $email);
- if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
- return true;
- }
- return false;
- }
- return true;
- }
- return false;
- } // end func validate
-
-
- function getValidationScript($options = null)
- {
- return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
- } // end func getValidationScript
-
-} // end class HTML_QuickForm_Rule_Email
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Email validation rule + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Email validation rule + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule +{ + var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; + + /** + * Validates an email address + * + * @param string $email Email address + * @param boolean $checkDomain True if dns check should be performed + * @access public + * @return boolean true if email is valid + */ + function validate($email, $checkDomain = false) + { + // Fix for bug #10799: add 'D' modifier to regex + if (preg_match($this->regex . 'D', $email)) { + if ($checkDomain && function_exists('checkdnsrr')) { + $tokens = explode('@', $email); + if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) { + return true; + } + return false; + } + return true; + } + return false; + } // end func validate + + + function getValidationScript($options = null) + { + return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})"); + } // end func getValidationScript + +} // end class HTML_QuickForm_Rule_Email ?>
\ No newline at end of file diff --git a/libs/HTML/QuickForm/Rule/Range.php b/libs/HTML/QuickForm/Rule/Range.php index aaa32d0660..76f1837a3e 100755 --- a/libs/HTML/QuickForm/Rule/Range.php +++ b/libs/HTML/QuickForm/Rule/Range.php @@ -1,75 +1,75 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Checks that the length of value is within range
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Checks that the length of value is within range
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
-{
- /**
- * Validates a value using a range comparison
- *
- * @param string $value Value to be checked
- * @param mixed $options Int for length, array for range
- * @access public
- * @return boolean true if value is valid
- */
- function validate($value, $options)
- {
- $length = strlen($value);
- switch ($this->name) {
- case 'minlength': return ($length >= $options);
- case 'maxlength': return ($length <= $options);
- default: return ($length >= $options[0] && $length <= $options[1]);
- }
- } // end func validate
-
-
- function getValidationScript($options = null)
- {
- switch ($this->name) {
- case 'minlength':
- $test = '{jsVar}.length < '.$options;
- break;
- case 'maxlength':
- $test = '{jsVar}.length > '.$options;
- break;
- default:
- $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
- }
- return array('', "{jsVar} != '' && {$test}");
- } // end func getValidationScript
-
-} // end class HTML_QuickForm_Rule_Range
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Checks that the length of value is within range + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Checks that the length of value is within range + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule +{ + /** + * Validates a value using a range comparison + * + * @param string $value Value to be checked + * @param mixed $options Int for length, array for range + * @access public + * @return boolean true if value is valid + */ + function validate($value, $options) + { + $length = strlen($value); + switch ($this->name) { + case 'minlength': return ($length >= $options); + case 'maxlength': return ($length <= $options); + default: return ($length >= $options[0] && $length <= $options[1]); + } + } // end func validate + + + function getValidationScript($options = null) + { + switch ($this->name) { + case 'minlength': + $test = '{jsVar}.length < '.$options; + break; + case 'maxlength': + $test = '{jsVar}.length > '.$options; + break; + default: + $test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')'; + } + return array('', "{jsVar} != '' && {$test}"); + } // end func getValidationScript + +} // end class HTML_QuickForm_Rule_Range ?>
\ No newline at end of file diff --git a/libs/HTML/QuickForm/Rule/Regex.php b/libs/HTML/QuickForm/Rule/Regex.php index bc060b9887..2417a022e2 100755 --- a/libs/HTML/QuickForm/Rule/Regex.php +++ b/libs/HTML/QuickForm/Rule/Regex.php @@ -1,101 +1,101 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Validates values using regular expressions
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Validates values using regular expressions
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule
-{
- /**
- * Array of regular expressions
- *
- * Array is in the format:
- * $_data['rulename'] = 'pattern';
- *
- * @var array
- * @access private
- */
- var $_data = array(
- 'lettersonly' => '/^[a-zA-Z]+$/',
- 'alphanumeric' => '/^[a-zA-Z0-9]+$/',
- 'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/',
- 'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/',
- 'nonzero' => '/^-?[1-9][0-9]*/'
- );
-
- /**
- * Validates a value using a regular expression
- *
- * @param string $value Value to be checked
- * @param string $regex Regular expression
- * @access public
- * @return boolean true if value is valid
- */
- function validate($value, $regex = null)
- {
- // Fix for bug #10799: add 'D' modifier to regex
- if (isset($this->_data[$this->name])) {
- if (!preg_match($this->_data[$this->name] . 'D', $value)) {
- return false;
- }
- } else {
- if (!preg_match($regex . 'D', $value)) {
- return false;
- }
- }
- return true;
- } // end func validate
-
- /**
- * Adds new regular expressions to the list
- *
- * @param string $name Name of rule
- * @param string $pattern Regular expression pattern
- * @access public
- */
- function addData($name, $pattern)
- {
- $this->_data[$name] = $pattern;
- } // end func addData
-
-
- function getValidationScript($options = null)
- {
- $regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options;
-
- return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
- } // end func getValidationScript
-
-} // end class HTML_QuickForm_Rule_Regex
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Validates values using regular expressions + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Validates values using regular expressions + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule +{ + /** + * Array of regular expressions + * + * Array is in the format: + * $_data['rulename'] = 'pattern'; + * + * @var array + * @access private + */ + var $_data = array( + 'lettersonly' => '/^[a-zA-Z]+$/', + 'alphanumeric' => '/^[a-zA-Z0-9]+$/', + 'numeric' => '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/', + 'nopunctuation' => '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/', + 'nonzero' => '/^-?[1-9][0-9]*/' + ); + + /** + * Validates a value using a regular expression + * + * @param string $value Value to be checked + * @param string $regex Regular expression + * @access public + * @return boolean true if value is valid + */ + function validate($value, $regex = null) + { + // Fix for bug #10799: add 'D' modifier to regex + if (isset($this->_data[$this->name])) { + if (!preg_match($this->_data[$this->name] . 'D', $value)) { + return false; + } + } else { + if (!preg_match($regex . 'D', $value)) { + return false; + } + } + return true; + } // end func validate + + /** + * Adds new regular expressions to the list + * + * @param string $name Name of rule + * @param string $pattern Regular expression pattern + * @access public + */ + function addData($name, $pattern) + { + $this->_data[$name] = $pattern; + } // end func addData + + + function getValidationScript($options = null) + { + $regex = isset($this->_data[$this->name]) ? $this->_data[$this->name] : $options; + + return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})"); + } // end func getValidationScript + +} // end class HTML_QuickForm_Rule_Regex ?>
\ No newline at end of file diff --git a/libs/HTML/QuickForm/Rule/Required.php b/libs/HTML/QuickForm/Rule/Required.php index 831efcf3ee..f8cc8f5924 100755 --- a/libs/HTML/QuickForm/Rule/Required.php +++ b/libs/HTML/QuickForm/Rule/Required.php @@ -1,63 +1,63 @@ -<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Required elements validation
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.01 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_01.txt If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @copyright 2001-2007 The PHP Group
- * @license http://www.php.net/license/3_01.txt PHP License 3.01
- * @version CVS: $Id$
- * @link http://pear.php.net/package/HTML_QuickForm
- */
-
-/**
- * Abstract base class for QuickForm validation rules
- */
-require_once 'HTML/QuickForm/Rule.php';
-
-/**
- * Required elements validation
- *
- * @category HTML
- * @package HTML_QuickForm
- * @author Bertrand Mansion <bmansion@mamasam.com>
- * @version Release: 3.2.9
- * @since 3.2
- */
-class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
-{
- /**
- * Checks if an element is empty
- *
- * @param string $value Value to check
- * @param mixed $options Not used yet
- * @access public
- * @return boolean true if value is not empty
- */
- function validate($value, $options = null)
- {
- if ((string)$value == '') {
- return false;
- }
- return true;
- } // end func validate
-
-
- function getValidationScript($options = null)
- {
- return array('', "{jsVar} == ''");
- } // end func getValidationScript
-
-} // end class HTML_QuickForm_Rule_Required
-?>
+<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Required elements validation + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.01 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_01.txt If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @copyright 2001-2007 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version CVS: $Id$ + * @link http://pear.php.net/package/HTML_QuickForm + */ + +/** + * Abstract base class for QuickForm validation rules + */ +require_once 'HTML/QuickForm/Rule.php'; + +/** + * Required elements validation + * + * @category HTML + * @package HTML_QuickForm + * @author Bertrand Mansion <bmansion@mamasam.com> + * @version Release: 3.2.9 + * @since 3.2 + */ +class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule +{ + /** + * Checks if an element is empty + * + * @param string $value Value to check + * @param mixed $options Not used yet + * @access public + * @return boolean true if value is not empty + */ + function validate($value, $options = null) + { + if ((string)$value == '') { + return false; + } + return true; + } // end func validate + + + function getValidationScript($options = null) + { + return array('', "{jsVar} == ''"); + } // end func getValidationScript + +} // end class HTML_QuickForm_Rule_Required +?> |