ILIAS  release_4-4 Revision
HTMLPurifier_EntityParser Class Reference

Handles referencing and derefencing character entities. More...

+ Collaboration diagram for HTMLPurifier_EntityParser:

Public Member Functions

 substituteNonSpecialEntities ($string)
 Substitutes non-special entities with their parsed equivalents. More...
 
 substituteSpecialEntities ($string)
 Substitutes only special entities with their parsed equivalents. More...
 

Protected Member Functions

 nonSpecialEntityCallback ($matches)
 Callback function for substituteNonSpecialEntities() that does the work. More...
 
 specialEntityCallback ($matches)
 Callback function for substituteSpecialEntities() that does the work. More...
 

Protected Attributes

 $_entity_lookup
 Reference to entity lookup table. More...
 
 $_substituteEntitiesRegex
 Callback regex string for parsing entities. More...
 
 $_special_dec2str
 Decimal to parsed string conversion table for special entities. More...
 
 $_special_ent2dec
 Stripped entity names to decimal conversion table for special entities. More...
 

Detailed Description

Handles referencing and derefencing character entities.

Definition at line 10 of file EntityParser.php.

Member Function Documentation

◆ nonSpecialEntityCallback()

HTMLPurifier_EntityParser::nonSpecialEntityCallback (   $matches)
protected

Callback function for substituteNonSpecialEntities() that does the work.

Parameters
$matchesPCRE matches array, with 0 the entire match, and either index 1, 2 or 3 set with a hex value, dec value, or string (respectively).
Returns
Replacement string.

Definition at line 75 of file EntityParser.php.

References HTMLPurifier_EntityLookup\instance(), and HTMLPurifier_Encoder\unichr().

75  {
76  // replaces all but big five
77  $entity = $matches[0];
78  $is_num = (@$matches[0][1] === '#');
79  if ($is_num) {
80  $is_hex = (@$entity[2] === 'x');
81  $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2];
82 
83  // abort for special characters
84  if (isset($this->_special_dec2str[$code])) return $entity;
85 
86  return HTMLPurifier_Encoder::unichr($code);
87  } else {
88  if (isset($this->_special_ent2dec[$matches[3]])) return $entity;
89  if (!$this->_entity_lookup) {
90  $this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
91  }
92  if (isset($this->_entity_lookup->table[$matches[3]])) {
93  return $this->_entity_lookup->table[$matches[3]];
94  } else {
95  return $entity;
96  }
97  }
98  }
static unichr($code)
Translates a Unicode codepoint into its corresponding UTF-8 character.
Definition: Encoder.php:288
static instance($prototype=false)
Retrieves sole instance of the object.
+ Here is the call graph for this function:

◆ specialEntityCallback()

HTMLPurifier_EntityParser::specialEntityCallback (   $matches)
protected

Callback function for substituteSpecialEntities() that does the work.

This callback has same syntax as nonSpecialEntityCallback().

Parameters
$matchesPCRE-style matches array, with 0 the entire match, and either index 1, 2 or 3 set with a hex value, dec value, or string (respectively).
Returns
Replacement string.

Definition at line 126 of file EntityParser.php.

126  {
127  $entity = $matches[0];
128  $is_num = (@$matches[0][1] === '#');
129  if ($is_num) {
130  $is_hex = (@$entity[2] === 'x');
131  $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2];
132  return isset($this->_special_dec2str[$int]) ?
133  $this->_special_dec2str[$int] :
134  $entity;
135  } else {
136  return isset($this->_special_ent2dec[$matches[3]]) ?
137  $this->_special_ent2dec[$matches[3]] :
138  $entity;
139  }
140  }

◆ substituteNonSpecialEntities()

HTMLPurifier_EntityParser::substituteNonSpecialEntities (   $string)

Substitutes non-special entities with their parsed equivalents.

Since running this whenever you have parsed character is t3h 5uck, we run it before everything else.

Parameters
$stringString to have non-special entities parsed.
Returns
Parsed string.

Definition at line 57 of file EntityParser.php.

57  {
58  // it will try to detect missing semicolons, but don't rely on it
59  return preg_replace_callback(
60  $this->_substituteEntitiesRegex,
61  array($this, 'nonSpecialEntityCallback'),
62  $string
63  );
64  }

◆ substituteSpecialEntities()

HTMLPurifier_EntityParser::substituteSpecialEntities (   $string)

Substitutes only special entities with their parsed equivalents.

We try to avoid calling this function because otherwise, it would have to be called a lot (for every parsed section).

Parameters
$stringString to have non-special entities parsed.
Returns
Parsed string.

Definition at line 109 of file EntityParser.php.

109  {
110  return preg_replace_callback(
111  $this->_substituteEntitiesRegex,
112  array($this, 'specialEntityCallback'),
113  $string);
114  }

Field Documentation

◆ $_entity_lookup

HTMLPurifier_EntityParser::$_entity_lookup
protected

Reference to entity lookup table.

Definition at line 16 of file EntityParser.php.

◆ $_special_dec2str

HTMLPurifier_EntityParser::$_special_dec2str
protected
Initial value:
=
array(
34 => '"',
38 => '&',
39 => "'",
60 => '<',
62 => '>'
)

Decimal to parsed string conversion table for special entities.

Definition at line 29 of file EntityParser.php.

◆ $_special_ent2dec

HTMLPurifier_EntityParser::$_special_ent2dec
protected
Initial value:
=
array(
'quot' => 34,
'amp' => 38,
'lt' => 60,
'gt' => 62
)

Stripped entity names to decimal conversion table for special entities.

Definition at line 41 of file EntityParser.php.

◆ $_substituteEntitiesRegex

HTMLPurifier_EntityParser::$_substituteEntitiesRegex
protected
Initial value:
=
'/&(?:[#]x([a-fA-F0-9]+)|[#]0*(\d+)|([A-Za-z_:][A-Za-z0-9.\-_:]*));?/'

Callback regex string for parsing entities.

Definition at line 21 of file EntityParser.php.


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