ILIAS  release_4-4 Revision
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)

Definition at line 24 of file ID.php.

References $selector.

24  {
25  $this->selector = $selector;
26  }
$selector
Determines whether or not we're validating an ID in a CSS selector context.
Definition: ID.php:22

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_HTML_ID::validate (   $id,
  $config,
  $context 
)

Definition at line 28 of file ID.php.

References $result.

28  {
29 
30  if (!$this->selector && !$config->get('Attr.EnableID')) return false;
31 
32  $id = trim($id); // trim it first
33 
34  if ($id === '') return false;
35 
36  $prefix = $config->get('Attr.IDPrefix');
37  if ($prefix !== '') {
38  $prefix .= $config->get('Attr.IDPrefixLocal');
39  // prevent re-appending the prefix
40  if (strpos($id, $prefix) !== 0) $id = $prefix . $id;
41  } elseif ($config->get('Attr.IDPrefixLocal') !== '') {
42  trigger_error('%Attr.IDPrefixLocal cannot be used unless '.
43  '%Attr.IDPrefix is set', E_USER_WARNING);
44  }
45 
46  if (!$this->selector) {
47  $id_accumulator =& $context->get('IDAccumulator');
48  if (isset($id_accumulator->ids[$id])) return false;
49  }
50 
51  // we purposely avoid using regex, hopefully this is faster
52 
53  if (ctype_alpha($id)) {
54  $result = true;
55  } else {
56  if (!ctype_alpha(@$id[0])) return false;
57  $trim = trim( // primitive style of regexps, I suppose
58  $id,
59  'A..Za..z0..9:-._'
60  );
61  $result = ($trim === '');
62  }
63 
64  $regexp = $config->get('Attr.IDBlacklistRegexp');
65  if ($regexp && preg_match($regexp, $id)) {
66  return false;
67  }
68 
69  if (!$this->selector && $result) $id_accumulator->add($id);
70 
71  // if no change was made to the ID, return the result
72  // else, return the new id if stripping whitespace made it
73  // valid, or return false.
74  return $result ? $id : false;
75 
76  }
$result

Field Documentation

◆ $selector

HTMLPurifier_AttrDef_HTML_ID::$selector
protected

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

Definition at line 22 of file ID.php.

Referenced by __construct().


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