@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The abstract class for validators.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Validator
|
||||
*/
|
||||
abstract class Ai1ec_Validator extends Ai1ec_Base {
|
||||
|
||||
/**
|
||||
* @var mixed The value to validate.
|
||||
*/
|
||||
protected $_value;
|
||||
|
||||
/**
|
||||
* @var mixed Additional info needed for complex validation
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*
|
||||
* @param Ai1ec_Registry_Object $registry
|
||||
* @param string $value
|
||||
* @param mixed $context
|
||||
*/
|
||||
public function __construct( Ai1ec_Registry_Object $registry, $value, $context = array() ) {
|
||||
parent::__construct( $registry );
|
||||
$this->_value = $value;
|
||||
$this->_context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the value.
|
||||
*
|
||||
* @throws Ai1ec_Value_Not_Valid_Exception if the velue is not valid.
|
||||
*
|
||||
* @return mixed the validated value (allows to set it to default)
|
||||
*/
|
||||
abstract public function validate();
|
||||
|
||||
}
|
||||
27
wp-content/plugins/all-in-one-event-calendar/lib/validator/email.php
Executable file
27
wp-content/plugins/all-in-one-event-calendar/lib/validator/email.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Email validator.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.3
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Validator
|
||||
*/
|
||||
class Ai1ec_Validator_Email extends Ai1ec_Validator {
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see Ai1ec_Validator::validate()
|
||||
*/
|
||||
public function validate() {
|
||||
if (
|
||||
! empty( $this->_value ) &&
|
||||
! is_email( $this->_value )
|
||||
) {
|
||||
throw new Ai1ec_Value_Not_Valid_Exception();
|
||||
}
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The exception thrown when value doesn't pass validation.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Validator
|
||||
*/
|
||||
class Ai1ec_Value_Not_Valid_Exception extends Ai1ec_Exception {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Human readable size validator.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Validator
|
||||
*/
|
||||
class Ai1ec_Validator_Human_Readable_Size extends Ai1ec_Validator {
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see Ai1ec_Validator::validate()
|
||||
*/
|
||||
public function validate() {
|
||||
$checked_string = trim( strtoupper( $this->_value ) );
|
||||
|
||||
// Bytes - Get the first number
|
||||
$bytes = '0';
|
||||
preg_match( '/^([0-9\.]+)/', $checked_string, $matches );
|
||||
if ( count( $matches ) == 2 ) {
|
||||
$bytes = $matches[1];
|
||||
}
|
||||
|
||||
// Unit - Get the first letter
|
||||
$unit = 'B';
|
||||
preg_match( '/([KMGT]{1})/', $checked_string, $matches );
|
||||
if ( count( $matches ) == 2 ) {
|
||||
$unit = $matches[1];
|
||||
}
|
||||
|
||||
return $bytes . $unit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Numeric validator.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Validator
|
||||
*/
|
||||
class Ai1ec_Validator_Numeric_Or_Default extends Ai1ec_Validator {
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see Ai1ec_Validator::validate()
|
||||
*/
|
||||
public function validate() {
|
||||
if ( ! is_numeric( $this->_value ) ) {
|
||||
throw new Ai1ec_Value_Not_Valid_Exception();
|
||||
}
|
||||
return (int)$this->_value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user