ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 getRewindOffset ()
 Retrieves rewind offset, and then unsets it.
 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.
 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.
 allowsElement ($name)
 Tests if the context node allows a certain element.
 handleText (&$token)
 Handler that is called when a text token is processed.
 handleElement (&$token)
 Handler that is called when a start or empty token is processed.
 handleEnd (&$token)
 Handler that is called when an end token is processed.
 notifyEnd ($token)
 Notifier that is called when an end token is processed.

Data Fields

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

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.
 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.
 backward (&$i, &$current)
 Iterator function, starts with the previous token and continues until you reach the beginning of input tokens.

Protected Attributes

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

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

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.

References $name.

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

{
if (!empty($this->currentNesting)) {
$parent_token = array_pop($this->currentNesting);
$this->currentNesting[] = $parent_token;
$parent = $this->htmlDefinition->info[$parent_token->name];
} else {
$parent = $this->htmlDefinition->info_parent_def;
}
if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) {
return false;
}
// check for exclusion
for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) {
$node = $this->currentNesting[$i];
$def = $this->htmlDefinition->info[$node->name];
if (isset($def->excludes[$name])) {
return false;
}
}
return true;
}

+ Here is the caller graph for this function:

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.

Referenced by HTMLPurifier_Injector_AutoParagraph\handleElement().

{
if ($i === null) {
$i = count($this->inputZipper->front) - 1;
} else {
$i--;
}
if ($i < 0) {
return false;
}
$current = $this->inputZipper->front[$i];
return true;
}

+ Here is the caller graph for this function:

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.

References $name.

Referenced by prepare().

{
$def = $config->getHTMLDefinition();
foreach ($this->needed as $element => $attributes) {
if (is_int($element)) {
$element = $attributes;
}
if (!isset($def->info[$element])) {
return $element;
}
if (!is_array($attributes)) {
continue;
}
foreach ($attributes as $name) {
if (!isset($def->info[$element]->attr[$name])) {
return "$element.$name";
}
}
}
return false;
}

+ Here is the caller graph for this function:

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.

Referenced by forwardUntilEndToken().

{
if ($i === null) {
$i = count($this->inputZipper->back) - 1;
} else {
$i--;
}
if ($i < 0) {
return false;
}
$current = $this->inputZipper->back[$i];
return true;
}

+ Here is the caller graph for this function:

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.

References $result, and forward().

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

{
$result = $this->forward($i, $current);
if (!$result) {
return false;
}
if ($nesting === null) {
$nesting = 0;
}
if ($current instanceof HTMLPurifier_Token_Start) {
$nesting++;
} elseif ($current instanceof HTMLPurifier_Token_End) {
if ($nesting <= 0) {
return false;
}
$nesting--;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_Injector::getRewindOffset ( )

Retrieves rewind offset, and then unsets it.

Returns
bool|int

Definition at line 81 of file Injector.php.

References $rewindOffset, and rewindOffset().

{
$this->rewindOffset = false;
return $r;
}

+ Here is the call graph for this function:

HTMLPurifier_Injector::handleElement ( $token)
HTMLPurifier_Injector::handleEnd ( $token)

Handler that is called when an end token is processed.

Reimplemented in HTMLPurifier_Injector_SafeObject, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, and HTMLPurifier_Injector_DisplayLinkURI.

Definition at line 265 of file Injector.php.

References notifyEnd().

{
$this->notifyEnd($token);
}

+ Here is the call graph for this function:

HTMLPurifier_Injector::handleText ( $token)

Handler that is called when a text token is processed.

Reimplemented in HTMLPurifier_Injector_PurifierLinkify, HTMLPurifier_Injector_AutoParagraph, and HTMLPurifier_Injector_Linkify.

Definition at line 251 of file Injector.php.

{
}
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.

Referenced by handleEnd().

{
}

+ Here is the caller graph for this function:

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_SafeObject, HTMLPurifier_Injector_RemoveEmpty, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, and HTMLPurifier_Injector_PurifierLinkify.

Definition at line 97 of file Injector.php.

References $result, and checkNeeded().

{
$this->htmlDefinition = $config->getHTMLDefinition();
// Even though this might fail, some unit tests ignore this and
// still test checkNeeded, so be careful. Maybe get rid of that
// dependency.
$result = $this->checkNeeded($config);
if ($result !== false) {
return $result;
}
$this->currentNesting =& $context->get('CurrentNesting');
$this->currentToken =& $context->get('CurrentToken');
$this->inputZipper =& $context->get('InputZipper');
return false;
}

+ Here is the call graph for this function:

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.

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

{
$this->rewindOffset = $offset;
}

+ Here is the caller graph for this function:

Field Documentation

HTMLPurifier_Injector::$currentNesting
protected

Reference to CurrentNesting variable in Context.

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

Definition at line 35 of file Injector.php.

HTMLPurifier_Injector::$currentToken
protected

Reference to current token.

HTMLPurifier_Token

Definition at line 41 of file Injector.php.

HTMLPurifier_Injector::$htmlDefinition
protected

HTMLPurifier_HTMLDefinition

Definition at line 28 of file Injector.php.

HTMLPurifier_Injector::$inputZipper
protected

Reference to InputZipper variable in Context.

HTMLPurifier_Zipper

Definition at line 47 of file Injector.php.

HTMLPurifier_Injector::$name

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

string

Definition at line 23 of file Injector.php.

Referenced by allowsElement(), and checkNeeded().

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') array

Definition at line 55 of file Injector.php.

HTMLPurifier_Injector::$rewindOffset = false
protected

Number of elements to rewind backwards (relative).

bool|int

Definition at line 61 of file Injector.php.

Referenced by getRewindOffset().


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