ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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
array$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
string Replacement string.

Definition at line 79 of file EntityParser.php.

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

80  {
81  // replaces all but big five
82  $entity = $matches[0];
83  $is_num = (@$matches[0][1] === '#');
84  if ($is_num) {
85  $is_hex = (@$entity[2] === 'x');
86  $code = $is_hex ? hexdec($matches[1]) : (int) $matches[2];
87  // abort for special characters
88  if (isset($this->_special_dec2str[$code])) {
89  return $entity;
90  }
91  return HTMLPurifier_Encoder::unichr($code);
92  } else {
93  if (isset($this->_special_ent2dec[$matches[3]])) {
94  return $entity;
95  }
96  if (!$this->_entity_lookup) {
97  $this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
98  }
99  if (isset($this->_entity_lookup->table[$matches[3]])) {
100  return $this->_entity_lookup->table[$matches[3]];
101  } else {
102  return $entity;
103  }
104  }
105  }
$code
Definition: example_050.php:99
static unichr($code)
Translates a Unicode codepoint into its corresponding UTF-8 character.
Definition: Encoder.php:309
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
array$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
string Replacement string.

Definition at line 135 of file EntityParser.php.

136  {
137  $entity = $matches[0];
138  $is_num = (@$matches[0][1] === '#');
139  if ($is_num) {
140  $is_hex = (@$entity[2] === 'x');
141  $int = $is_hex ? hexdec($matches[1]) : (int) $matches[2];
142  return isset($this->_special_dec2str[$int]) ?
143  $this->_special_dec2str[$int] :
144  $entity;
145  } else {
146  return isset($this->_special_ent2dec[$matches[3]]) ?
147  $this->_special_ent2dec[$matches[3]] :
148  $entity;
149  }
150  }

◆ 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
string$stringString to have non-special entities parsed.
Returns
string Parsed string.

Definition at line 60 of file EntityParser.php.

References array.

61  {
62  // it will try to detect missing semicolons, but don't rely on it
63  return preg_replace_callback(
64  $this->_substituteEntitiesRegex,
65  array($this, 'nonSpecialEntityCallback'),
66  $string
67  );
68  }
Create styles array
The data for the language used.

◆ 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
string$stringString to have non-special entities parsed.
Returns
string Parsed string.

Definition at line 116 of file EntityParser.php.

References array.

117  {
118  return preg_replace_callback(
119  $this->_substituteEntitiesRegex,
120  array($this, 'specialEntityCallback'),
121  $string
122  );
123  }
Create styles array
The data for the language used.

Field Documentation

◆ $_entity_lookup

HTMLPurifier_EntityParser::$_entity_lookup
protected

Reference to entity lookup table.

HTMLPurifier_EntityLookup

Definition at line 17 of file EntityParser.php.

◆ $_special_dec2str

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

Decimal to parsed string conversion table for special entities.

array

Definition at line 31 of file EntityParser.php.

◆ $_special_ent2dec

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

Stripped entity names to decimal conversion table for special entities.

array

Definition at line 44 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.

string

Definition at line 23 of file EntityParser.php.


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