ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTMLPurifier_Injector Class Reference

Injects tokens into the document while parsing for well-formedness. More...

+ Inheritance diagram for HTMLPurifier_Injector:
+ Collaboration diagram for HTMLPurifier_Injector:

Public Member Functions

 rewindOffset ($offset)
 Rewind to a spot to re-perform processing. More...
 
 getRewindOffset ()
 Retrieves rewind offset, and then unsets it. More...
 
 prepare ($config, $context)
 Prepares the injector by giving it the config and context objects: this allows references to important variables to be made within the injector. More...
 
 checkNeeded ($config)
 This function checks if the HTML environment will work with the Injector: if p tags are not allowed, the Auto-Paragraphing injector should not be enabled. More...
 
 allowsElement ($name)
 Tests if the context node allows a certain element. More...
 
 handleText (&$token)
 Handler that is called when a text token is processed. More...
 
 handleElement (&$token)
 Handler that is called when a start or empty token is processed. More...
 
 handleEnd (&$token)
 Handler that is called when an end token is processed. More...
 
 notifyEnd ($token)
 Notifier that is called when an end token is processed. More...
 

Data Fields

 $name
 Advisory name of injector, this is for friendly error messages. More...
 
 $needed = array()
 Array of elements and attributes this injector creates and therefore need to be allowed by the definition. More...
 

Protected Member Functions

 forward (&$i, &$current)
 Iterator function, which starts with the next token and continues until you reach the end of the input tokens. More...
 
 forwardUntilEndToken (&$i, &$current, &$nesting)
 Similar to _forward, but accepts a third parameter $nesting (which should be initialized at 0) and stops when we hit the end tag for the node $this->inputIndex starts in. More...
 
 backward (&$i, &$current)
 Iterator function, starts with the previous token and continues until you reach the beginning of input tokens. More...
 

Protected Attributes

 $htmlDefinition
 @type HTMLPurifier_HTMLDefinition More...
 
 $currentNesting
 Reference to CurrentNesting variable in Context. More...
 
 $currentToken
 Reference to current token. More...
 
 $inputZipper
 Reference to InputZipper variable in Context. More...
 
 $rewindOffset = false
 Number of elements to rewind backwards (relative). More...
 

Detailed Description

Injects tokens into the document while parsing for well-formedness.

This enables "formatter-like" functionality such as auto-paragraphing, smiley-ification and linkification to take place.

A note on how handlers create changes; this is done by assigning a new value to the $token reference. These values can take a variety of forms and are best described HTMLPurifier_Strategy_MakeWellFormed->processToken() documentation.

Todo:
Allow injectors to request a re-run on their output. This would help if an operation is recursive.

Definition at line 16 of file Injector.php.

Member Function Documentation

◆ allowsElement()

HTMLPurifier_Injector::allowsElement (   $name)

Tests if the context node allows a certain element.

Parameters
string$nameName of element to test for
Returns
bool True if element is allowed, false if it is not

Definition at line 147 of file Injector.php.

148 {
149 if (!empty($this->currentNesting)) {
150 $parent_token = array_pop($this->currentNesting);
151 $this->currentNesting[] = $parent_token;
152 $parent = $this->htmlDefinition->info[$parent_token->name];
153 } else {
154 $parent = $this->htmlDefinition->info_parent_def;
155 }
156 if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) {
157 return false;
158 }
159 // check for exclusion
160 for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) {
161 $node = $this->currentNesting[$i];
162 $def = $this->htmlDefinition->info[$node->name];
163 if (isset($def->excludes[$name])) {
164 return false;
165 }
166 }
167 return true;
168 }
$name
Advisory name of injector, this is for friendly error messages.
Definition: Injector.php:23

References $name.

Referenced by HTMLPurifier_Injector_AutoParagraph\handleElement(), HTMLPurifier_Injector_AutoParagraph\handleText(), HTMLPurifier_Injector_Linkify\handleText(), and HTMLPurifier_Injector_PurifierLinkify\handleText().

+ Here is the caller graph for this function:

◆ backward()

HTMLPurifier_Injector::backward ( $i,
$current 
)
protected

Iterator function, starts with the previous token and continues until you reach the beginning of input tokens.

Warning
Please prevent previous references from interfering with this functions by setting $i = null beforehand!
Parameters
int$iCurrent integer index variable for inputTokens
HTMLPurifier_Token$currentCurrent token variable. Do NOT use $token, as that variable is also a reference
Returns
bool

Definition at line 234 of file Injector.php.

235 {
236 if ($i === null) {
237 $i = count($this->inputZipper->front) - 1;
238 } else {
239 $i--;
240 }
241 if ($i < 0) {
242 return false;
243 }
244 $current = $this->inputZipper->front[$i];
245 return true;
246 }

