ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
HTMLPurifier_AttrDef_HTML_ID Class Reference

Validates the HTML attribute ID. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_HTML_ID:
+ Collaboration diagram for HTMLPurifier_AttrDef_HTML_ID:

Public Member Functions

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

 $selector
 Determines whether or not we're validating an ID in a CSS selector context. 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 the HTML attribute ID.

Warning
Even though this is the id processor, it will ignore the directive Attr:IDBlacklist, since it will only go according to the ID accumulator. Since the accumulator is automatically generated, it will have already absorbed the blacklist. If you're hacking around, make sure you use load()!

Definition at line 12 of file ID.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_HTML_ID::__construct (   $selector = false)
Parameters
bool$selector

Definition at line 28 of file ID.php.

References $selector.

29  {
30  $this->selector = $selector;
31  }
$selector
Determines whether or not we're validating an ID in a CSS selector context.
Definition: ID.php:23

Member Function Documentation

◆ validate()

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

Definition at line 39 of file ID.php.

References $config.

40  {
41  if (!$this->selector && !$config->get('Attr.EnableID')) {
42  return false;
43  }
44 
45  $id = trim($id); // trim it first
46 
47  if ($id === '') {
48  return false;
49  }
50 
51  $prefix = $config->get('Attr.IDPrefix');
52  if ($prefix !== '') {
53  $prefix .= $config->get('Attr.IDPrefixLocal');
54  // prevent re-appending the prefix
55  if (strpos($id, $prefix) !== 0) {
56  $id = $prefix . $id;
57  }
58  } elseif ($config->get('Attr.IDPrefixLocal') !== '') {
59  trigger_error(
60  '%Attr.IDPrefixLocal cannot be used unless ' .
61  '%Attr.IDPrefix is set',
62  E_USER_WARNING
63  );
64  }
65 
66  if (!$this->selector) {
67  $id_accumulator =& $context->get('IDAccumulator');
68  if (isset($id_accumulator->ids[$id])) {
69  return false;
70  }
71  }
72 
73  // we purposely avoid using regex, hopefully this is faster
74 
75  if ($config->get('Attr.ID.HTML5') === true) {
76  if (preg_match('/[\t\n\x0b\x0c ]/', $id)) {
77  return false;
78  }
79  } else {
80  if (ctype_alpha($id)) {
81  // OK
82  } else {
83  if (!ctype_alpha(@$id[0])) {
84  return false;
85  }
86  // primitive style of regexps, I suppose
87  $trim = trim(
88  $id,
89  'A..Za..z0..9:-._'
90  );
91  if ($trim !== '') {
92  return false;
93  }
94  }
95  }
96 
97  $regexp = $config->get('Attr.IDBlacklistRegexp');
98  if ($regexp && preg_match($regexp, $id)) {
99  return false;
100  }
101 
102  if (!$this->selector) {
103  $id_accumulator->add($id);
104  }
105 
106  // if no change was made to the ID, return the result
107  // else, return the new id if stripping whitespace made it
108  // valid, or return false.
109  return $id;
110  }

Field Documentation

◆ $selector

HTMLPurifier_AttrDef_HTML_ID::$selector
protected

Determines whether or not we're validating an ID in a CSS selector context.

bool

Definition at line 23 of file ID.php.

Referenced by __construct().


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