First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Callback.php,v 1.9 2009/04/04 21:34:04 avb Exp $
* @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.11
* @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
?>

View file

@ -0,0 +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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Compare.php,v 1.7 2009/04/04 21:34:04 avb Exp $
* @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.11
* @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}");
}
}
?>

View file

@ -0,0 +1,86 @@
<?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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Email.php,v 1.7 2009/04/04 21:34:04 avb Exp $
* @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.11
* @since 3.2
*/
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
{
// switching to a better regex as per CRM-40
// 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\-]+))$/';
var $regex = '/^([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*"))*@([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\]))*$/';
/**
* 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)
{
if (function_exists('idn_to_ascii')) {
if ($parts = explode('@', $email)) {
if (sizeof($parts) == 2) {
foreach ($parts as &$part) {
$part = idn_to_ascii($part);
}
$email = implode('@', $parts);
}
}
}
// 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
?>

View file

@ -0,0 +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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Range.php,v 1.8 2009/04/04 21:34:04 avb Exp $
* @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.11
* @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
?>

View file

@ -0,0 +1,107 @@
<?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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Regex.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @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.11
* @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;
// bug #12376, converting unicode escapes and stripping 'u' modifier
if ($pos = strpos($regex, 'u', strrpos($regex, '/'))) {
$regex = substr($regex, 0, $pos) . substr($regex, $pos + 1);
$regex = preg_replace('/(?<!\\\\)(?>\\\\\\\\)*\\\\x{([a-fA-F0-9]+)}/', '\\u$1', $regex);
}
return array(" var regex = " . $regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Regex
?>

View file

@ -0,0 +1,86 @@
<?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-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Required.php,v 1.6 2009/04/04 21:34:04 avb Exp $
* @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.11
* @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 ( is_array( $value ) ) {
// check if file type, if so permit empty type
$fileType =
array_key_exists( 'name', $value ) &&
array_key_exists( 'tmp_name', $value );
// hack to fix required issue with advcheckbox, but in general if any value is present then
// it should pass required check
$return = false;
foreach ( $value as $k => $v ) {
// dont check type field. Safari3 Beta does not set this
if ( $fileType && $k == 'type' ) {
continue;
}
if ( is_array($v) ) {
if ( $v ) {
$return = true;
}
}
elseif ( ( string ) $v != '' ) {
$return = true;
}
}
return $return;
} else 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
?>