Referenced by HTMLPurifier_Injector_AutoParagraph\handleElement().

+ Here is the caller graph for this function:

◆ checkNeeded()

HTMLPurifier_Injector::checkNeeded (   $config)

This function checks if the HTML environment will work with the Injector: if p tags are not allowed, the Auto-Paragraphing injector should not be enabled.

Parameters
HTMLPurifier_Config$config
Returns
bool|string Boolean false if success, string of missing needed element/attribute if failure

Definition at line 120 of file Injector.php.

121 {
122 $def = $config->getHTMLDefinition();
123 foreach ($this->needed as $element => $attributes) {
124 if (is_int($element)) {
125 $element = $attributes;
126 }
127 if (!isset($def->info[$element])) {
128 return $element;
129 }
130 if (!is_array($attributes)) {
131 continue;
132 }
133 foreach ($attributes as $name) {
134 if (!isset($def->info[$element]->attr[$name])) {
135 return "$element.$name";
136 }
137 }
138 }
139 return false;
140 }

References $name.

Referenced by prepare().

+ Here is the caller graph for this function:

◆ forward()

HTMLPurifier_Injector::forward ( $i,
$current 
)
protected

Iterator function, which starts with the next token and continues until you reach the end of the input tokens.

Warning
Please prevent previous references from interfering with this functions by setting $i = null beforehand!
Parameters
int$iCurrent integer index variable for inputTokens
HTMLPurifier_Token$currentCurrent token variable. Do NOT use $token, as that variable is also a reference
Returns
bool

Definition at line 180 of file Injector.php.

181 {
182 if ($i === null) {
183 $i = count($this->inputZipper->back) - 1;
184 } else {
185 $i--;
186 }
187 if ($i < 0) {
188 return false;
189 }
190 $current = $this->inputZipper->back[$i];
191 return true;
192 }

Referenced by forwardUntilEndToken().

+ Here is the caller graph for this function:

◆ forwardUntilEndToken()

HTMLPurifier_Injector::forwardUntilEndToken ( $i,
$current,
$nesting 
)
protected

Similar to _forward, but accepts a third parameter $nesting (which should be initialized at 0) and stops when we hit the end tag for the node $this->inputIndex starts in.

Parameters
int$iCurrent integer index variable for inputTokens
HTMLPurifier_Token$currentCurrent token variable. Do NOT use $token, as that variable is also a reference
int$nesting
Returns
bool

Definition at line 204 of file Injector.php.

205 {
206 $result = $this->forward($i, $current);
207 if (!$result) {
208 return false;
209 }
210 if ($nesting === null) {
211 $nesting = 0;
212 }
213 if ($current instanceof HTMLPurifier_Token_Start) {
214 $nesting++;
215 } elseif ($current instanceof HTMLPurifier_Token_End) {
216 if ($nesting <= 0) {
217 return false;
218 }
219 $nesting--;
220 }
221 return true;
222 }
$result
forward(&$i, &$current)
Iterator function, which starts with the next token and continues until you reach the end of the inpu...
Definition: Injector.php:180
Concrete end token class.
Definition: End.php:11
Concrete start token class.
Definition: Start.php:7

References $result, and forward().

Referenced by HTMLPurifier_Injector_AutoParagraph\_pLookAhead(), HTMLPurifier_Injector_RemoveSpansWithoutAttributes\handleElement(), and HTMLPurifier_Injector_AutoParagraph\handleText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRewindOffset()

HTMLPurifier_Injector::getRewindOffset ( )

Retrieves rewind offset, and then unsets it.

Returns
bool|int

Definition at line 81 of file Injector.php.

82 {
84 $this->rewindOffset = false;
85 return $r;
86 }
$rewindOffset
Number of elements to rewind backwards (relative).
Definition: Injector.php:61
rewindOffset($offset)
Rewind to a spot to re-perform processing.
Definition: Injector.php:72
$r
Definition: example_031.php:79

References $r, $rewindOffset, and rewindOffset().

+ Here is the call graph for this function:

◆ handleElement()

HTMLPurifier_Injector::handleElement ( $token)

Handler that is called when a start or empty token is processed.

Reimplemented in HTMLPurifier_Injector_AutoParagraph, HTMLPurifier_Injector_DisplayLinkURI, HTMLPurifier_Injector_RemoveEmpty, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, and HTMLPurifier_Injector_SafeObject.

Definition at line 258 of file Injector.php.

259 {
260 }

◆ handleEnd()

HTMLPurifier_Injector::handleEnd ( $token)

