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

Validates the HTML type length (not to be confused with CSS's length). More...

+ Inheritance diagram for HTMLPurifier_AttrDef_HTML_Length:
+ Collaboration diagram for HTMLPurifier_AttrDef_HTML_Length:

Public Member Functions

 validate ($string, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef_HTML_Pixels
 __construct ($max=null)
 
 validate ($string, $config, $context)
 
 make ($string)
 
- 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...
 

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...
 
- Protected Attributes inherited from HTMLPurifier_AttrDef_HTML_Pixels
 $max
 int More...
 

Detailed Description

Validates the HTML type length (not to be confused with CSS's length).

This accepts integer pixels or percentages as lengths for certain HTML attributes.

Definition at line 10 of file Length.php.

Member Function Documentation

◆ validate()

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

Definition at line 19 of file Length.php.

20  {
21  $string = trim($string);
22  if ($string === '') {
23  return false;
24  }
25 
26  $parent_result = parent::validate($string, $config, $context);
27  if ($parent_result !== false) {
28  return $parent_result;
29  }
30 
31  $length = strlen($string);
32  $last_char = $string[$length - 1];
33 
34  if ($last_char !== '%') {
35  return false;
36  }
37 
38  $points = substr($string, 0, $length - 1);
39 
40  if (!is_numeric($points)) {
41  return false;
42  }
43 
44  $points = (int)$points;
45 
46  if ($points < 0) {
47  return '0%';
48  }
49  if ($points > 100) {
50  return '100%';
51  }
52  return ((string)$points) . '%';
53  }

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