ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition. More...
 
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA. More...
 
 make ($string)
 Factory method for creating this class from a string. More...
 

Protected Attributes

 $non_negative = false
 Indicates whether or not only positive values are allowed. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized. More...
 
 $required = false
 Tells us whether or not an HTML attribute is required. More...
 
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
 
 expandCSSEscape ($string)
 Parses a possibly escaped CSS string and returns the "pure" version of it. More...
 

Detailed Description

Validates a number as defined by the CSS spec.

Definition at line 6 of file Number.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_Number::__construct (   $non_negative = false)
Parameters
bool$non_negativeindicates whether negatives are forbidden

Definition at line 18 of file Number.php.

References $non_negative.

19  {
20  $this->non_negative = $non_negative;
21  }
$non_negative
Indicates whether or not only positive values are allowed.
Definition: Number.php:13

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_Number::validate (   $number,
  $config,
  $context 
)
Parameters
string$number
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
string|bool
Warning
Some contexts do not pass $config, $context. These variables should not be used without checking HTMLPurifier_Length

Definition at line 31 of file Number.php.

References HTMLPurifier_AttrDef\parseCDATA().

32  {
33  $number = $this->parseCDATA($number);
34 
35  if ($number === '') {
36  return false;
37  }
38  if ($number === '0') {
39  return '0';
40  }
41 
42  $sign = '';
43  switch ($number[0]) {
44  case '-':
45  if ($this->non_negative) {
46  return false;
47  }
48  $sign = '-';
49  case '+':
50  $number = substr($number, 1);
51  }
52 
53  if (ctype_digit($number)) {
54  $number = ltrim($number, '0');
55  return $number ? $sign . $number : '0';
56  }
57 
58  // Period is the only non-numeric character allowed
59  if (strpos($number, '.') === false) {
60  return false;
61  }
62 
63  list($left, $right) = explode('.', $number, 2);
64 
65  if ($left === '' && $right === '') {
66  return false;
67  }
68  if ($left !== '' && !ctype_digit($left)) {
69  return false;
70  }
71 
72  // Remove leading zeros until positive number or a zero stays left
73  if (ltrim($left, '0') != '') {
74  $left = ltrim($left, '0');
75  } else {
76  $left = '0';
77  }
78 
79  $right = rtrim($right, '0');
80 
81  if ($right === '') {
82  return $left ? $sign . $left : '0';
83  } elseif (!ctype_digit($right)) {
84  return false;
85  }
86  return $sign . $left . '.' . $right;
87  }
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
+ Here is the call graph for this function:

Field Documentation

◆ $non_negative

HTMLPurifier_AttrDef_CSS_Number::$non_negative = false
protected

Indicates whether or not only positive values are allowed.

bool

Definition at line 13 of file Number.php.

Referenced by __construct().


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