add piwik installation
This commit is contained in:
parent
90aa4ef157
commit
8c5d4f0c31
49 changed files with 563902 additions and 0 deletions
456
www/analytics/libs/Zend/Validate/Abstract.php
Normal file
456
www/analytics/libs/Zend/Validate/Abstract.php
Normal file
|
|
@ -0,0 +1,456 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Interface
|
||||
*/
|
||||
// require_once 'Zend/Validate/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Validate_Abstract implements Zend_Validate_Interface
|
||||
{
|
||||
/**
|
||||
* The value to be validated
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_value;
|
||||
|
||||
/**
|
||||
* Additional variables available for validation failure messages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageVariables = array();
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array();
|
||||
|
||||
/**
|
||||
* Array of validation failure messages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messages = array();
|
||||
|
||||
/**
|
||||
* Flag indidcating whether or not value should be obfuscated in error
|
||||
* messages
|
||||
* @var bool
|
||||
*/
|
||||
protected $_obscureValue = false;
|
||||
|
||||
/**
|
||||
* Array of validation failure message codes
|
||||
*
|
||||
* @var array
|
||||
* @deprecated Since 1.5.0
|
||||
*/
|
||||
protected $_errors = array();
|
||||
|
||||
/**
|
||||
* Translation object
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected $_translator;
|
||||
|
||||
/**
|
||||
* Default translation object for all validate objects
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected static $_defaultTranslator;
|
||||
|
||||
/**
|
||||
* Is translation disabled?
|
||||
* @var Boolean
|
||||
*/
|
||||
protected $_translatorDisabled = false;
|
||||
|
||||
/**
|
||||
* Limits the maximum returned length of a error message
|
||||
*
|
||||
* @var Integer
|
||||
*/
|
||||
protected static $_messageLength = -1;
|
||||
|
||||
/**
|
||||
* Returns array of validation failure messages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->_messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the names of variables that are used in constructing validation failure messages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessageVariables()
|
||||
{
|
||||
return array_keys($this->_messageVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message templates from the validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessageTemplates()
|
||||
{
|
||||
return $this->_messageTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the validation failure message template for a particular key
|
||||
*
|
||||
* @param string $messageString
|
||||
* @param string $messageKey OPTIONAL
|
||||
* @return Zend_Validate_Abstract Provides a fluent interface
|
||||
* @throws Zend_Validate_Exception
|
||||
*/
|
||||
public function setMessage($messageString, $messageKey = null)
|
||||
{
|
||||
if ($messageKey === null) {
|
||||
$keys = array_keys($this->_messageTemplates);
|
||||
foreach($keys as $key) {
|
||||
$this->setMessage($messageString, $key);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!isset($this->_messageTemplates[$messageKey])) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
|
||||
}
|
||||
|
||||
$this->_messageTemplates[$messageKey] = $messageString;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets validation failure message templates given as an array, where the array keys are the message keys,
|
||||
* and the array values are the message template strings.
|
||||
*
|
||||
* @param array $messages
|
||||
* @return Zend_Validate_Abstract
|
||||
*/
|
||||
public function setMessages(array $messages)
|
||||
{
|
||||
foreach ($messages as $key => $message) {
|
||||
$this->setMessage($message, $key);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function returns the value of the requested property, if and only if it is the value or a
|
||||
* message variable.
|
||||
*
|
||||
* @param string $property
|
||||
* @return mixed
|
||||
* @throws Zend_Validate_Exception
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
if ($property == 'value') {
|
||||
return $this->_value;
|
||||
}
|
||||
if (array_key_exists($property, $this->_messageVariables)) {
|
||||
return $this->{$this->_messageVariables[$property]};
|
||||
}
|
||||
/**
|
||||
* @see Zend_Validate_Exception
|
||||
*/
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("No property exists by the name '$property'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a validation failure message with the given message key and value.
|
||||
*
|
||||
* Returns null if and only if $messageKey does not correspond to an existing template.
|
||||
*
|
||||
* If a translator is available and a translation exists for $messageKey,
|
||||
* the translation will be used.
|
||||
*
|
||||
* @param string $messageKey
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function _createMessage($messageKey, $value)
|
||||
{
|
||||
if (!isset($this->_messageTemplates[$messageKey])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$message = $this->_messageTemplates[$messageKey];
|
||||
|
||||
if (null !== ($translator = $this->getTranslator())) {
|
||||
if ($translator->isTranslated($messageKey)) {
|
||||
$message = $translator->translate($messageKey);
|
||||
} else {
|
||||
$message = $translator->translate($message);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
if (!in_array('__toString', get_class_methods($value))) {
|
||||
$value = get_class($value) . ' object';
|
||||
} else {
|
||||
$value = $value->__toString();
|
||||
}
|
||||
} else {
|
||||
$value = (string)$value;
|
||||
}
|
||||
|
||||
if ($this->getObscureValue()) {
|
||||
$value = str_repeat('*', strlen($value));
|
||||
}
|
||||
|
||||
$message = str_replace('%value%', (string) $value, $message);
|
||||
foreach ($this->_messageVariables as $ident => $property) {
|
||||
$message = str_replace("%$ident%", (string) $this->$property, $message);
|
||||
}
|
||||
|
||||
$length = self::getMessageLength();
|
||||
if (($length > -1) && (strlen($message) > $length)) {
|
||||
$message = substr($message, 0, (self::getMessageLength() - 3)) . '...';
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $messageKey
|
||||
* @param string $value OPTIONAL
|
||||
* @return void
|
||||
*/
|
||||
protected function _error($messageKey, $value = null)
|
||||
{
|
||||
if ($messageKey === null) {
|
||||
$keys = array_keys($this->_messageTemplates);
|
||||
$messageKey = current($keys);
|
||||
}
|
||||
if ($value === null) {
|
||||
$value = $this->_value;
|
||||
}
|
||||
$this->_errors[] = $messageKey;
|
||||
$this->_messages[$messageKey] = $this->_createMessage($messageKey, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value to be validated and clears the messages and errors arrays
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
protected function _setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
$this->_messages = array();
|
||||
$this->_errors = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of validation failure message codes
|
||||
*
|
||||
* @return array
|
||||
* @deprecated Since 1.5.0
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->_errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag indicating whether or not value should be obfuscated in messages
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return Zend_Validate_Abstract
|
||||
*/
|
||||
public function setObscureValue($flag)
|
||||
{
|
||||
$this->_obscureValue = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve flag indicating whether or not value should be obfuscated in
|
||||
* messages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getObscureValue()
|
||||
{
|
||||
return $this->_obscureValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set translation object
|
||||
*
|
||||
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
|
||||
* @return Zend_Validate_Abstract
|
||||
*/
|
||||
public function setTranslator($translator = null)
|
||||
{
|
||||
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
|
||||
$this->_translator = $translator;
|
||||
} elseif ($translator instanceof Zend_Translate) {
|
||||
$this->_translator = $translator->getAdapter();
|
||||
} else {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid translator specified');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return translation object
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
if ($this->translatorIsDisabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null === $this->_translator) {
|
||||
return self::getDefaultTranslator();
|
||||
}
|
||||
|
||||
return $this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this validator have its own specific translator?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTranslator()
|
||||
{
|
||||
return (bool)$this->_translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default translation object for all validate objects
|
||||
*
|
||||
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultTranslator($translator = null)
|
||||
{
|
||||
if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
|
||||
self::$_defaultTranslator = $translator;
|
||||
} elseif ($translator instanceof Zend_Translate) {
|
||||
self::$_defaultTranslator = $translator->getAdapter();
|
||||
} else {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid translator specified');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default translation object for all validate objects
|
||||
*
|
||||
* @return Zend_Translate_Adapter|null
|
||||
*/
|
||||
public static function getDefaultTranslator()
|
||||
{
|
||||
if (null === self::$_defaultTranslator) {
|
||||
// require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Translate')) {
|
||||
$translator = \Zend_Registry::get('Zend_Translate');
|
||||
if ($translator instanceof Zend_Translate_Adapter) {
|
||||
return $translator;
|
||||
} elseif ($translator instanceof Zend_Translate) {
|
||||
return $translator->getAdapter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::$_defaultTranslator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a default translation object set?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasDefaultTranslator()
|
||||
{
|
||||
return (bool)self::$_defaultTranslator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether or not translation should be disabled
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return Zend_Validate_Abstract
|
||||
*/
|
||||
public function setDisableTranslator($flag)
|
||||
{
|
||||
$this->_translatorDisabled = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is translation disabled?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function translatorIsDisabled()
|
||||
{
|
||||
return $this->_translatorDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum allowed message length
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getMessageLength()
|
||||
{
|
||||
return self::$_messageLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum allowed message length
|
||||
*
|
||||
* @param integer $length
|
||||
*/
|
||||
public static function setMessageLength($length = -1)
|
||||
{
|
||||
self::$_messageLength = $length;
|
||||
}
|
||||
}
|
||||
150
www/analytics/libs/Zend/Validate/Alnum.php
Normal file
150
www/analytics/libs/Zend/Validate/Alnum.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Alnum.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Alnum extends Zend_Validate_Abstract
|
||||
{
|
||||
const INVALID = 'alnumInvalid';
|
||||
const NOT_ALNUM = 'notAlnum';
|
||||
const STRING_EMPTY = 'alnumStringEmpty';
|
||||
|
||||
/**
|
||||
* Whether to allow white space characters; off by default
|
||||
*
|
||||
* @var boolean
|
||||
* @deprecated
|
||||
*/
|
||||
public $allowWhiteSpace;
|
||||
|
||||
/**
|
||||
* Alphanumeric filter used for validation
|
||||
*
|
||||
* @var Zend_Filter_Alnum
|
||||
*/
|
||||
protected static $_filter = null;
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID => "Invalid type given. String, integer or float expected",
|
||||
self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits",
|
||||
self::STRING_EMPTY => "'%value%' is an empty string",
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets default option values for this instance
|
||||
*
|
||||
* @param boolean|Zend_Config $allowWhiteSpace
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($allowWhiteSpace = false)
|
||||
{
|
||||
if ($allowWhiteSpace instanceof Zend_Config) {
|
||||
$allowWhiteSpace = $allowWhiteSpace->toArray();
|
||||
}
|
||||
|
||||
if (is_array($allowWhiteSpace)) {
|
||||
if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) {
|
||||
$allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace'];
|
||||
} else {
|
||||
$allowWhiteSpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the allowWhiteSpace option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getAllowWhiteSpace()
|
||||
{
|
||||
return $this->allowWhiteSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowWhiteSpace option
|
||||
*
|
||||
* @param boolean $allowWhiteSpace
|
||||
* @return Zend_Filter_Alnum Provides a fluent interface
|
||||
*/
|
||||
public function setAllowWhiteSpace($allowWhiteSpace)
|
||||
{
|
||||
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value contains only alphabetic and digit characters
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value) && !is_int($value) && !is_float($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_setValue($value);
|
||||
|
||||
if ('' === $value) {
|
||||
$this->_error(self::STRING_EMPTY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === self::$_filter) {
|
||||
/**
|
||||
* @see Zend_Filter_Alnum
|
||||
*/
|
||||
// require_once 'Zend/Filter/Alnum.php';
|
||||
self::$_filter = new Zend_Filter_Alnum();
|
||||
}
|
||||
|
||||
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
|
||||
|
||||
if ($value != self::$_filter->filter($value)) {
|
||||
$this->_error(self::NOT_ALNUM);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
150
www/analytics/libs/Zend/Validate/Alpha.php
Normal file
150
www/analytics/libs/Zend/Validate/Alpha.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Alpha.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Alpha extends Zend_Validate_Abstract
|
||||
{
|
||||
const INVALID = 'alphaInvalid';
|
||||
const NOT_ALPHA = 'notAlpha';
|
||||
const STRING_EMPTY = 'alphaStringEmpty';
|
||||
|
||||
/**
|
||||
* Whether to allow white space characters; off by default
|
||||
*
|
||||
* @var boolean
|
||||
* @deprecated
|
||||
*/
|
||||
public $allowWhiteSpace;
|
||||
|
||||
/**
|
||||
* Alphabetic filter used for validation
|
||||
*
|
||||
* @var Zend_Filter_Alpha
|
||||
*/
|
||||
protected static $_filter = null;
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID => "Invalid type given. String expected",
|
||||
self::NOT_ALPHA => "'%value%' contains non alphabetic characters",
|
||||
self::STRING_EMPTY => "'%value%' is an empty string"
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets default option values for this instance
|
||||
*
|
||||
* @param boolean|Zend_Config $allowWhiteSpace
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($allowWhiteSpace = false)
|
||||
{
|
||||
if ($allowWhiteSpace instanceof Zend_Config) {
|
||||
$allowWhiteSpace = $allowWhiteSpace->toArray();
|
||||
}
|
||||
|
||||
if (is_array($allowWhiteSpace)) {
|
||||
if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) {
|
||||
$allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace'];
|
||||
} else {
|
||||
$allowWhiteSpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the allowWhiteSpace option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getAllowWhiteSpace()
|
||||
{
|
||||
return $this->allowWhiteSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowWhiteSpace option
|
||||
*
|
||||
* @param boolean $allowWhiteSpace
|
||||
* @return Zend_Filter_Alpha Provides a fluent interface
|
||||
*/
|
||||
public function setAllowWhiteSpace($allowWhiteSpace)
|
||||
{
|
||||
$this->allowWhiteSpace = (boolean) $allowWhiteSpace;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value contains only alphabetic characters
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_setValue($value);
|
||||
|
||||
if ('' === $value) {
|
||||
$this->_error(self::STRING_EMPTY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === self::$_filter) {
|
||||
/**
|
||||
* @see Zend_Filter_Alpha
|
||||
*/
|
||||
// require_once 'Zend/Filter/Alpha.php';
|
||||
self::$_filter = new Zend_Filter_Alpha();
|
||||
}
|
||||
|
||||
self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
|
||||
|
||||
if ($value !== self::$_filter->filter($value)) {
|
||||
$this->_error(self::NOT_ALPHA);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
224
www/analytics/libs/Zend/Validate/Between.php
Normal file
224
www/analytics/libs/Zend/Validate/Between.php
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Between.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Between extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* Validation failure message key for when the value is not between the min and max, inclusively
|
||||
*/
|
||||
const NOT_BETWEEN = 'notBetween';
|
||||
|
||||
/**
|
||||
* Validation failure message key for when the value is not strictly between the min and max
|
||||
*/
|
||||
const NOT_BETWEEN_STRICT = 'notBetweenStrict';
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::NOT_BETWEEN => "'%value%' is not between '%min%' and '%max%', inclusively",
|
||||
self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'"
|
||||
);
|
||||
|
||||
/**
|
||||
* Additional variables available for validation failure messages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'min' => '_min',
|
||||
'max' => '_max'
|
||||
);
|
||||
|
||||
/**
|
||||
* Minimum value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_min;
|
||||
|
||||
/**
|
||||
* Maximum value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_max;
|
||||
|
||||
/**
|
||||
* Whether to do inclusive comparisons, allowing equivalence to min and/or max
|
||||
*
|
||||
* If false, then strict comparisons are done, and the value may equal neither
|
||||
* the min nor max options
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_inclusive;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
* Accepts the following option keys:
|
||||
* 'min' => scalar, minimum border
|
||||
* 'max' => scalar, maximum border
|
||||
* 'inclusive' => boolean, inclusive border values
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} else if (!is_array($options)) {
|
||||
$options = func_get_args();
|
||||
$temp['min'] = array_shift($options);
|
||||
if (!empty($options)) {
|
||||
$temp['max'] = array_shift($options);
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
$temp['inclusive'] = array_shift($options);
|
||||
}
|
||||
|
||||
$options = $temp;
|
||||
}
|
||||
|
||||
if (!array_key_exists('min', $options) || !array_key_exists('max', $options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("Missing option. 'min' and 'max' has to be given");
|
||||
}
|
||||
|
||||
if (!array_key_exists('inclusive', $options)) {
|
||||
$options['inclusive'] = true;
|
||||
}
|
||||
|
||||
$this->setMin($options['min'])
|
||||
->setMax($options['max'])
|
||||
->setInclusive($options['inclusive']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the min option
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMin()
|
||||
{
|
||||
return $this->_min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the min option
|
||||
*
|
||||
* @param mixed $min
|
||||
* @return Zend_Validate_Between Provides a fluent interface
|
||||
*/
|
||||
public function setMin($min)
|
||||
{
|
||||
$this->_min = $min;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max option
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMax()
|
||||
{
|
||||
return $this->_max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max option
|
||||
*
|
||||
* @param mixed $max
|
||||
* @return Zend_Validate_Between Provides a fluent interface
|
||||
*/
|
||||
public function setMax($max)
|
||||
{
|
||||
$this->_max = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the inclusive option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getInclusive()
|
||||
{
|
||||
return $this->_inclusive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the inclusive option
|
||||
*
|
||||
* @param boolean $inclusive
|
||||
* @return Zend_Validate_Between Provides a fluent interface
|
||||
*/
|
||||
public function setInclusive($inclusive)
|
||||
{
|
||||
$this->_inclusive = $inclusive;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value is between min and max options, inclusively
|
||||
* if inclusive option is true.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
if ($this->_inclusive) {
|
||||
if ($this->_min > $value || $value > $this->_max) {
|
||||
$this->_error(self::NOT_BETWEEN);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($this->_min >= $value || $value >= $this->_max) {
|
||||
$this->_error(self::NOT_BETWEEN_STRICT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
174
www/analytics/libs/Zend/Validate/Callback.php
Normal file
174
www/analytics/libs/Zend/Validate/Callback.php
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Callback.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Callback extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* Invalid callback
|
||||
*/
|
||||
const INVALID_CALLBACK = 'callbackInvalid';
|
||||
|
||||
/**
|
||||
* Invalid value
|
||||
*/
|
||||
const INVALID_VALUE = 'callbackValue';
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID_VALUE => "'%value%' is not valid",
|
||||
self::INVALID_CALLBACK => "An exception has been raised within the callback",
|
||||
);
|
||||
|
||||
/**
|
||||
* Callback in a call_user_func format
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $_callback = null;
|
||||
|
||||
/**
|
||||
* Default options to set for the filter
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $callback
|
||||
* @param mixed $max
|
||||
* @param boolean $inclusive
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($callback = null)
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
$this->setCallback($callback);
|
||||
} elseif (is_array($callback)) {
|
||||
if (isset($callback['callback'])) {
|
||||
$this->setCallback($callback['callback']);
|
||||
}
|
||||
if (isset($callback['options'])) {
|
||||
$this->setOptions($callback['options']);
|
||||
}
|
||||
}
|
||||
|
||||
if (null === ($initializedCallack = $this->getCallback())) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('No callback registered');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set callback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->_callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback
|
||||
*
|
||||
* @param string|array $callback
|
||||
* @return Zend_Validate_Callback Provides a fluent interface
|
||||
*/
|
||||
public function setCallback($callback)
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid callback given');
|
||||
}
|
||||
$this->_callback = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set options for the callback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets options for the callback
|
||||
*
|
||||
* @param mixed $max
|
||||
* @return Zend_Validate_Callback Provides a fluent interface
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->_options = (array) $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the set callback returns
|
||||
* for the provided $value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
$options = $this->getOptions();
|
||||
$callback = $this->getCallback();
|
||||
$args = func_get_args();
|
||||
$options = array_merge($args, $options);
|
||||
|
||||
try {
|
||||
if (!call_user_func_array($callback, $options)) {
|
||||
$this->_error(self::INVALID_VALUE);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->_error(self::INVALID_CALLBACK);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
112
www/analytics/libs/Zend/Validate/Ccnum.php
Normal file
112
www/analytics/libs/Zend/Validate/Ccnum.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Ccnum.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Ccnum extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* Validation failure message key for when the value is not of valid length
|
||||
*/
|
||||
const LENGTH = 'ccnumLength';
|
||||
|
||||
/**
|
||||
* Validation failure message key for when the value fails the mod-10 checksum
|
||||
*/
|
||||
const CHECKSUM = 'ccnumChecksum';
|
||||
|
||||
/**
|
||||
* Digits filter for input
|
||||
*
|
||||
* @var Zend_Filter_Digits
|
||||
*/
|
||||
protected static $_filter = null;
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::LENGTH => "'%value%' must contain between 13 and 19 digits",
|
||||
self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
trigger_error('Using the Ccnum validator is deprecated in favor of the CreditCard validator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
if (null === self::$_filter) {
|
||||
/**
|
||||
* @see Zend_Filter_Digits
|
||||
*/
|
||||
// require_once 'Zend/Filter/Digits.php';
|
||||
self::$_filter = new Zend_Filter_Digits();
|
||||
}
|
||||
|
||||
$valueFiltered = self::$_filter->filter($value);
|
||||
|
||||
$length = strlen($valueFiltered);
|
||||
|
||||
if ($length < 13 || $length > 19) {
|
||||
$this->_error(self::LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
$sum = 0;
|
||||
$weight = 2;
|
||||
|
||||
for ($i = $length - 2; $i >= 0; $i--) {
|
||||
$digit = $weight * $valueFiltered[$i];
|
||||
$sum += floor($digit / 10) + $digit % 10;
|
||||
$weight = $weight % 2 + 1;
|
||||
}
|
||||
|
||||
if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) {
|
||||
$this->_error(self::CHECKSUM, $valueFiltered);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
317
www/analytics/libs/Zend/Validate/CreditCard.php
Normal file
317
www/analytics/libs/Zend/Validate/CreditCard.php
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: CreditCard.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_CreditCard extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* Detected CCI list
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ALL = 'All';
|
||||
const AMERICAN_EXPRESS = 'American_Express';
|
||||
const UNIONPAY = 'Unionpay';
|
||||
const DINERS_CLUB = 'Diners_Club';
|
||||
const DINERS_CLUB_US = 'Diners_Club_US';
|
||||
const DISCOVER = 'Discover';
|
||||
const JCB = 'JCB';
|
||||
const LASER = 'Laser';
|
||||
const MAESTRO = 'Maestro';
|
||||
const MASTERCARD = 'Mastercard';
|
||||
const SOLO = 'Solo';
|
||||
const VISA = 'Visa';
|
||||
|
||||
const CHECKSUM = 'creditcardChecksum';
|
||||
const CONTENT = 'creditcardContent';
|
||||
const INVALID = 'creditcardInvalid';
|
||||
const LENGTH = 'creditcardLength';
|
||||
const PREFIX = 'creditcardPrefix';
|
||||
const SERVICE = 'creditcardService';
|
||||
const SERVICEFAILURE = 'creditcardServiceFailure';
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::CHECKSUM => "'%value%' seems to contain an invalid checksum",
|
||||
self::CONTENT => "'%value%' must contain only digits",
|
||||
self::INVALID => "Invalid type given. String expected",
|
||||
self::LENGTH => "'%value%' contains an invalid amount of digits",
|
||||
self::PREFIX => "'%value%' is not from an allowed institute",
|
||||
self::SERVICE => "'%value%' seems to be an invalid creditcard number",
|
||||
self::SERVICEFAILURE => "An exception has been raised while validating '%value%'",
|
||||
);
|
||||
|
||||
/**
|
||||
* List of allowed CCV lengths
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_cardLength = array(
|
||||
self::AMERICAN_EXPRESS => array(15),
|
||||
self::DINERS_CLUB => array(14),
|
||||
self::DINERS_CLUB_US => array(16),
|
||||
self::DISCOVER => array(16),
|
||||
self::JCB => array(16),
|
||||
self::LASER => array(16, 17, 18, 19),
|
||||
self::MAESTRO => array(12, 13, 14, 15, 16, 17, 18, 19),
|
||||
self::MASTERCARD => array(16),
|
||||
self::SOLO => array(16, 18, 19),
|
||||
self::UNIONPAY => array(16, 17, 18, 19),
|
||||
self::VISA => array(16),
|
||||
);
|
||||
|
||||
/**
|
||||
* List of accepted CCV provider tags
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_cardType = array(
|
||||
self::AMERICAN_EXPRESS => array('34', '37'),
|
||||
self::DINERS_CLUB => array('300', '301', '302', '303', '304', '305', '36'),
|
||||
self::DINERS_CLUB_US => array('54', '55'),
|
||||
self::DISCOVER => array('6011', '622126', '622127', '622128', '622129', '62213',
|
||||
'62214', '62215', '62216', '62217', '62218', '62219',
|
||||
'6222', '6223', '6224', '6225', '6226', '6227', '6228',
|
||||
'62290', '62291', '622920', '622921', '622922', '622923',
|
||||
'622924', '622925', '644', '645', '646', '647', '648',
|
||||
'649', '65'),
|
||||
self::JCB => array('3528', '3529', '353', '354', '355', '356', '357', '358'),
|
||||
self::LASER => array('6304', '6706', '6771', '6709'),
|
||||
self::MAESTRO => array('5018', '5020', '5038', '6304', '6759', '6761', '6763'),
|
||||
self::MASTERCARD => array('51', '52', '53', '54', '55'),
|
||||
self::SOLO => array('6334', '6767'),
|
||||
self::UNIONPAY => array('622126', '622127', '622128', '622129', '62213', '62214',
|
||||
'62215', '62216', '62217', '62218', '62219', '6222', '6223',
|
||||
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
|
||||
'622920', '622921', '622922', '622923', '622924', '622925'),
|
||||
self::VISA => array('4'),
|
||||
);
|
||||
|
||||
/**
|
||||
* CCIs which are accepted by validation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_type = array();
|
||||
|
||||
/**
|
||||
* Service callback for additional validation
|
||||
*
|
||||
* @var callback
|
||||
*/
|
||||
protected $_service;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string|array $type OPTIONAL Type of CCI to allow
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} else if (!is_array($options)) {
|
||||
$options = func_get_args();
|
||||
$temp['type'] = array_shift($options);
|
||||
if (!empty($options)) {
|
||||
$temp['service'] = array_shift($options);
|
||||
}
|
||||
|
||||
$options = $temp;
|
||||
}
|
||||
|
||||
if (!array_key_exists('type', $options)) {
|
||||
$options['type'] = self::ALL;
|
||||
}
|
||||
|
||||
$this->setType($options['type']);
|
||||
if (array_key_exists('service', $options)) {
|
||||
$this->setService($options['service']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of accepted CCIs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets CCIs which are accepted by validation
|
||||
*
|
||||
* @param string|array $type Type to allow for validation
|
||||
* @return Zend_Validate_CreditCard Provides a fluid interface
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->_type = array();
|
||||
return $this->addType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a CCI to be accepted by validation
|
||||
*
|
||||
* @param string|array $type Type to allow for validation
|
||||
* @return Zend_Validate_CreditCard Provides a fluid interface
|
||||
*/
|
||||
public function addType($type)
|
||||
{
|
||||
if (is_string($type)) {
|
||||
$type = array($type);
|
||||
}
|
||||
|
||||
foreach($type as $typ) {
|
||||
if (defined('self::' . strtoupper($typ)) && !in_array($typ, $this->_type)) {
|
||||
$this->_type[] = $typ;
|
||||
}
|
||||
|
||||
if (($typ == self::ALL)) {
|
||||
$this->_type = array_keys($this->_cardLength);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the actual set service
|
||||
*
|
||||
* @return callback
|
||||
*/
|
||||
public function getService()
|
||||
{
|
||||
return $this->_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new callback for service validation
|
||||
*
|
||||
* @param unknown_type $service
|
||||
*/
|
||||
public function setService($service)
|
||||
{
|
||||
if (!is_callable($service)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid callback given');
|
||||
}
|
||||
|
||||
$this->_service = $service;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
if (!is_string($value)) {
|
||||
$this->_error(self::INVALID, $value);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ctype_digit($value)) {
|
||||
$this->_error(self::CONTENT, $value);
|
||||
return false;
|
||||
}
|
||||
|
||||
$length = strlen($value);
|
||||
$types = $this->getType();
|
||||
$foundp = false;
|
||||
$foundl = false;
|
||||
foreach ($types as $type) {
|
||||
foreach ($this->_cardType[$type] as $prefix) {
|
||||
if (substr($value, 0, strlen($prefix)) == $prefix) {
|
||||
$foundp = true;
|
||||
if (in_array($length, $this->_cardLength[$type])) {
|
||||
$foundl = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($foundp == false){
|
||||
$this->_error(self::PREFIX, $value);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($foundl == false) {
|
||||
$this->_error(self::LENGTH, $value);
|
||||
return false;
|
||||
}
|
||||
|
||||
$sum = 0;
|
||||
$weight = 2;
|
||||
|
||||
for ($i = $length - 2; $i >= 0; $i--) {
|
||||
$digit = $weight * $value[$i];
|
||||
$sum += floor($digit / 10) + $digit % 10;
|
||||
$weight = $weight % 2 + 1;
|
||||
}
|
||||
|
||||
if ((10 - $sum % 10) % 10 != $value[$length - 1]) {
|
||||
$this->_error(self::CHECKSUM, $value);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($this->_service)) {
|
||||
try {
|
||||
// require_once 'Zend/Validate/Callback.php';
|
||||
$callback = new Zend_Validate_Callback($this->_service);
|
||||
$callback->setOptions($this->_type);
|
||||
if (!$callback->isValid($value)) {
|
||||
$this->_error(self::SERVICE, $value);
|
||||
return false;
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
$this->_error(self::SERVICEFAILURE, $value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
259
www/analytics/libs/Zend/Validate/Date.php
Normal file
259
www/analytics/libs/Zend/Validate/Date.php
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Date.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Date extends Zend_Validate_Abstract
|
||||
{
|
||||
const INVALID = 'dateInvalid';
|
||||
const INVALID_DATE = 'dateInvalidDate';
|
||||
const FALSEFORMAT = 'dateFalseFormat';
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID => "Invalid type given. String, integer, array or Zend_Date expected",
|
||||
self::INVALID_DATE => "'%value%' does not appear to be a valid date",
|
||||
self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'",
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'format' => '_format'
|
||||
);
|
||||
|
||||
/**
|
||||
* Optional format
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_format;
|
||||
|
||||
/**
|
||||
* Optional locale
|
||||
*
|
||||
* @var string|Zend_Locale|null
|
||||
*/
|
||||
protected $_locale;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|Zend_Config $options OPTIONAL
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} else if (!is_array($options)) {
|
||||
$options = func_get_args();
|
||||
$temp['format'] = array_shift($options);
|
||||
if (!empty($options)) {
|
||||
$temp['locale'] = array_shift($options);
|
||||
}
|
||||
|
||||
$options = $temp;
|
||||
}
|
||||
|
||||
if (array_key_exists('format', $options)) {
|
||||
$this->setFormat($options['format']);
|
||||
}
|
||||
|
||||
if (!array_key_exists('locale', $options)) {
|
||||
// require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Locale')) {
|
||||
$options['locale'] = \Zend_Registry::get('Zend_Locale');
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('locale', $options)) {
|
||||
$this->setLocale($options['locale']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale option
|
||||
*
|
||||
* @return string|Zend_Locale|null
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->_locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the locale option
|
||||
*
|
||||
* @param string|Zend_Locale $locale
|
||||
* @return Zend_Validate_Date provides a fluent interface
|
||||
*/
|
||||
public function setLocale($locale = null)
|
||||
{
|
||||
// require_once 'Zend/Locale.php';
|
||||
$this->_locale = Zend_Locale::findLocale($locale);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale option
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFormat()
|
||||
{
|
||||
return $this->_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the format option
|
||||
*
|
||||
* @param string $format
|
||||
* @return Zend_Validate_Date provides a fluent interface
|
||||
*/
|
||||
public function setFormat($format = null)
|
||||
{
|
||||
$this->_format = $format;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if $value is a valid date of the format YYYY-MM-DD
|
||||
* If optional $format or $locale is set the date format is checked
|
||||
* according to Zend_Date, see Zend_Date::isDate()
|
||||
*
|
||||
* @param string|array|Zend_Date $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value) && !is_int($value) && !is_float($value) &&
|
||||
!is_array($value) && !($value instanceof Zend_Date)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_setValue($value);
|
||||
|
||||
if (($this->_format !== null) || ($this->_locale !== null) || is_array($value) ||
|
||||
$value instanceof Zend_Date) {
|
||||
// require_once 'Zend/Date.php';
|
||||
if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
|
||||
if ($this->_checkFormat($value) === false) {
|
||||
$this->_error(self::FALSEFORMAT);
|
||||
} else {
|
||||
$this->_error(self::INVALID_DATE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
|
||||
$this->_format = 'yyyy-MM-dd';
|
||||
$this->_error(self::FALSEFORMAT);
|
||||
$this->_format = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
list($year, $month, $day) = sscanf($value, '%d-%d-%d');
|
||||
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
$this->_error(self::INVALID_DATE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given date fits the given format
|
||||
*
|
||||
* @param string $value Date to check
|
||||
* @return boolean False when date does not fit the format
|
||||
*/
|
||||
private function _checkFormat($value)
|
||||
{
|
||||
try {
|
||||
// require_once 'Zend/Locale/Format.php';
|
||||
$parsed = Zend_Locale_Format::getDate($value, array(
|
||||
'date_format' => $this->_format, 'format_type' => 'iso',
|
||||
'fix_date' => false));
|
||||
if (isset($parsed['year']) and ((strpos(strtoupper($this->_format), 'YY') !== false) and
|
||||
(strpos(strtoupper($this->_format), 'YYYY') === false))) {
|
||||
$parsed['year'] = Zend_Date::getFullYear($parsed['year']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Date can not be parsed
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((strpos($this->_format, 'Y') !== false) or (strpos($this->_format, 'y') !== false)) and
|
||||
(!isset($parsed['year']))) {
|
||||
// Year expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((strpos($this->_format, 'M') !== false) and (!isset($parsed['month']))) {
|
||||
// Month expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((strpos($this->_format, 'd') !== false) and (!isset($parsed['day']))) {
|
||||
// Day expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((strpos($this->_format, 'H') !== false) or (strpos($this->_format, 'h') !== false)) and
|
||||
(!isset($parsed['hour']))) {
|
||||
// Hour expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((strpos($this->_format, 'm') !== false) and (!isset($parsed['minute']))) {
|
||||
// Minute expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((strpos($this->_format, 's') !== false) and (!isset($parsed['second']))) {
|
||||
// Second expected but not found
|
||||
return false;
|
||||
}
|
||||
|
||||
// Date fits the format
|
||||
return true;
|
||||
}
|
||||
}
|
||||
91
www/analytics/libs/Zend/Validate/Digits.php
Normal file
91
www/analytics/libs/Zend/Validate/Digits.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Digits.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Digits extends Zend_Validate_Abstract
|
||||
{
|
||||
const NOT_DIGITS = 'notDigits';
|
||||
const STRING_EMPTY = 'digitsStringEmpty';
|
||||
const INVALID = 'digitsInvalid';
|
||||
|
||||
/**
|
||||
* Digits filter used for validation
|
||||
*
|
||||
* @var Zend_Filter_Digits
|
||||
*/
|
||||
protected static $_filter = null;
|
||||
|
||||
/**
|
||||
* Validation failure message template definitions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::NOT_DIGITS => "'%value%' must contain only digits",
|
||||
self::STRING_EMPTY => "'%value%' is an empty string",
|
||||
self::INVALID => "Invalid type given. String, integer or float expected",
|
||||
);
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value only contains digit characters
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value) && !is_int($value) && !is_float($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_setValue((string) $value);
|
||||
|
||||
if ('' === $this->_value) {
|
||||
$this->_error(self::STRING_EMPTY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === self::$_filter) {
|
||||
// require_once 'Zend/Filter/Digits.php';
|
||||
self::$_filter = new Zend_Filter_Digits();
|
||||
}
|
||||
|
||||
if ($this->_value !== self::$_filter->filter($this->_value)) {
|
||||
$this->_error(self::NOT_DIGITS);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
560
www/analytics/libs/Zend/Validate/EmailAddress.php
Normal file
560
www/analytics/libs/Zend/Validate/EmailAddress.php
Normal file
|
|
@ -0,0 +1,560 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: EmailAddress.php 24304 2011-07-30 01:12:35Z adamlundrigan $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Hostname
|
||||
*/
|
||||
// require_once 'Zend/Validate/Hostname.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
|
||||
{
|
||||
const INVALID = 'emailAddressInvalid';
|
||||
const INVALID_FORMAT = 'emailAddressInvalidFormat';
|
||||
const INVALID_HOSTNAME = 'emailAddressInvalidHostname';
|
||||
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord';
|
||||
const INVALID_SEGMENT = 'emailAddressInvalidSegment';
|
||||
const DOT_ATOM = 'emailAddressDotAtom';
|
||||
const QUOTED_STRING = 'emailAddressQuotedString';
|
||||
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
|
||||
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID => "Invalid type given. String expected",
|
||||
self::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part@hostname",
|
||||
self::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'",
|
||||
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
|
||||
self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network",
|
||||
self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
|
||||
self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format",
|
||||
self::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'",
|
||||
self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length",
|
||||
);
|
||||
|
||||
/**
|
||||
* @see http://en.wikipedia.org/wiki/IPv4
|
||||
* @var array
|
||||
*/
|
||||
protected $_invalidIp = array(
|
||||
'0' => '0.0.0.0/8',
|
||||
'10' => '10.0.0.0/8',
|
||||
'127' => '127.0.0.0/8',
|
||||
'128' => '128.0.0.0/16',
|
||||
'169' => '169.254.0.0/16',
|
||||
'172' => '172.16.0.0/12',
|
||||
'191' => '191.255.0.0/16',
|
||||
'192' => array(
|
||||
'192.0.0.0/24',
|
||||
'192.0.2.0/24',
|
||||
'192.88.99.0/24',
|
||||
'192.168.0.0/16'
|
||||
),
|
||||
'198' => '198.18.0.0/15',
|
||||
'223' => '223.255.255.0/24',
|
||||
'224' => '224.0.0.0/4',
|
||||
'240' => '240.0.0.0/4'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'hostname' => '_hostname',
|
||||
'localPart' => '_localPart'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_hostname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_localPart;
|
||||
|
||||
/**
|
||||
* Internal options array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'mx' => false,
|
||||
'deep' => false,
|
||||
'domain' => true,
|
||||
'allow' => Zend_Validate_Hostname::ALLOW_DNS,
|
||||
'hostname' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Instantiates hostname validator for local use
|
||||
*
|
||||
* The following option keys are supported:
|
||||
* 'hostname' => A hostname validator, see Zend_Validate_Hostname
|
||||
* 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_*
|
||||
* 'mx' => If MX check should be enabled, boolean
|
||||
* 'deep' => If a deep MX check should be done, boolean
|
||||
*
|
||||
* @param array|Zend_Config $options OPTIONAL
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} else if (!is_array($options)) {
|
||||
$options = func_get_args();
|
||||
$temp['allow'] = array_shift($options);
|
||||
if (!empty($options)) {
|
||||
$temp['mx'] = array_shift($options);
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
$temp['hostname'] = array_shift($options);
|
||||
}
|
||||
|
||||
$options = $temp;
|
||||
}
|
||||
|
||||
$options += $this->_options;
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all set Options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options for the email validator
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Validate_EmailAddress fluid interface
|
||||
*/
|
||||
public function setOptions(array $options = array())
|
||||
{
|
||||
if (array_key_exists('messages', $options)) {
|
||||
$this->setMessages($options['messages']);
|
||||
}
|
||||
|
||||
if (array_key_exists('hostname', $options)) {
|
||||
if (array_key_exists('allow', $options)) {
|
||||
$this->setHostnameValidator($options['hostname'], $options['allow']);
|
||||
} else {
|
||||
$this->setHostnameValidator($options['hostname']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('mx', $options)) {
|
||||
$this->setValidateMx($options['mx']);
|
||||
}
|
||||
|
||||
if (array_key_exists('deep', $options)) {
|
||||
$this->setDeepMxCheck($options['deep']);
|
||||
}
|
||||
|
||||
if (array_key_exists('domain', $options)) {
|
||||
$this->setDomainCheck($options['domain']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the validation failure message template for a particular key
|
||||
* Adds the ability to set messages to the attached hostname validator
|
||||
*
|
||||
* @param string $messageString
|
||||
* @param string $messageKey OPTIONAL
|
||||
* @return Zend_Validate_Abstract Provides a fluent interface
|
||||
* @throws Zend_Validate_Exception
|
||||
*/
|
||||
public function setMessage($messageString, $messageKey = null)
|
||||
{
|
||||
$messageKeys = $messageKey;
|
||||
if ($messageKey === null) {
|
||||
$keys = array_keys($this->_messageTemplates);
|
||||
$messageKeys = current($keys);
|
||||
}
|
||||
|
||||
if (!isset($this->_messageTemplates[$messageKeys])) {
|
||||
$this->_options['hostname']->setMessage($messageString, $messageKey);
|
||||
}
|
||||
|
||||
$this->_messageTemplates[$messageKeys] = $messageString;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set hostname validator
|
||||
*
|
||||
* @return Zend_Validate_Hostname
|
||||
*/
|
||||
public function getHostnameValidator()
|
||||
{
|
||||
return $this->_options['hostname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
|
||||
* @param int $allow OPTIONAL
|
||||
* @return void
|
||||
*/
|
||||
public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS)
|
||||
{
|
||||
if (!$hostnameValidator) {
|
||||
$hostnameValidator = new Zend_Validate_Hostname($allow);
|
||||
}
|
||||
|
||||
$this->_options['hostname'] = $hostnameValidator;
|
||||
$this->_options['allow'] = $allow;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether MX checking via getmxrr is supported or not
|
||||
*
|
||||
* This currently only works on UNIX systems
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function validateMxSupported()
|
||||
{
|
||||
return function_exists('getmxrr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set validateMx option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getValidateMx()
|
||||
{
|
||||
return $this->_options['mx'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether we check for a valid MX record via DNS
|
||||
*
|
||||
* This only applies when DNS hostnames are validated
|
||||
*
|
||||
* @param boolean $mx Set allowed to true to validate for MX records, and false to not validate them
|
||||
* @return Zend_Validate_EmailAddress Fluid Interface
|
||||
*/
|
||||
public function setValidateMx($mx)
|
||||
{
|
||||
if ((bool) $mx && !$this->validateMxSupported()) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('MX checking not available on this system');
|
||||
}
|
||||
|
||||
$this->_options['mx'] = (bool) $mx;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set deepMxCheck option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getDeepMxCheck()
|
||||
{
|
||||
return $this->_options['deep'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether we check MX record should be a deep validation
|
||||
*
|
||||
* @param boolean $deep Set deep to true to perform a deep validation process for MX records
|
||||
* @return Zend_Validate_EmailAddress Fluid Interface
|
||||
*/
|
||||
public function setDeepMxCheck($deep)
|
||||
{
|
||||
$this->_options['deep'] = (bool) $deep;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set domainCheck option
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
public function getDomainCheck()
|
||||
{
|
||||
return $this->_options['domain'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the domain should also be checked
|
||||
* or only the local part of the email address
|
||||
*
|
||||
* @param boolean $domain
|
||||
* @return Zend_Validate_EmailAddress Fluid Interface
|
||||
*/
|
||||
public function setDomainCheck($domain = true)
|
||||
{
|
||||
$this->_options['domain'] = (boolean) $domain;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the given host is reserved
|
||||
*
|
||||
* @param string $host
|
||||
* @return boolean
|
||||
*/
|
||||
private function _isReserved($host){
|
||||
if (!preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $host)) {
|
||||
$host = gethostbyname($host);
|
||||
}
|
||||
|
||||
$octet = explode('.',$host);
|
||||
if ((int)$octet[0] >= 224) {
|
||||
return true;
|
||||
} else if (array_key_exists($octet[0], $this->_invalidIp)) {
|
||||
foreach ((array)$this->_invalidIp[$octet[0]] as $subnetData) {
|
||||
// we skip the first loop as we already know that octet matches
|
||||
for ($i = 1; $i < 4; $i++) {
|
||||
if (strpos($subnetData, $octet[$i]) !== $i * 4) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$host = explode("/", $subnetData);
|
||||
$binaryHost = "";
|
||||
$tmp = explode(".", $host[0]);
|
||||
for ($i = 0; $i < 4 ; $i++) {
|
||||
$binaryHost .= str_pad(decbin($tmp[$i]), 8, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$segmentData = array(
|
||||
'network' => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 0)),
|
||||
'broadcast' => (int)$this->_toIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 1))
|
||||
);
|
||||
|
||||
for ($j = $i; $j < 4; $j++) {
|
||||
if ((int)$octet[$j] < $segmentData['network'][$j] ||
|
||||
(int)$octet[$j] > $segmentData['broadcast'][$j]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a binary string to an IP address
|
||||
*
|
||||
* @param string $binary
|
||||
* @return mixed
|
||||
*/
|
||||
private function _toIp($binary)
|
||||
{
|
||||
$ip = array();
|
||||
$tmp = explode(".", chunk_split($binary, 8, "."));
|
||||
for ($i = 0; $i < 4 ; $i++) {
|
||||
$ip[$i] = bindec($tmp[$i]);
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to validate the local part of the email address
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function _validateLocalPart()
|
||||
{
|
||||
// First try to match the local part on the common dot-atom format
|
||||
$result = false;
|
||||
|
||||
// Dot-atom characters are: 1*atext *("." 1*atext)
|
||||
// atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
|
||||
// "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
|
||||
$atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e';
|
||||
if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
|
||||
$result = true;
|
||||
} else {
|
||||
// Try quoted string format
|
||||
|
||||
// Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
|
||||
// qtext: Non white space controls, and the rest of the US-ASCII characters not
|
||||
// including "\" or the quote character
|
||||
$noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f';
|
||||
$qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e';
|
||||
$ws = '\x20\x09';
|
||||
if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) {
|
||||
$result = true;
|
||||
} else {
|
||||
$this->_error(self::DOT_ATOM);
|
||||
$this->_error(self::QUOTED_STRING);
|
||||
$this->_error(self::INVALID_LOCAL_PART);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to validate the servers MX records
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function _validateMXRecords()
|
||||
{
|
||||
$mxHosts = array();
|
||||
$result = getmxrr($this->_hostname, $mxHosts);
|
||||
if (!$result) {
|
||||
$this->_error(self::INVALID_MX_RECORD);
|
||||
} else if ($this->_options['deep'] && function_exists('checkdnsrr')) {
|
||||
$validAddress = false;
|
||||
$reserved = true;
|
||||
foreach ($mxHosts as $hostname) {
|
||||
$res = $this->_isReserved($hostname);
|
||||
if (!$res) {
|
||||
$reserved = false;
|
||||
}
|
||||
|
||||
if (!$res
|
||||
&& (checkdnsrr($hostname, "A")
|
||||
|| checkdnsrr($hostname, "AAAA")
|
||||
|| checkdnsrr($hostname, "A6"))) {
|
||||
$validAddress = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$validAddress) {
|
||||
$result = false;
|
||||
if ($reserved) {
|
||||
$this->_error(self::INVALID_SEGMENT);
|
||||
} else {
|
||||
$this->_error(self::INVALID_MX_RECORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to validate the hostname part of the email address
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function _validateHostnamePart()
|
||||
{
|
||||
$hostname = $this->_options['hostname']->setTranslator($this->getTranslator())
|
||||
->isValid($this->_hostname);
|
||||
if (!$hostname) {
|
||||
$this->_error(self::INVALID_HOSTNAME);
|
||||
|
||||
// Get messages and errors from hostnameValidator
|
||||
foreach ($this->_options['hostname']->getMessages() as $code => $message) {
|
||||
$this->_messages[$code] = $message;
|
||||
}
|
||||
|
||||
foreach ($this->_options['hostname']->getErrors() as $error) {
|
||||
$this->_errors[] = $error;
|
||||
}
|
||||
} else if ($this->_options['mx']) {
|
||||
// MX check on hostname
|
||||
$hostname = $this->_validateMXRecords();
|
||||
}
|
||||
|
||||
return $hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if $value is a valid email address
|
||||
* according to RFC2822
|
||||
*
|
||||
* @link http://www.ietf.org/rfc/rfc2822.txt RFC2822
|
||||
* @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
$length = true;
|
||||
$this->_setValue($value);
|
||||
|
||||
// Split email address up and disallow '..'
|
||||
if ((strpos($value, '..') !== false) or
|
||||
(!preg_match('/^(.+)@([^@]+)$/', $value, $matches))) {
|
||||
$this->_error(self::INVALID_FORMAT);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_localPart = $matches[1];
|
||||
$this->_hostname = $matches[2];
|
||||
|
||||
if ((strlen($this->_localPart) > 64) || (strlen($this->_hostname) > 255)) {
|
||||
$length = false;
|
||||
$this->_error(self::LENGTH_EXCEEDED);
|
||||
}
|
||||
|
||||
// Match hostname part
|
||||
if ($this->_options['domain']) {
|
||||
$hostname = $this->_validateHostnamePart();
|
||||
}
|
||||
|
||||
$local = $this->_validateLocalPart();
|
||||
|
||||
// If both parts valid, return true
|
||||
if ($local && $length) {
|
||||
if (($this->_options['domain'] && $hostname) || !$this->_options['domain']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
34
www/analytics/libs/Zend/Validate/Exception.php
Normal file
34
www/analytics/libs/Zend/Validate/Exception.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
// require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Exception extends Zend_Exception
|
||||
{}
|
||||
284
www/analytics/libs/Zend/Validate/File/Count.php
Normal file
284
www/analytics/libs/Zend/Validate/File/Count.php
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Count.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Validator for counting all given files
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_Count extends Zend_Validate_Abstract
|
||||
{
|
||||
/**#@+
|
||||
* @const string Error constants
|
||||
*/
|
||||
const TOO_MANY = 'fileCountTooMany';
|
||||
const TOO_FEW = 'fileCountTooFew';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::TOO_MANY => "Too many files, maximum '%max%' are allowed but '%count%' are given",
|
||||
self::TOO_FEW => "Too few files, minimum '%min%' are expected but '%count%' are given",
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Error message template variables
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'min' => '_min',
|
||||
'max' => '_max',
|
||||
'count' => '_count'
|
||||
);
|
||||
|
||||
/**
|
||||
* Minimum file count
|
||||
*
|
||||
* If null, there is no minimum file count
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_min;
|
||||
|
||||
/**
|
||||
* Maximum file count
|
||||
*
|
||||
* If null, there is no maximum file count
|
||||
*
|
||||
* @var integer|null
|
||||
*/
|
||||
protected $_max;
|
||||
|
||||
/**
|
||||
* Actual filecount
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_count;
|
||||
|
||||
/**
|
||||
* Internal file array
|
||||
* @var array
|
||||
*/
|
||||
protected $_files;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* Min limits the file count, when used with max=null it is the maximum file count
|
||||
* It also accepts an array with the keys 'min' and 'max'
|
||||
*
|
||||
* If $options is a integer, it will be used as maximum file count
|
||||
* As Array is accepts the following keys:
|
||||
* 'min': Minimum filecount
|
||||
* 'max': Maximum filecount
|
||||
*
|
||||
* @param integer|array|Zend_Config $options Options for the adapter
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_string($options) || is_numeric($options)) {
|
||||
$options = array('max' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
$options['min'] = func_get_arg(0);
|
||||
$options['max'] = func_get_arg(1);
|
||||
}
|
||||
|
||||
if (isset($options['min'])) {
|
||||
$this->setMin($options);
|
||||
}
|
||||
|
||||
if (isset($options['max'])) {
|
||||
$this->setMax($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum file count
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMin()
|
||||
{
|
||||
return $this->_min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum file count
|
||||
*
|
||||
* @param integer|array $min The minimum file count
|
||||
* @return Zend_Validate_File_Count Provides a fluent interface
|
||||
* @throws Zend_Validate_Exception When min is greater than max
|
||||
*/
|
||||
public function setMin($min)
|
||||
{
|
||||
if (is_array($min) and isset($min['min'])) {
|
||||
$min = $min['min'];
|
||||
}
|
||||
|
||||
if (!is_string($min) and !is_numeric($min)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
$min = (integer) $min;
|
||||
if (($this->_max !== null) && ($min > $this->_max)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum file count, but $min >"
|
||||
. " {$this->_max}");
|
||||
}
|
||||
|
||||
$this->_min = $min;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum file count
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMax()
|
||||
{
|
||||
return $this->_max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum file count
|
||||
*
|
||||
* @param integer|array $max The maximum file count
|
||||
* @return Zend_Validate_StringLength Provides a fluent interface
|
||||
* @throws Zend_Validate_Exception When max is smaller than min
|
||||
*/
|
||||
public function setMax($max)
|
||||
{
|
||||
if (is_array($max) and isset($max['max'])) {
|
||||
$max = $max['max'];
|
||||
}
|
||||
|
||||
if (!is_string($max) and !is_numeric($max)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
$max = (integer) $max;
|
||||
if (($this->_min !== null) && ($max < $this->_min)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum file count, but "
|
||||
. "$max < {$this->_min}");
|
||||
}
|
||||
|
||||
$this->_max = $max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file for validation
|
||||
*
|
||||
* @param string|array $file
|
||||
*/
|
||||
public function addFile($file)
|
||||
{
|
||||
if (is_string($file)) {
|
||||
$file = array($file);
|
||||
}
|
||||
|
||||
if (is_array($file)) {
|
||||
foreach ($file as $name) {
|
||||
if (!isset($this->_files[$name]) && !empty($name)) {
|
||||
$this->_files[$name] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the file count of all checked files is at least min and
|
||||
* not bigger than max (when max is not null). Attention: When checking with set min you
|
||||
* must give all files with the first call, otherwise you will get an false.
|
||||
*
|
||||
* @param string|array $value Filenames to check for count
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
if (($file !== null) && !array_key_exists('destination', $file)) {
|
||||
$file['destination'] = dirname($value);
|
||||
}
|
||||
|
||||
if (($file !== null) && array_key_exists('tmp_name', $file)) {
|
||||
$value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name'];
|
||||
}
|
||||
|
||||
if (($file === null) || !empty($file['tmp_name'])) {
|
||||
$this->addFile($value);
|
||||
}
|
||||
|
||||
$this->_count = count($this->_files);
|
||||
if (($this->_max !== null) && ($this->_count > $this->_max)) {
|
||||
return $this->_throw($file, self::TOO_MANY);
|
||||
}
|
||||
|
||||
if (($this->_min !== null) && ($this->_count < $this->_min)) {
|
||||
return $this->_throw($file, self::TOO_FEW);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $errorType
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if ($file !== null) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
179
www/analytics/libs/Zend/Validate/File/Crc32.php
Normal file
179
www/analytics/libs/Zend/Validate/File/Crc32.php
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Crc32.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_File_Hash
|
||||
*/
|
||||
// require_once 'Zend/Validate/File/Hash.php';
|
||||
|
||||
/**
|
||||
* Validator for the crc32 hash of given files
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const DOES_NOT_MATCH = 'fileCrc32DoesNotMatch';
|
||||
const NOT_DETECTED = 'fileCrc32NotDetected';
|
||||
const NOT_FOUND = 'fileCrc32NotFound';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::DOES_NOT_MATCH => "File '%value%' does not match the given crc32 hashes",
|
||||
self::NOT_DETECTED => "A crc32 hash could not be evaluated for the given file",
|
||||
self::NOT_FOUND => "File '%value%' is not readable or does not exist",
|
||||
);
|
||||
|
||||
/**
|
||||
* Hash of the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_hash;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_scalar($options)) {
|
||||
$options = array('hash1' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
$this->setCrc32($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all set crc32 hashes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCrc32()
|
||||
{
|
||||
return $this->getHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the crc32 hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function setHash($options)
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
$options = array($options);
|
||||
}
|
||||
|
||||
$options['algorithm'] = 'crc32';
|
||||
parent::setHash($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the crc32 hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function setCrc32($options)
|
||||
{
|
||||
$this->setHash($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the crc32 hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function addHash($options)
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
$options = array($options);
|
||||
}
|
||||
|
||||
$options['algorithm'] = 'crc32';
|
||||
parent::addHash($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the crc32 hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function addCrc32($options)
|
||||
{
|
||||
$this->addHash($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the given file confirms the set hash
|
||||
*
|
||||
* @param string $value Filename to check for hash
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_FOUND);
|
||||
}
|
||||
|
||||
$hashes = array_unique(array_keys($this->_hash));
|
||||
$filehash = hash_file('crc32', $value);
|
||||
if ($filehash === false) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
foreach($hashes as $hash) {
|
||||
if ($filehash === $hash) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::DOES_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
94
www/analytics/libs/Zend/Validate/File/ExcludeExtension.php
Normal file
94
www/analytics/libs/Zend/Validate/File/ExcludeExtension.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ExcludeExtension.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/File/Extension.php';
|
||||
|
||||
/**
|
||||
* Validator for the excluding file extensions
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const FALSE_EXTENSION = 'fileExcludeExtensionFalse';
|
||||
const NOT_FOUND = 'fileExcludeExtensionNotFound';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::FALSE_EXTENSION => "File '%value%' has a false extension",
|
||||
self::NOT_FOUND => "File '%value%' is not readable or does not exist",
|
||||
);
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the fileextension of $value is not included in the
|
||||
* set extension list
|
||||
*
|
||||
* @param string $value Real file to check for extension
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
$info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
|
||||
} else {
|
||||
$info = pathinfo($value);
|
||||
}
|
||||
|
||||
$extensions = $this->getExtension();
|
||||
|
||||
if ($this->_case and (!in_array($info['extension'], $extensions))) {
|
||||
return true;
|
||||
} else if (!$this->_case) {
|
||||
$found = false;
|
||||
foreach ($extensions as $extension) {
|
||||
if (strtolower($extension) == strtolower($info['extension'])) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::FALSE_EXTENSION);
|
||||
}
|
||||
}
|
||||
109
www/analytics/libs/Zend/Validate/File/ExcludeMimeType.php
Normal file
109
www/analytics/libs/Zend/Validate/File/ExcludeMimeType.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ExcludeMimeType.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_File_MimeType
|
||||
*/
|
||||
// require_once 'Zend/Validate/File/MimeType.php';
|
||||
|
||||
/**
|
||||
* Validator for the mime type of a file
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType
|
||||
{
|
||||
const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
|
||||
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
|
||||
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if the mimetype of the file does not matche the given ones. Also parts
|
||||
* of mimetypes can be checked. If you give for example "image" all image
|
||||
* mime types will not be accepted like "image/gif", "image/jpeg" and so on.
|
||||
*
|
||||
* @param string $value Real file to check for mimetype
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
if ($file === null) {
|
||||
$file = array(
|
||||
'type' => null,
|
||||
'name' => $value
|
||||
);
|
||||
}
|
||||
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
$mimefile = $this->getMagicFile();
|
||||
if (class_exists('finfo', false)) {
|
||||
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
|
||||
if (!empty($mimefile)) {
|
||||
$mime = new finfo($const, $mimefile);
|
||||
} else {
|
||||
$mime = new finfo($const);
|
||||
}
|
||||
|
||||
if (!empty($mime)) {
|
||||
$this->_type = $mime->file($value);
|
||||
}
|
||||
unset($mime);
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} elseif ($this->_headerCheck) {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
$mimetype = $this->getMimeType(true);
|
||||
if (in_array($this->_type, $mimetype)) {
|
||||
return $this->_throw($file, self::FALSE_TYPE);
|
||||
}
|
||||
|
||||
$types = explode('/', $this->_type);
|
||||
$types = array_merge($types, explode('-', $this->_type));
|
||||
foreach($mimetype as $mime) {
|
||||
if (in_array($mime, $types)) {
|
||||
return $this->_throw($file, self::FALSE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
203
www/analytics/libs/Zend/Validate/File/Exists.php
Normal file
203
www/analytics/libs/Zend/Validate/File/Exists.php
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exists.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Validator which checks if the file already exists in the directory
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_Exists extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const DOES_NOT_EXIST = 'fileExistsDoesNotExist';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::DOES_NOT_EXIST => "File '%value%' does not exist",
|
||||
);
|
||||
|
||||
/**
|
||||
* Internal list of directories
|
||||
* @var string
|
||||
*/
|
||||
protected $_directory = '';
|
||||
|
||||
/**
|
||||
* @var array Error message template variables
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'directory' => '_directory'
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array|Zend_Config $directory
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($directory = array())
|
||||
{
|
||||
if ($directory instanceof Zend_Config) {
|
||||
$directory = $directory->toArray();
|
||||
} else if (is_string($directory)) {
|
||||
$directory = explode(',', $directory);
|
||||
} else if (!is_array($directory)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
$this->setDirectory($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set file directories which are checked
|
||||
*
|
||||
* @param boolean $asArray Returns the values as array, when false an concated string is returned
|
||||
* @return string
|
||||
*/
|
||||
public function getDirectory($asArray = false)
|
||||
{
|
||||
$asArray = (bool) $asArray;
|
||||
$directory = (string) $this->_directory;
|
||||
if ($asArray) {
|
||||
$directory = explode(',', $directory);
|
||||
}
|
||||
|
||||
return $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file directory which will be checked
|
||||
*
|
||||
* @param string|array $directory The directories to validate
|
||||
* @return Zend_Validate_File_Extension Provides a fluent interface
|
||||
*/
|
||||
public function setDirectory($directory)
|
||||
{
|
||||
$this->_directory = null;
|
||||
$this->addDirectory($directory);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the file directory which will be checked
|
||||
*
|
||||
* @param string|array $directory The directory to add for validation
|
||||
* @return Zend_Validate_File_Extension Provides a fluent interface
|
||||
*/
|
||||
public function addDirectory($directory)
|
||||
{
|
||||
$directories = $this->getDirectory(true);
|
||||
|
||||
if (is_string($directory)) {
|
||||
$directory = explode(',', $directory);
|
||||
} else if (!is_array($directory)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
foreach ($directory as $content) {
|
||||
if (empty($content) || !is_string($content)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$directories[] = trim($content);
|
||||
}
|
||||
$directories = array_unique($directories);
|
||||
|
||||
// Sanity check to ensure no empty values
|
||||
foreach ($directories as $key => $dir) {
|
||||
if (empty($dir)) {
|
||||
unset($directories[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_directory = implode(',', $directories);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the file already exists in the set directories
|
||||
*
|
||||
* @param string $value Real file to check for existance
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
$directories = $this->getDirectory(true);
|
||||
if (($file !== null) and (!empty($file['destination']))) {
|
||||
$directories[] = $file['destination'];
|
||||
} else if (!isset($file['name'])) {
|
||||
$file['name'] = $value;
|
||||
}
|
||||
|
||||
$check = false;
|
||||
foreach ($directories as $directory) {
|
||||
if (empty($directory)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$check = true;
|
||||
if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) {
|
||||
return $this->_throw($file, self::DOES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$check) {
|
||||
return $this->_throw($file, self::DOES_NOT_EXIST);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $errorType
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if ($file !== null) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
232
www/analytics/libs/Zend/Validate/File/Extension.php
Normal file
232
www/analytics/libs/Zend/Validate/File/Extension.php
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Extension.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Validator for the file extension of a file
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_Extension extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const FALSE_EXTENSION = 'fileExtensionFalse';
|
||||
const NOT_FOUND = 'fileExtensionNotFound';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::FALSE_EXTENSION => "File '%value%' has a false extension",
|
||||
self::NOT_FOUND => "File '%value%' is not readable or does not exist",
|
||||
);
|
||||
|
||||
/**
|
||||
* Internal list of extensions
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '';
|
||||
|
||||
/**
|
||||
* Validate case sensitive
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_case = false;
|
||||
|
||||
/**
|
||||
* @var array Error message template variables
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'extension' => '_extension'
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
$case = func_get_arg(1);
|
||||
$this->setCase($case);
|
||||
}
|
||||
|
||||
if (is_array($options) and isset($options['case'])) {
|
||||
$this->setCase($options['case']);
|
||||
unset($options['case']);
|
||||
}
|
||||
|
||||
$this->setExtension($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the case option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCase()
|
||||
{
|
||||
return $this->_case;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the case to use
|
||||
*
|
||||
* @param boolean $case
|
||||
* @return Zend_Validate_File_Extension Provides a fluent interface
|
||||
*/
|
||||
public function setCase($case)
|
||||
{
|
||||
$this->_case = (boolean) $case;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set file extension
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
$extension = explode(',', $this->_extension);
|
||||
|
||||
return $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extensions
|
||||
*
|
||||
* @param string|array $extension The extensions to validate
|
||||
* @return Zend_Validate_File_Extension Provides a fluent interface
|
||||
*/
|
||||
public function setExtension($extension)
|
||||
{
|
||||
$this->_extension = null;
|
||||
$this->addExtension($extension);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the file extensions
|
||||
*
|
||||
* @param string|array $extension The extensions to add for validation
|
||||
* @return Zend_Validate_File_Extension Provides a fluent interface
|
||||
*/
|
||||
public function addExtension($extension)
|
||||
{
|
||||
$extensions = $this->getExtension();
|
||||
if (is_string($extension)) {
|
||||
$extension = explode(',', $extension);
|
||||
}
|
||||
|
||||
foreach ($extension as $content) {
|
||||
if (empty($content) || !is_string($content)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extensions[] = trim($content);
|
||||
}
|
||||
$extensions = array_unique($extensions);
|
||||
|
||||
// Sanity check to ensure no empty values
|
||||
foreach ($extensions as $key => $ext) {
|
||||
if (empty($ext)) {
|
||||
unset($extensions[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_extension = implode(',', $extensions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the fileextension of $value is included in the
|
||||
* set extension list
|
||||
*
|
||||
* @param string $value Real file to check for extension
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
$info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
|
||||
} else {
|
||||
$info = pathinfo($value);
|
||||
}
|
||||
|
||||
$extensions = $this->getExtension();
|
||||
|
||||
if ($this->_case && (in_array($info['extension'], $extensions))) {
|
||||
return true;
|
||||
} else if (!$this->getCase()) {
|
||||
foreach ($extensions as $extension) {
|
||||
if (strtolower($extension) == strtolower($info['extension'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::FALSE_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $errorType
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if (null !== $file) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
164
www/analytics/libs/Zend/Validate/File/FilesSize.php
Normal file
164
www/analytics/libs/Zend/Validate/File/FilesSize.php
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FilesSize.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_File_Size
|
||||
*/
|
||||
// require_once 'Zend/Validate/File/Size.php';
|
||||
|
||||
/**
|
||||
* Validator for the size of all files which will be validated in sum
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const TOO_BIG = 'fileFilesSizeTooBig';
|
||||
const TOO_SMALL = 'fileFilesSizeTooSmall';
|
||||
const NOT_READABLE = 'fileFilesSizeNotReadable';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::TOO_BIG => "All files in sum should have a maximum size of '%max%' but '%size%' were detected",
|
||||
self::TOO_SMALL => "All files in sum should have a minimum size of '%min%' but '%size%' were detected",
|
||||
self::NOT_READABLE => "One or more files can not be read",
|
||||
);
|
||||
|
||||
/**
|
||||
* Internal file array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_files;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
|
||||
* It also accepts an array with the keys 'min' and 'max'
|
||||
*
|
||||
* @param integer|array|Zend_Config $options Options for this validator
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->_files = array();
|
||||
$this->_setSize(0);
|
||||
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_scalar($options)) {
|
||||
$options = array('max' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
$argv = func_get_args();
|
||||
array_shift($argv);
|
||||
$options['max'] = array_shift($argv);
|
||||
if (!empty($argv)) {
|
||||
$options['bytestring'] = array_shift($argv);
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the disk usage of all files is at least min and
|
||||
* not bigger than max (when max is not null).
|
||||
*
|
||||
* @param string|array $value Real file to check for size
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (is_string($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
$min = $this->getMin(true);
|
||||
$max = $this->getMax(true);
|
||||
$size = $this->_getSize();
|
||||
foreach ($value as $files) {
|
||||
// Is file readable ?
|
||||
if (!Zend_Loader::isReadable($files)) {
|
||||
$this->_throw($file, self::NOT_READABLE);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($this->_files[$files])) {
|
||||
$this->_files[$files] = $files;
|
||||
} else {
|
||||
// file already counted... do not count twice
|
||||
continue;
|
||||
}
|
||||
|
||||
// limited to 2GB files
|
||||
$size += @filesize($files);
|
||||
$this->_size = $size;
|
||||
if (($max !== null) && ($max < $size)) {
|
||||
if ($this->useByteString()) {
|
||||
$this->_max = $this->_toByteString($max);
|
||||
$this->_size = $this->_toByteString($size);
|
||||
$this->_throw($file, self::TOO_BIG);
|
||||
$this->_max = $max;
|
||||
$this->_size = $size;
|
||||
} else {
|
||||
$this->_throw($file, self::TOO_BIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check that aggregate files are >= minimum size
|
||||
if (($min !== null) && ($size < $min)) {
|
||||
if ($this->useByteString()) {
|
||||
$this->_min = $this->_toByteString($min);
|
||||
$this->_size = $this->_toByteString($size);
|
||||
$this->_throw($file, self::TOO_SMALL);
|
||||
$this->_min = $min;
|
||||
$this->_size = $size;
|
||||
} else {
|
||||
$this->_throw($file, self::TOO_SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->_messages) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
194
www/analytics/libs/Zend/Validate/File/Hash.php
Normal file
194
www/analytics/libs/Zend/Validate/File/Hash.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hash.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Validator for the hash of given files
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_Hash extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const DOES_NOT_MATCH = 'fileHashDoesNotMatch';
|
||||
const NOT_DETECTED = 'fileHashHashNotDetected';
|
||||
const NOT_FOUND = 'fileHashNotFound';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::DOES_NOT_MATCH => "File '%value%' does not match the given hashes",
|
||||
self::NOT_DETECTED => "A hash could not be evaluated for the given file",
|
||||
self::NOT_FOUND => "File '%value%' is not readable or does not exist"
|
||||
);
|
||||
|
||||
/**
|
||||
* Hash of the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_hash;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_scalar($options)) {
|
||||
$options = array('hash1' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
$options['algorithm'] = func_get_arg(1);
|
||||
}
|
||||
|
||||
$this->setHash($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set hash values as array, the hash as key and the algorithm the value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHash()
|
||||
{
|
||||
return $this->_hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function setHash($options)
|
||||
{
|
||||
$this->_hash = null;
|
||||
$this->addHash($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the hash for one or multiple files
|
||||
*
|
||||
* @param string|array $options
|
||||
* @return Zend_Validate_File_Hash Provides a fluent interface
|
||||
*/
|
||||
public function addHash($options)
|
||||
{
|
||||
if (is_string($options)) {
|
||||
$options = array($options);
|
||||
} else if (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("False parameter given");
|
||||
}
|
||||
|
||||
$known = hash_algos();
|
||||
if (!isset($options['algorithm'])) {
|
||||
$algorithm = 'crc32';
|
||||
} else {
|
||||
$algorithm = $options['algorithm'];
|
||||
unset($options['algorithm']);
|
||||
}
|
||||
|
||||
if (!in_array($algorithm, $known)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("Unknown algorithm '{$algorithm}'");
|
||||
}
|
||||
|
||||
foreach ($options as $value) {
|
||||
$this->_hash[$value] = $algorithm;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the given file confirms the set hash
|
||||
*
|
||||
* @param string $value Filename to check for hash
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_FOUND);
|
||||
}
|
||||
|
||||
$algos = array_unique(array_values($this->_hash));
|
||||
$hashes = array_unique(array_keys($this->_hash));
|
||||
foreach ($algos as $algorithm) {
|
||||
$filehash = hash_file($algorithm, $value);
|
||||
if ($filehash === false) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
foreach($hashes as $hash) {
|
||||
if ($filehash === $hash) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::DOES_NOT_MATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $errorType
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if ($file !== null) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
364
www/analytics/libs/Zend/Validate/File/ImageSize.php
Normal file
364
www/analytics/libs/Zend/Validate/File/ImageSize.php
Normal file
|
|
@ -0,0 +1,364 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ImageSize.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
// require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Validator for the image size of a image file
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @const string Error constants
|
||||
*/
|
||||
const WIDTH_TOO_BIG = 'fileImageSizeWidthTooBig';
|
||||
const WIDTH_TOO_SMALL = 'fileImageSizeWidthTooSmall';
|
||||
const HEIGHT_TOO_BIG = 'fileImageSizeHeightTooBig';
|
||||
const HEIGHT_TOO_SMALL = 'fileImageSizeHeightTooSmall';
|
||||
const NOT_DETECTED = 'fileImageSizeNotDetected';
|
||||
const NOT_READABLE = 'fileImageSizeNotReadable';
|
||||
|
||||
/**
|
||||
* @var array Error message template
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::WIDTH_TOO_BIG => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected",
|
||||
self::WIDTH_TOO_SMALL => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected",
|
||||
self::HEIGHT_TOO_BIG => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected",
|
||||
self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected",
|
||||
self::NOT_DETECTED => "The size of image '%value%' could not be detected",
|
||||
self::NOT_READABLE => "File '%value%' is not readable or does not exist",
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Error message template variables
|
||||
*/
|
||||
protected $_messageVariables = array(
|
||||
'minwidth' => '_minwidth',
|
||||
'maxwidth' => '_maxwidth',
|
||||
'minheight' => '_minheight',
|
||||
'maxheight' => '_maxheight',
|
||||
'width' => '_width',
|
||||
'height' => '_height'
|
||||
);
|
||||
|
||||
/**
|
||||
* Minimum image width
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_minwidth;
|
||||
|
||||
/**
|
||||
* Maximum image width
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_maxwidth;
|
||||
|
||||
/**
|
||||
* Minimum image height
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_minheight;
|
||||
|
||||
/**
|
||||
* Maximum image height
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_maxheight;
|
||||
|
||||
/**
|
||||
* Detected width
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_width;
|
||||
|
||||
/**
|
||||
* Detected height
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_height;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* Accepts the following option keys:
|
||||
* - minheight
|
||||
* - minwidth
|
||||
* - maxheight
|
||||
* - maxwidth
|
||||
*
|
||||
* @param Zend_Config|array $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (1 < func_num_args()) {
|
||||
if (!is_array($options)) {
|
||||
$options = array('minwidth' => $options);
|
||||
}
|
||||
$argv = func_get_args();
|
||||
array_shift($argv);
|
||||
$options['minheight'] = array_shift($argv);
|
||||
if (!empty($argv)) {
|
||||
$options['maxwidth'] = array_shift($argv);
|
||||
if (!empty($argv)) {
|
||||
$options['maxheight'] = array_shift($argv);
|
||||
}
|
||||
}
|
||||
} else if (!is_array($options)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception ('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
if (isset($options['minheight']) || isset($options['minwidth'])) {
|
||||
$this->setImageMin($options);
|
||||
}
|
||||
|
||||
if (isset($options['maxheight']) || isset($options['maxwidth'])) {
|
||||
$this->setImageMax($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set minimum image sizes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImageMin()
|
||||
{
|
||||
return array('minwidth' => $this->_minwidth, 'minheight' => $this->_minheight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set maximum image sizes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImageMax()
|
||||
{
|
||||
return array('maxwidth' => $this->_maxwidth, 'maxheight' => $this->_maxheight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set image width sizes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImageWidth()
|
||||
{
|
||||
return array('minwidth' => $this->_minwidth, 'maxwidth' => $this->_maxwidth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set image height sizes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImageHeight()
|
||||
{
|
||||
return array('minheight' => $this->_minheight, 'maxheight' => $this->_maxheight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum image size
|
||||
*
|
||||
* @param array $options The minimum image dimensions
|
||||
* @throws Zend_Validate_Exception When minwidth is greater than maxwidth
|
||||
* @throws Zend_Validate_Exception When minheight is greater than maxheight
|
||||
* @return Zend_Validate_File_ImageSize Provides a fluent interface
|
||||
*/
|
||||
public function setImageMin($options)
|
||||
{
|
||||
if (isset($options['minwidth'])) {
|
||||
if (($this->_maxwidth !== null) and ($options['minwidth'] > $this->_maxwidth)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The minimum image width must be less than or equal to the "
|
||||
. " maximum image width, but {$options['minwidth']} > {$this->_maxwidth}");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['maxheight'])) {
|
||||
if (($this->_maxheight !== null) and ($options['minheight'] > $this->_maxheight)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The minimum image height must be less than or equal to the "
|
||||
. " maximum image height, but {$options['minheight']} > {$this->_maxheight}");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['minwidth'])) {
|
||||
$this->_minwidth = (int) $options['minwidth'];
|
||||
}
|
||||
|
||||
if (isset($options['minheight'])) {
|
||||
$this->_minheight = (int) $options['minheight'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum image size
|
||||
*
|
||||
* @param array $options The maximum image dimensions
|
||||
* @throws Zend_Validate_Exception When maxwidth is smaller than minwidth
|
||||
* @throws Zend_Validate_Exception When maxheight is smaller than minheight
|
||||
* @return Zend_Validate_StringLength Provides a fluent interface
|
||||
*/
|
||||
public function setImageMax($options)
|
||||
{
|
||||
if (isset($options['maxwidth'])) {
|
||||
if (($this->_minwidth !== null) and ($options['maxwidth'] < $this->_minwidth)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The maximum image width must be greater than or equal to the "
|
||||
. "minimum image width, but {$options['maxwidth']} < {$this->_minwidth}");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['maxheight'])) {
|
||||
if (($this->_minheight !== null) and ($options['maxheight'] < $this->_minheight)) {
|
||||
// require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("The maximum image height must be greater than or equal to the "
|
||||
. "minimum image height, but {$options['maxheight']} < {$this->_minwidth}");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['maxwidth'])) {
|
||||
$this->_maxwidth = (int) $options['maxwidth'];
|
||||
}
|
||||
|
||||
if (isset($options['maxheight'])) {
|
||||
$this->_maxheight = (int) $options['maxheight'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mimimum and maximum image width
|
||||
*
|
||||
* @param array $options The image width dimensions
|
||||
* @return Zend_Validate_File_ImageSize Provides a fluent interface
|
||||
*/
|
||||
public function setImageWidth($options)
|
||||
{
|
||||
$this->setImageMin($options);
|
||||
$this->setImageMax($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mimimum and maximum image height
|
||||
*
|
||||
* @param array $options The image height dimensions
|
||||
* @return Zend_Validate_File_ImageSize Provides a fluent interface
|
||||
*/
|
||||
public function setImageHeight($options)
|
||||
{
|
||||
$this->setImageMin($options);
|
||||
$this->setImageMax($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the imagesize of $value is at least min and
|
||||
* not bigger than max
|
||||
*
|
||||
* @param string $value Real file to check for image size
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
// require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
$size = @getimagesize($value);
|
||||
$this->_setValue($file);
|
||||
|
||||
if (empty($size) or ($size[0] === 0) or ($size[1] === 0)) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
$this->_width = $size[0];
|
||||
$this->_height = $size[1];
|
||||
if ($this->_width < $this->_minwidth) {
|
||||
$this->_throw($file, self::WIDTH_TOO_SMALL);
|
||||
}
|
||||
|
||||
if (($this->_maxwidth !== null) and ($this->_maxwidth < $this->_width)) {
|
||||
$this->_throw($file, self::WIDTH_TOO_BIG);
|
||||
}
|
||||
|
||||
if ($this->_height < $this->_minheight) {
|
||||
$this->_throw($file, self::HEIGHT_TOO_SMALL);
|
||||
}
|
||||
|
||||
if (($this->_maxheight !== null) and ($this->_maxheight < $this->_height)) {
|
||||
$this->_throw($file, self::HEIGHT_TOO_BIG);
|
||||
}
|
||||
|
||||
if (count($this->_messages) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $errorType
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if ($file !== null) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue