Abstract Class HTMLPurifier_Injector

InheritanceHTMLPurifier_Injector
SubclassesHTMLPurifier_Injector_AutoParagraph, HTMLPurifier_Injector_DisplayLinkURI, HTMLPurifier_Injector_Linkify, HTMLPurifier_Injector_PurifierLinkify, HTMLPurifier_Injector_RemoveEmpty, HTMLPurifier_Injector_RemoveSpansWithoutAttributes, HTMLPurifier_Injector_SafeObject

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.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$name Advisory name of injector, this is for friendly error messages. HTMLPurifier_Injector
$needed 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') HTMLPurifier_Injector

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$currentNesting Reference to CurrentNesting variable in Context. This is an array list of tokens that we are currently "inside" HTMLPurifier_Injector
$currentToken Reference to current token. HTMLPurifier_Injector
$htmlDefinition HTMLPurifier_Injector
$inputZipper Reference to InputZipper variable in Context. HTMLPurifier_Injector
$rewindOffset Number of elements to rewind backwards (relative). HTMLPurifier_Injector

Public Methods

Hide inherited methods

MethodDescriptionDefined By
allowsElement() Tests if the context node allows a certain element HTMLPurifier_Injector
checkNeeded() 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. HTMLPurifier_Injector
getRewindOffset() Retrieves rewind offset, and then unsets it. HTMLPurifier_Injector
handleElement() Handler that is called when a start or empty token is processed HTMLPurifier_Injector
handleEnd() Handler that is called when an end token is processed HTMLPurifier_Injector
handleText() Handler that is called when a text token is processed HTMLPurifier_Injector
notifyEnd() Notifier that is called when an end token is processed HTMLPurifier_Injector
prepare() 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()). HTMLPurifier_Injector
rewindOffset() 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. HTMLPurifier_Injector

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
backward() Iterator function, starts with the previous token and continues until you reach the beginning of input tokens. HTMLPurifier_Injector
forward() Iterator function, which starts with the next token and continues until you reach the end of the input tokens. HTMLPurifier_Injector
forwardUntilEndToken() 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. HTMLPurifier_Injector

Property Details

$currentNesting protected property
protected $currentNesting null
$currentToken protected property
protected $currentToken null
$htmlDefinition protected property
protected $htmlDefinition null
$inputZipper protected property
protected $inputZipper null
$name public property
public $name null
$needed public property
public $needed = []
$rewindOffset protected property
protected $rewindOffset false

Method Details

allowsElement() public method

Tests if the context node allows a certain element

public bool allowsElement ( $name )
$name string

Name of element to test for

return bool

True if element is allowed, false if it is not

backward() protected method

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

protected bool backward ( <b>&</b>$i, <b>&</b>$current )
$i int

Current integer index variable for inputTokens

$current HTMLPurifier_Token

Current token variable.

     Do NOT use $token, as that variable is also a reference
checkNeeded() public method

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.

public bool|string checkNeeded ( $config )
$config HTMLPurifier_Config
return bool|string

Boolean false if success, string of missing needed element/attribute if failure

forward() protected method

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

protected bool forward ( <b>&</b>$i, <b>&</b>$current )
$i int

Current integer index variable for inputTokens

$current HTMLPurifier_Token

Current token variable.

     Do NOT use $token, as that variable is also a reference
forwardUntilEndToken() protected method

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.

protected bool forwardUntilEndToken ( <b>&</b>$i, <b>&</b>$current, <b>&</b>$nesting )
$i int

Current integer index variable for inputTokens

$current HTMLPurifier_Token

Current token variable.

     Do NOT use $token, as that variable is also a reference
$nesting int
getRewindOffset() public method

Retrieves rewind offset, and then unsets it.

public bool|int getRewindOffset ( )
handleElement() public method

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

public void handleElement ( <b>&</b>$token )
$token
handleEnd() public method

Handler that is called when an end token is processed

public void handleEnd ( <b>&</b>$token )
$token
handleText() public method

Handler that is called when a text token is processed

public void handleText ( <b>&</b>$token )
$token
notifyEnd() public method

Notifier that is called when an end token is processed

public void notifyEnd ( $token )
$token HTMLPurifier_Token

Current token variable.

prepare() public method

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()).

public bool|string prepare ( $config, $context )
$config HTMLPurifier_Config
$context HTMLPurifier_Context
return bool|string

Boolean false if success, string of missing needed element/attribute if failure

rewindOffset() public method

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.

public void rewindOffset ( $offset )
$offset bool|int