ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
HTMLPurifier_AttrDef_CSS_Percentage Class Reference

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

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_Percentage:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_Percentage:

Public Member Functions

 __construct ($non_negative=false)
 
 validate ($string, $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

 $number_def
 Instance to defer number validation to. 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 Percentage as defined by the CSS spec.

Definition at line 6 of file Percentage.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_Percentage::__construct (   $non_negative = false)
Parameters
bool$non_negativeWhether to forbid negative values

Definition at line 18 of file Percentage.php.

19  {
20  $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
21  }
Validates a number as defined by the CSS spec.
Definition: Number.php:6

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_Percentage::validate (   $string,
  $config,
  $context 
)
Parameters
string$string
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string

Definition at line 29 of file Percentage.php.

References HTMLPurifier_AttrDef\parseCDATA().

30  {
31  $string = $this->parseCDATA($string);
32 
33  if ($string === '') {
34  return false;
35  }
36  $length = strlen($string);
37  if ($length === 1) {
38  return false;
39  }
40  if ($string[$length - 1] !== '%') {
41  return false;
42  }
43 
44  $number = substr($string, 0, $length - 1);
45  $number = $this->number_def->validate($number, $config, $context);
46 
47  if ($number === false) {
48  return false;
49  }
50  return "$number%";
51  }
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

◆ $number_def

HTMLPurifier_AttrDef_CSS_Percentage::$number_def
protected

Instance to defer number validation to.

HTMLPurifier_AttrDef_CSS_Number

Definition at line 13 of file Percentage.php.


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