Handler that is called when an end token is processed.

Reimplemented in HTMLPurifier_Injector_DisplayLinkURI, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, and HTMLPurifier_Injector_SafeObject.

Definition at line 265 of file Injector.php.

266 {
267 $this->notifyEnd($token);
268 }
notifyEnd($token)
Notifier that is called when an end token is processed.
Definition: Injector.php:276

References notifyEnd().

+ Here is the call graph for this function:

◆ handleText()

HTMLPurifier_Injector::handleText ( $token)

Handler that is called when a text token is processed.

Reimplemented in HTMLPurifier_Injector_AutoParagraph, HTMLPurifier_Injector_Linkify, and HTMLPurifier_Injector_PurifierLinkify.

Definition at line 251 of file Injector.php.

252 {
253 }

◆ notifyEnd()

HTMLPurifier_Injector::notifyEnd (   $token)

Notifier that is called when an end token is processed.

Parameters
HTMLPurifier_Token$tokenCurrent token variable.
Note
This differs from handlers in that the token is read-only
Deprecated:

Definition at line 276 of file Injector.php.

277 {
278 }

Referenced by handleEnd().

+ Here is the caller graph for this function:

◆ prepare()

HTMLPurifier_Injector::prepare (   $config,
  $context 
)

Prepares the injector by giving it the config and context objects: this allows references to important variables to be made within the injector.

This function also checks if the HTML environment will work with the Injector (see checkNeeded()).

Parameters
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string Boolean false if success, string of missing needed element/attribute if failure

Reimplemented in HTMLPurifier_Injector_PurifierLinkify, HTMLPurifier_Injector_RemoveEmpty, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, and HTMLPurifier_Injector_SafeObject.

Definition at line 97 of file Injector.php.

98 {
99 $this->htmlDefinition = $config->getHTMLDefinition();
100 // Even though this might fail, some unit tests ignore this and
101 // still test checkNeeded, so be careful. Maybe get rid of that
102 // dependency.
103 $result = $this->checkNeeded($config);
104 if ($result !== false) {
105 return $result;
106 }
107 $this->currentNesting =& $context->get('CurrentNesting');
108 $this->currentToken =& $context->get('CurrentToken');
109 $this->inputZipper =& $context->get('InputZipper');
110 return false;
111 }
checkNeeded($config)
This function checks if the HTML environment will work with the Injector: if p tags are not allowed,...
Definition: Injector.php:120

References $result, and checkNeeded().

+ Here is the call graph for this function:

◆ rewindOffset()

HTMLPurifier_Injector::rewindOffset (   $offset)

Rewind to a spot to re-perform processing.

This is useful if you deleted a node, and now need to see if this change affected any earlier nodes. Rewinding does not affect other injectors, and can result in infinite loops if not used carefully.

Parameters
bool | int$offset
Warning
HTML Purifier will prevent you from fast-forwarding with this function.

Definition at line 72 of file Injector.php.

73 {
74 $this->rewindOffset = $offset;
75 }

References rewindOffset().

Referenced by getRewindOffset(), HTMLPurifier_Injector_RemoveEmpty\handleElement(), and rewindOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $currentNesting

HTMLPurifier_Injector::$currentNesting
protected

Reference to CurrentNesting variable in Context.

This is an array list of tokens that we are currently "inside" @type array

Definition at line 35 of file Injector.php.

◆ $currentToken

HTMLPurifier_Injector::$currentToken
protected

Reference to current token.

@type HTMLPurifier_Token

Definition at line 41 of file Injector.php.

◆ $htmlDefinition

HTMLPurifier_Injector::$htmlDefinition
protected

@type HTMLPurifier_HTMLDefinition

Definition at line 28 of file Injector.php.

◆ $inputZipper

HTMLPurifier_Injector::$inputZipper
protected

Reference to InputZipper variable in Context.

@type HTMLPurifier_Zipper

Definition at line 47 of file Injector.php.

◆ $name

HTMLPurifier_Injector::$name

Advisory name of injector, this is for friendly error messages.

@type string

Definition at line 23 of file Injector.php.

Referenced by allowsElement(), and checkNeeded().

◆ $needed

HTMLPurifier_Injector::$needed = array()

Array of elements and attributes this injector creates and therefore need to be allowed by the definition.

Takes form of array('element' => array('attr', 'attr2'), 'element2') @type array

Definition at line 55 of file Injector.php.

◆ $rewindOffset

HTMLPurifier_Injector::$rewindOffset = false
protected

Number of elements to rewind backwards (relative).

@type bool|int

Definition at line 61 of file Injector.php.

Referenced by getRewindOffset().


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