ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_AttrDef_CSS_Number Class Reference

Validates a number as defined by the CSS spec. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_Number:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_Number:

Public Member Functions

 __construct ($non_negative=false)
 validate ($number, $config, $context)
- Public Member Functions inherited from HTMLPurifier_AttrDef
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA.
 make ($string)
 Factory method for creating this class from a string.

Protected Attributes

 $non_negative = false
 Bool indicating whether or not only positive values allowed.

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized.
 $required = false
 Tells us whether or not an HTML attribute is required.
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly.

Detailed Description

Validates a number as defined by the CSS spec.

Definition at line 6 of file Number.php.

Constructor & Destructor Documentation

HTMLPurifier_AttrDef_CSS_Number::__construct (   $non_negative = false)
Parameters
$non_negativeBool indicating whether negatives are forbidden

Definition at line 17 of file Number.php.

References $non_negative.

{
$this->non_negative = $non_negative;
}

Member Function Documentation

HTMLPurifier_AttrDef_CSS_Number::validate (   $number,
  $config,
  $context 
)
Warning
Some contexts do not pass $config, $context. These variables should not be used without checking HTMLPurifier_Length

Reimplemented from HTMLPurifier_AttrDef.

Reimplemented in HTMLPurifier_AttrDef_CSS_AlphaValue.

Definition at line 25 of file Number.php.

References elseif(), and HTMLPurifier_AttrDef\parseCDATA().

{
$number = $this->parseCDATA($number);
if ($number === '') return false;
if ($number === '0') return '0';
$sign = '';
switch ($number[0]) {
case '-':
if ($this->non_negative) return false;
$sign = '-';
case '+':
$number = substr($number, 1);
}
if (ctype_digit($number)) {
$number = ltrim($number, '0');
return $number ? $sign . $number : '0';
}
// Period is the only non-numeric character allowed
if (strpos($number, '.') === false) return false;
list($left, $right) = explode('.', $number, 2);
if ($left === '' && $right === '') return false;
if ($left !== '' && !ctype_digit($left)) return false;
$left = ltrim($left, '0');
$right = rtrim($right, '0');
if ($right === '') {
return $left ? $sign . $left : '0';
} elseif (!ctype_digit($right)) {
return false;
}
return $sign . $left . '.' . $right;
}

+ Here is the call graph for this function:

Field Documentation

HTMLPurifier_AttrDef_CSS_Number::$non_negative = false
protected

Bool indicating whether or not only positive values allowed.

Definition at line 12 of file Number.php.

Referenced by __construct().


The documentation for this class was generated from the following file: