PDF rausgenommen
This commit is contained in:
172
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Callback.php
Normal file
172
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Callback.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Callback.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*
|
||||
* The Rule needs a valid callback as a configuration parameter for its work, it
|
||||
* may also be given additional arguments to pass to the callback alongside the
|
||||
* element's value. See {@link mergeConfig()} for description of possible ways
|
||||
* to pass configuration parameters.
|
||||
*
|
||||
* The callback will be called with element's value as the first argument, if
|
||||
* additional arguments were provided they'll be passed as well. It is expected
|
||||
* to return false if the value is invalid and true if it is valid.
|
||||
*
|
||||
* Checking that the value is not empty:
|
||||
* <code>
|
||||
* $str->addRule('callback', 'The field should not be empty', 'strlen');
|
||||
* </code>
|
||||
* Checking that the value is in the given array:
|
||||
* <code>
|
||||
* $meta->addRule('callback', 'Unknown variable name',
|
||||
* array('callback' => 'in_array',
|
||||
* 'arguments' => array(array('foo', 'bar', 'baz'))));
|
||||
* </code>
|
||||
* The same, but with rule registering first:
|
||||
* <code>
|
||||
* HTML_QuickForm2_Factory::registerRule(
|
||||
* 'in_array', 'HTML_QuickForm2_Rule_Callback',
|
||||
* 'HTML/QuickForm2/Rule/Callback.php', 'in_array'
|
||||
* );
|
||||
* $meta->addRule('in_array', 'Unknown variable name', array(array('foo', 'bar', 'baz')));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Callback extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool the value returned by a callback function
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
return (bool)call_user_func_array(
|
||||
$config['callback'], array_merge(array($value), $config['arguments'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges local configuration with that provided for registerRule()
|
||||
*
|
||||
* "Global" configuration may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in either of the
|
||||
* following formats
|
||||
* - callback
|
||||
* - array(['callback' => callback, ]['arguments' => array(...)])
|
||||
*
|
||||
* "Local" configuration may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - callback or arguments (interpretation depends on whether the global
|
||||
* configuration already contains the callback)
|
||||
* - array(['callback' => callback, ]['arguments' => array(...)])
|
||||
*
|
||||
* As usual, global config overrides local one. It is a good idea to use the
|
||||
* associative array format to prevent ambiguity.
|
||||
*
|
||||
* @param mixed Local configuration
|
||||
* @param mixed Global configuration
|
||||
* @return mixed Merged configuration
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
if (!isset($globalConfig)) {
|
||||
$config = $localConfig;
|
||||
|
||||
} else {
|
||||
if (!is_array($globalConfig) ||
|
||||
!isset($globalConfig['callback']) && !isset($globalConfig['arguments'])
|
||||
) {
|
||||
$config = array('callback' => $globalConfig);
|
||||
} else {
|
||||
$config = $globalConfig;
|
||||
}
|
||||
if (is_array($localConfig) && (isset($localConfig['callback'])
|
||||
|| isset($localConfig['arguments']))
|
||||
) {
|
||||
$config += $localConfig;
|
||||
} elseif(isset($localConfig)) {
|
||||
$config += array('callback' => $localConfig, 'arguments' => $localConfig);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback to use for validation and its additional arguments
|
||||
*
|
||||
* @param callback|array Callback or array ('callback' => validation callback,
|
||||
* 'arguments' => additional arguments)
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if callback is missing or invalid
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!is_array($config) || !isset($config['callback'])) {
|
||||
$config = array('callback' => $config);
|
||||
}
|
||||
if (!is_callable($config['callback'], false, $callbackName)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Callback Rule requires a valid callback, \'' . $callbackName .
|
||||
'\' was given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config + array('arguments' => array()));
|
||||
}
|
||||
}
|
||||
?>
|
250
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Compare.php
Normal file
250
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Compare.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule comparing the value of the field with some other value
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Compare.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule comparing the value of the field with some other value
|
||||
*
|
||||
* The Rule needs two configuration parameters for its work
|
||||
* - comparison operator (defaults to equality)
|
||||
* - operand to compare with; this can be either a constant or another form
|
||||
* element (its value will be used)
|
||||
* See {@link mergeConfig()} for description of possible ways to pass
|
||||
* configuration parameters.
|
||||
*
|
||||
* Note that 'less than [or equal]' and 'greater than [or equal]' operators
|
||||
* compare the operands numerically, since this is considered as more useful
|
||||
* approach by the authors.
|
||||
*
|
||||
* For convenience, this Rule is already registered in the Factory with the
|
||||
* names 'eq', 'neq', 'lt', 'gt', 'lte', 'gte' corresponding to the relevant
|
||||
* operators:
|
||||
* <code>
|
||||
* $password->addRule('eq', 'Passwords do not match', $passwordRepeat);
|
||||
* $orderQty->addRule('lte', 'Should not order more than 10 of these', 10);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Compare extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Possible comparison operators
|
||||
* @var array
|
||||
*/
|
||||
protected $operators = array('==', '!=', '===', '!==', '<', '<=', '>', '>=');
|
||||
|
||||
protected function doOperation($a, $b, $operator)
|
||||
{
|
||||
switch ($operator) {
|
||||
case "==": return $a == $b;
|
||||
case "!=": return $a != $b;
|
||||
case "===": return $a === $b;
|
||||
case "!==": return $a !== $b;
|
||||
case ">": return $a > $b;
|
||||
case "<=": return $a <= $b;
|
||||
case "<": return $a < $b;
|
||||
case ">=": return $a >= $b;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether (element_value operator operand) expression is true
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
|
||||
if ($config['operand'] instanceof HTML_QuickForm2_Node) {
|
||||
$b = $config['operand']->getValue();
|
||||
} else {
|
||||
$b = $config['operand'];
|
||||
}
|
||||
|
||||
if (!in_array($config['operator'], array('===', '!=='))) {
|
||||
$a = floatval($value);
|
||||
$b = floatval($b);
|
||||
} else {
|
||||
$a = strval($value);
|
||||
$b = strval($b);
|
||||
}
|
||||
|
||||
return $this->doOperation($a, $b, $config['operator']);
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
$operand1 = $this->owner->getJavascriptValue();
|
||||
$operand2 = $config['operand'] instanceof HTML_QuickForm2_Node
|
||||
? $config['operand']->getJavascriptValue()
|
||||
: "'" . strtr($config['operand'], array(
|
||||
"\r" => '\r',
|
||||
"\n" => '\n',
|
||||
"\t" => '\t',
|
||||
"'" => "\\'",
|
||||
'"' => '\"',
|
||||
'\\' => '\\\\'
|
||||
)) . "'";
|
||||
|
||||
if (!in_array($config['operator'], array('===', '!=='))) {
|
||||
$check = "Number({$operand1}) {$config['operator']} Number({$operand2})";
|
||||
} else {
|
||||
$check = "String({$operand1}) {$config['operator']} String({$operand2})";
|
||||
}
|
||||
|
||||
return "function () { return {$check}; }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges local configuration with that provided for registerRule()
|
||||
*
|
||||
* "Global" configuration may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in
|
||||
* either of the following formats
|
||||
* - operator
|
||||
* - array(operator[, operand])
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
|
||||
* "Local" configuration may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - operand
|
||||
* - array([operator, ]operand)
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
*
|
||||
* As usual, global configuration overrides local one.
|
||||
*
|
||||
* @param mixed Local configuration
|
||||
* @param mixed Global configuration
|
||||
* @return mixed Merged configuration
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
$config = null;
|
||||
if (is_array($globalConfig) && 0 < count($globalConfig)) {
|
||||
$config = self::toCanonicalForm($globalConfig, 'operator');
|
||||
}
|
||||
if (is_array($localConfig) && 0 < count($localConfig)) {
|
||||
$config = (isset($config)? $config: array())
|
||||
+ self::toCanonicalForm($localConfig);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts configuration data to a canonical associative array form
|
||||
*
|
||||
* @param mixed Configuration data
|
||||
* @param string Array key to assign $config to if it is scalar
|
||||
* @return array Associative array that may contain 'operand' and 'operator' keys
|
||||
*/
|
||||
protected static function toCanonicalForm($config, $key = 'operand')
|
||||
{
|
||||
if (!is_array($config)) {
|
||||
return array($key => $config);
|
||||
|
||||
} elseif (array_key_exists('operator', $config)
|
||||
|| array_key_exists('operand', $config)
|
||||
) {
|
||||
return $config;
|
||||
|
||||
} elseif (1 == count($config)) {
|
||||
return array($key => end($config));
|
||||
|
||||
} else {
|
||||
return array('operator' => reset($config), 'operand' => end($config));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparison operator and operand to compare to
|
||||
*
|
||||
* $config can be either of the following
|
||||
* - operand
|
||||
* - array([operator, ]operand)
|
||||
* - array(['operator' => operator, ]['operand' => operand])
|
||||
* If operator is missing it will default to '==='
|
||||
*
|
||||
* @param mixed Configuration data
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus comparison
|
||||
* operator is used for configuration, if an operand is missing
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 == count($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Compare Rule requires an argument to compare with'
|
||||
);
|
||||
}
|
||||
$config = self::toCanonicalForm($config);
|
||||
|
||||
$config += array('operator' => '===');
|
||||
if (!in_array($config['operator'], $this->operators)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Compare Rule requires a valid comparison operator, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config['operator'], true)) . ' given'
|
||||
);
|
||||
}
|
||||
if (in_array($config['operator'], array('==', '!='))) {
|
||||
$config['operator'] .= '=';
|
||||
}
|
||||
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
}
|
||||
?>
|
137
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Each.php
Normal file
137
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Each.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Validates all elements in a Container using a template Rule
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Each.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates all elements in a Container using a template Rule
|
||||
*
|
||||
* This Rule needs one configuration parameter for its work: the template Rule
|
||||
* to use for actual validation. It can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local.
|
||||
*
|
||||
* The container will be considered valid if all its elements are valid
|
||||
* according to a template Rule.
|
||||
*
|
||||
* <code>
|
||||
* $group->addRule('each', 'The fields should contain only letters',
|
||||
* $group->createRule('regex', '/^[a-z]+$/i'));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Each extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner's children using the template Rule
|
||||
*
|
||||
* @return bool Whether all children are valid according to a template Rule
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$rule = clone $this->getConfig();
|
||||
foreach ($this->owner->getRecursiveIterator(RecursiveIteratorIterator::LEAVES_ONLY) as $child) {
|
||||
$rule->setOwner($child);
|
||||
if (!$rule->validateOwner()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template Rule to use for actual validation
|
||||
*
|
||||
* We do not allow using Required rules here, they are able to validate
|
||||
* containers themselves without the help of Each rule.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule Template Rule
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if $config is either not
|
||||
* an instance of Rule or is an instance of Rule_Required
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!$config instanceof HTML_QuickForm2_Rule) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Each Rule requires a template Rule to validate with, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
} elseif ($config instanceof HTML_QuickForm2_Rule_Required) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Cannot use "required" Rule as a template'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Container Container to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a Container
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Container) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Each Rule can only validate Containers, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
89
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Empty.php
Normal file
89
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Empty.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking that the field is empty
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Empty.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that the field is empty
|
||||
*
|
||||
* Handles both simple form fields and file uploads, the latter are considered
|
||||
* valid iff no file upload was attempted.
|
||||
*
|
||||
* The rule doesn't make much sense if used separately, but can be very helpful
|
||||
* if chained:
|
||||
* <code>
|
||||
* $spamCheck->addRule('empty')
|
||||
* ->or_($email->createRule('nonempty', 'Supply a valid email if you want to receive our spam')
|
||||
* ->and_($email->createRule('email')));
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Empty extends HTML_QuickForm2_Rule
|
||||
{
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!$this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
return 0 == strlen($value);
|
||||
} else {
|
||||
return isset($value['error']) && UPLOAD_ERR_NO_FILE == $value['error'];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
return "function() { return " . $this->owner->getJavascriptValue() . " == ''; }";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
236
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Length.php
Normal file
236
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Length.php
Normal file
@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking the value's length
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Length.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value's length
|
||||
*
|
||||
* The rule needs an "allowed length" parameter for its work, it can be either
|
||||
* - a scalar: the value will be valid if it is exactly this long
|
||||
* - an array: the value will be valid if its length is between the given values
|
||||
* (inclusive). If one of these evaluates to 0, then length will be compared
|
||||
* only with the remaining one.
|
||||
* See {@link mergeConfig()} for description of possible ways to pass
|
||||
* configuration parameters.
|
||||
*
|
||||
* The Rule considers empty fields as valid and doesn't try to compare their
|
||||
* lengths with provided limits.
|
||||
*
|
||||
* For convenience this Rule is also registered with the names 'minlength' and
|
||||
* 'maxlength' (having, respectively, 'max' and 'min' parameters set to 0):
|
||||
* <code>
|
||||
* $password->addRule('minlength', 'The password should be at least 6 characters long', 6);
|
||||
* $message->addRule('maxlength', 'Your message is too verbose', 1000);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Length extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether length of the element's value is within allowed range
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
if (0 == ($valueLength = strlen($this->owner->getValue()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$allowedLength = $this->getConfig();
|
||||
if (is_scalar($allowedLength)) {
|
||||
return $valueLength == $allowedLength;
|
||||
} else {
|
||||
return (empty($allowedLength['min']) || $valueLength >= $allowedLength['min']) &&
|
||||
(empty($allowedLength['max']) || $valueLength <= $allowedLength['max']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$allowedLength = $this->getConfig();
|
||||
if (is_scalar($allowedLength)) {
|
||||
$check = "length == {$allowedLength}";
|
||||
} else {
|
||||
$checks = array();
|
||||
if (!empty($allowedLength['min'])) {
|
||||
$checks[] = "length >= {$allowedLength['min']}";
|
||||
}
|
||||
if (!empty($allowedLength['max'])) {
|
||||
$checks[] = "length <= {$allowedLength['max']}";
|
||||
}
|
||||
$check = implode(' && ', $checks);
|
||||
}
|
||||
return "function() { var length = " . $this->owner->getJavascriptValue() .
|
||||
".length; if (0 == length) { return true; } else { return {$check}; } }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the 'min' and 'max' fields from one array to the other
|
||||
*
|
||||
* @param array Rule configuration, array with 'min' and 'max' keys
|
||||
* @param array Additional configuration, fields will be added to
|
||||
* $length if it doesn't contain such a key already
|
||||
* @return array
|
||||
*/
|
||||
protected static function mergeMinMaxLength($length, $config)
|
||||
{
|
||||
if (array_key_exists('min', $config) || array_key_exists('max', $config)) {
|
||||
if (!array_key_exists('min', $length) && array_key_exists('min', $config)) {
|
||||
$length['min'] = $config['min'];
|
||||
}
|
||||
if (!array_key_exists('max', $length) && array_key_exists('max', $config)) {
|
||||
$length['max'] = $config['max'];
|
||||
}
|
||||
} else {
|
||||
if (!array_key_exists('min', $length)) {
|
||||
$length['min'] = reset($config);
|
||||
}
|
||||
if (!array_key_exists('max', $length)) {
|
||||
$length['max'] = end($config);
|
||||
}
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges length limits given on rule creation with those given to registerRule()
|
||||
*
|
||||
* "Global" length limits may be passed to
|
||||
* {@link HTML_QuickForm2_Factory::registerRule()} in either of the
|
||||
* following formats
|
||||
* - scalar (exact length)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* "Local" length limits may be passed to the constructor in either of
|
||||
* the following formats
|
||||
* - scalar (if global config is unset then it is treated as an exact
|
||||
* length, if 'min' or 'max' is in global config then it is treated
|
||||
* as 'max' or 'min', respectively)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* As usual, global configuration overrides local one.
|
||||
*
|
||||
* @param int|array Local length limits
|
||||
* @param int|array Global length limits, usually provided to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* @return int|array Merged length limits
|
||||
*/
|
||||
public static function mergeConfig($localConfig, $globalConfig)
|
||||
{
|
||||
if (!isset($globalConfig)) {
|
||||
$length = $localConfig;
|
||||
|
||||
} elseif (!is_array($globalConfig)) {
|
||||
$length = $globalConfig;
|
||||
|
||||
} else {
|
||||
$length = self::mergeMinMaxLength(array(), $globalConfig);
|
||||
if (isset($localConfig)) {
|
||||
$length = self::mergeMinMaxLength(
|
||||
$length, is_array($localConfig)? $localConfig: array($localConfig)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowed length limits
|
||||
*
|
||||
* $config can be either of the following
|
||||
* - integer (rule checks for exact length)
|
||||
* - array(minlength, maxlength)
|
||||
* - array(['min' => minlength, ]['max' => maxlength])
|
||||
*
|
||||
* @param int|array Length limits
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if bogus length limits
|
||||
* were provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (is_array($config)) {
|
||||
$config = self::mergeMinMaxLength(array(), $config)
|
||||
+ array('min' => 0, 'max' => 0);
|
||||
}
|
||||
if (is_array($config) && ($config['min'] < 0 || $config['max'] < 0) ||
|
||||
!is_array($config) && $config < 0)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Length Rule requires limits to be nonnegative, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
|
||||
} elseif (is_array($config) && $config['min'] == 0 && $config['max'] == 0 ||
|
||||
!is_array($config) && 0 == $config)
|
||||
{
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Length Rule requires at least one non-zero limit, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($config['min']) && !empty($config['max'])) {
|
||||
if ($config['min'] > $config['max']) {
|
||||
list($config['min'], $config['max']) = array($config['max'], $config['min']);
|
||||
} elseif ($config['min'] == $config['max']) {
|
||||
$config = $config['min'];
|
||||
}
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
}
|
||||
?>
|
124
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/MaxFileSize.php
Normal file
124
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/MaxFileSize.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking that uploaded file size does not exceed the given limit
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: MaxFileSize.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that uploaded file size does not exceed the given limit
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: the size limit.
|
||||
* This limit can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* Note that if file upload failed due to upload_max_filesize php.ini setting
|
||||
* or MAX_FILE_SIZE form field, then this rule won't even be called, due to
|
||||
* File element's built-in validation setting the error message.
|
||||
*
|
||||
* The Rule considers missing file uploads (UPLOAD_ERR_NO_FILE) valid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_MaxFileSize extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether uploaded file's size is within given limit
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
return ($this->getConfig() >= @filesize($value['tmp_name']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maximum allowed file size
|
||||
*
|
||||
* @param int Maximum allowed size
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus size limit was provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 >= $config) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MaxFileSize Rule requires a positive size limit, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Element_InputFile File upload field to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a file upload field
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MaxFileSize Rule can only validate file upload fields, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
122
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/MimeType.php
Normal file
122
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/MimeType.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking that uploaded file is of the correct MIME type
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: MimeType.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that uploaded file is of the correct MIME type
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: a string with a
|
||||
* desired MIME type or array of such strings. This parameter can be passed
|
||||
* either to {@link HTML_QuickForm2_Rule::__construct() the Rule constructor}
|
||||
* as local configuration or to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* as global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* The Rule considers missing file uploads (UPLOAD_ERR_NO_FILE) valid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_MimeType extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether uploaded file's MIME type is correct
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$mime = $this->getConfig();
|
||||
return is_array($mime)? in_array($value['type'], $mime):
|
||||
$value['type'] == $mime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets allowed MIME type(s) for the uploaded file
|
||||
*
|
||||
* @param string|array Allowed MIME type or an array of types
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if bogus configuration provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (0 == count($config) || !is_string($config) && !is_array($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MimeType Rule requires MIME type(s), ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element that will be validated by this rule
|
||||
*
|
||||
* @param HTML_QuickForm2_Element_InputFile File upload field to validate
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if trying to use
|
||||
* this Rule on something that isn't a file upload field
|
||||
*/
|
||||
public function setOwner(HTML_QuickForm2_Node $owner)
|
||||
{
|
||||
if (!$owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'MimeType Rule can only validate file upload fields, '.
|
||||
get_class($owner) . ' given'
|
||||
);
|
||||
}
|
||||
parent::setOwner($owner);
|
||||
}
|
||||
}
|
||||
?>
|
141
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Nonempty.php
Normal file
141
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Nonempty.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking that the field is not empty
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Nonempty.php 299706 2010-05-24 18:32:37Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Rule checking that the field is not empty
|
||||
*
|
||||
* Handles simple form fields, file uploads and Containers.
|
||||
*
|
||||
* When validating <select multiple> fields and Containers it may use an
|
||||
* optional configuration parameter for minimum number of nonempty values,
|
||||
* defaulting to 1. It can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()} as
|
||||
* global one. As usual, global configuration overrides local.
|
||||
*
|
||||
* <code>
|
||||
* // Required rule is 'nonempty' with a bit of special handling
|
||||
* $login->addRule('required', 'Please provide your login');
|
||||
* $multiSelect->addRule('required', 'Please select at least two options', 2);
|
||||
* </code>
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Nonempty extends HTML_QuickForm2_Rule
|
||||
{
|
||||
protected function validateOwner()
|
||||
{
|
||||
if ($this->owner instanceof HTML_QuickForm2_Container) {
|
||||
$nonempty = 0;
|
||||
foreach ($this->owner->getRecursiveIterator(RecursiveIteratorIterator::LEAVES_ONLY) as $child) {
|
||||
$rule = new self($child);
|
||||
if ($rule->validateOwner()) {
|
||||
$nonempty++;
|
||||
}
|
||||
}
|
||||
return $nonempty >= $this->getConfig();
|
||||
}
|
||||
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
return isset($value['error']) && (UPLOAD_ERR_OK == $value['error']);
|
||||
} elseif (is_array($value)) {
|
||||
return count(array_filter($value, 'strlen')) >= $this->getConfig();
|
||||
} else {
|
||||
return (bool)strlen($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets minimum number of nonempty values
|
||||
*
|
||||
* This is useful for multiple selects and Containers, will be ignored for
|
||||
* all other elements. Defaults to 1, thus multiple select will be
|
||||
* considered not empty if at least one option is selected, Container will
|
||||
* be considered not empty if at least one contained element is not empty.
|
||||
*
|
||||
* @param int Maximum allowed size
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if a bogus size limit was provided
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (is_null($config)) {
|
||||
$config = 1;
|
||||
} elseif (1 > intval($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Nonempty Rule accepts a positive count of nonempty values, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig(intval($config));
|
||||
}
|
||||
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$js = "function() {var value = " . $this->owner->getJavascriptValue() . ";";
|
||||
if (!$this->owner instanceof HTML_QuickForm2_Container) {
|
||||
$js .= " if (!value instanceof Array) { return value != ''; } else { " .
|
||||
"var valid = 0; for (var i = 0; i < value.length; i++) { " .
|
||||
"if ('' != value[i]) { valid++; } } return valid >= " . $this->getConfig() . "; } }";
|
||||
} else {
|
||||
$js .= " var values = value.getValues(); var valid = 0; " .
|
||||
"for (var i = 0; i < values.length; i++) { " .
|
||||
"if ('' != values[i]) { valid++; } } return valid >= " . $this->getConfig() . "; }";
|
||||
}
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule checking the value via a callback function (method) with logical negation
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: NotCallback.php 299305 2010-05-12 20:15:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method)
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Callback.php';
|
||||
|
||||
/**
|
||||
* Rule checking the value via a callback function (method) with logical negation
|
||||
*
|
||||
* The Rule accepts the same configuration parameters as the Callback Rule
|
||||
* does, but the callback is expected to return false if the element is valid
|
||||
* and true if it is invalid.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_NotCallback extends HTML_QuickForm2_Rule_Callback
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool negated result of a callback function
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
$config = $this->getConfig();
|
||||
return !call_user_func_array(
|
||||
$config['callback'], array_merge(array($value), $config['arguments'])
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
106
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/NotRegex.php
Normal file
106
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/NotRegex.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Checks that the element's value does not match a regular expression
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: NotRegex.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Regex.php';
|
||||
|
||||
/**
|
||||
* Checks that the element's value does not match a regular expression
|
||||
*
|
||||
* The Rule behaves like Regex Rule, but it considers the element valid if its
|
||||
* value does not match the given regular expression.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_NotRegex extends HTML_QuickForm2_Rule_Regex
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether element's value does not match given regular expression
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$value = $value['name'];
|
||||
} elseif (!strlen($value)) {
|
||||
return true;
|
||||
}
|
||||
return !preg_match($this->getConfig() . 'D', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side validation callback
|
||||
*
|
||||
* For this to work properly, slashes have to be used as regex delimiters.
|
||||
* The method takes care of transforming PHP unicode escapes in regexps to
|
||||
* JS unicode escapes if using 'u' modifier (see bug #12376)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$regex = $this->getConfig();
|
||||
|
||||
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 "function() { var regex = {$regex}; var value = " . $this->owner->getJavascriptValue() .
|
||||
"; return value == '' || !regex.test(value); }";
|
||||
}
|
||||
}
|
||||
?>
|
133
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Regex.php
Normal file
133
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Regex.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Regex.php 299480 2010-05-19 06:55:03Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTML_QuickForm2 rules
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule.php';
|
||||
|
||||
/**
|
||||
* Validates values using regular expressions
|
||||
*
|
||||
* The Rule needs one configuration parameter for its work: a Perl-compatible
|
||||
* regular expression. This parameter can be passed either to
|
||||
* {@link HTML_QuickForm2_Rule::__construct() the Rule constructor} as local
|
||||
* configuration or to {@link HTML_QuickForm2_Factory::registerRule()}
|
||||
* as global one. As usual, global configuration overrides local one.
|
||||
*
|
||||
* The Rule can also validate file uploads, in this case the regular expression
|
||||
* is applied to upload's 'name' field.
|
||||
*
|
||||
* The Rule considers empty fields (file upload fields with UPLOAD_ERR_NO_FILE)
|
||||
* as valid and doesn't try to test them with the regular expression.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Regex extends HTML_QuickForm2_Rule
|
||||
{
|
||||
/**
|
||||
* Validates the owner element
|
||||
*
|
||||
* @return bool whether element's value matches given regular expression
|
||||
*/
|
||||
protected function validateOwner()
|
||||
{
|
||||
$value = $this->owner->getValue();
|
||||
if ($this->owner instanceof HTML_QuickForm2_Element_InputFile) {
|
||||
if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
|
||||
return true;
|
||||
}
|
||||
$value = $value['name'];
|
||||
} elseif (!strlen($value)) {
|
||||
return true;
|
||||
}
|
||||
return preg_match($this->getConfig() . 'D', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regular expression to validate with
|
||||
*
|
||||
* @param string Regular expression
|
||||
* @return HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_InvalidArgumentException if $config is not a string
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
if (!is_string($config)) {
|
||||
throw new HTML_QuickForm2_InvalidArgumentException(
|
||||
'Regex Rule requires a regular expression, ' .
|
||||
preg_replace('/\s+/', ' ', var_export($config, true)) . ' given'
|
||||
);
|
||||
}
|
||||
return parent::setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client-side validation callback
|
||||
*
|
||||
* For this to work properly, slashes have to be used as regex delimiters.
|
||||
* The method takes care of transforming PHP unicode escapes in regexps to
|
||||
* JS unicode escapes if using 'u' modifier (see bug #12376)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getJavascriptCallback()
|
||||
{
|
||||
$regex = $this->getConfig();
|
||||
|
||||
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 "function() { var regex = {$regex}; var value = " . $this->owner->getJavascriptValue() .
|
||||
"; return value == '' || regex.test(value); }";
|
||||
}
|
||||
}
|
||||
?>
|
88
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Required.php
Normal file
88
msd2/tracking/piwik/libs/HTML/QuickForm2/Rule/Required.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Rule for required elements
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
|
||||
* Bertrand Mansion <golgote@mamasam.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Required.php 294057 2010-01-26 21:10:28Z avb $
|
||||
* @link http://pear.php.net/package/HTML_QuickForm2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rule checking that the form field is not empty
|
||||
*/
|
||||
// require_once 'HTML/QuickForm2/Rule/Nonempty.php';
|
||||
|
||||
/**
|
||||
* Rule for required elements
|
||||
*
|
||||
* The main difference from "nonempty" Rule is that
|
||||
* - elements to which this Rule is attached will be considered required
|
||||
* ({@link HTML_QuickForm2_Node::isRequired()} will return true for them) and
|
||||
* marked accordingly when outputting the form
|
||||
* - this Rule can only be added directly to the element and other Rules can
|
||||
* only be added to it via and_() method
|
||||
*
|
||||
* @category HTML
|
||||
* @package HTML_QuickForm2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @author Bertrand Mansion <golgote@mamasam.com>
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class HTML_QuickForm2_Rule_Required extends HTML_QuickForm2_Rule_Nonempty
|
||||
{
|
||||
/**
|
||||
* Disallows adding a rule to the chain with an "or" operator
|
||||
*
|
||||
* Required rules are different from all others because they affect the
|
||||
* visual representation of an element ("* denotes required field").
|
||||
* Therefore we cannot allow chaining other rules to these via or_(), since
|
||||
* this will effectively mean that the field is not required anymore and the
|
||||
* visual difference is bogus.
|
||||
*
|
||||
* @param HTML_QuickForm2_Rule
|
||||
* @throws HTML_QuickForm2_Exception
|
||||
*/
|
||||
public function or_(HTML_QuickForm2_Rule $next)
|
||||
{
|
||||
throw new HTML_QuickForm2_Exception(
|
||||
'or_(): Cannot add a rule to "required" rule'
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user