mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 05:37:49 +02:00
PSR-2 reformatting PHPDoc corrections
With minor corrections. Signed-off-by: Marcus Bointon <marcus@synchromedia.co.uk> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
committed by
Edward Z. Yang
parent
19eee14899
commit
fac747bdbd
@@ -17,24 +17,27 @@ abstract class HTMLPurifier_Injector
|
||||
{
|
||||
|
||||
/**
|
||||
* Advisory name of injector, this is for friendly error messages
|
||||
* Advisory name of injector, this is for friendly error messages.
|
||||
* @type string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_HTMLDefinition
|
||||
* @type HTMLPurifier_HTMLDefinition
|
||||
*/
|
||||
protected $htmlDefinition;
|
||||
|
||||
/**
|
||||
* Reference to CurrentNesting variable in Context. This is an array
|
||||
* list of tokens that we are currently "inside"
|
||||
* @type array
|
||||
*/
|
||||
protected $currentNesting;
|
||||
|
||||
/**
|
||||
* Reference to InputTokens variable in Context. This is an array
|
||||
* list of the input tokens that are being processed.
|
||||
* @type array
|
||||
*/
|
||||
protected $inputTokens;
|
||||
|
||||
@@ -42,6 +45,7 @@ abstract class HTMLPurifier_Injector
|
||||
* Reference to InputIndex variable in Context. This is an integer
|
||||
* array index for $this->inputTokens that indicates what token
|
||||
* is currently being processed.
|
||||
* @type int
|
||||
*/
|
||||
protected $inputIndex;
|
||||
|
||||
@@ -49,11 +53,13 @@ abstract class HTMLPurifier_Injector
|
||||
* 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
|
||||
*/
|
||||
public $needed = array();
|
||||
|
||||
/**
|
||||
* Index of inputTokens to rewind to.
|
||||
* @type bool|int
|
||||
*/
|
||||
protected $rewind = false;
|
||||
|
||||
@@ -62,17 +68,21 @@ abstract class HTMLPurifier_Injector
|
||||
* 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.
|
||||
* @param bool|int $index
|
||||
* @warning HTML Purifier will prevent you from fast-forwarding with this
|
||||
* function.
|
||||
*/
|
||||
public function rewind($index) {
|
||||
public function rewind($index)
|
||||
{
|
||||
$this->rewind = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves rewind, and then unsets it.
|
||||
* @return bool|int
|
||||
*/
|
||||
public function getRewind() {
|
||||
public function getRewind()
|
||||
{
|
||||
$r = $this->rewind;
|
||||
$this->rewind = false;
|
||||
return $r;
|
||||
@@ -83,17 +93,20 @@ abstract class HTMLPurifier_Injector
|
||||
* 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()).
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @param $context Instance of HTMLPurifier_Context
|
||||
* @return Boolean false if success, string of missing needed element/attribute if failure
|
||||
* @param HTMLPurifier_Config $config
|
||||
* @param HTMLPurifier_Context $context
|
||||
* @return bool|string Boolean false if success, string of missing needed element/attribute if failure
|
||||
*/
|
||||
public function prepare($config, $context) {
|
||||
public function prepare($config, $context)
|
||||
{
|
||||
$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;
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
$this->currentNesting =& $context->get('CurrentNesting');
|
||||
$this->inputTokens =& $context->get('InputTokens');
|
||||
$this->inputIndex =& $context->get('InputIndex');
|
||||
@@ -104,18 +117,26 @@ abstract class HTMLPurifier_Injector
|
||||
* 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.
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @param $context Instance of HTMLPurifier_Context
|
||||
* @return Boolean false if success, string of missing needed element/attribute if failure
|
||||
* @param HTMLPurifier_Config $config
|
||||
* @return bool|string Boolean false if success, string of missing needed element/attribute if failure
|
||||
*/
|
||||
public function checkNeeded($config) {
|
||||
public function checkNeeded($config)
|
||||
{
|
||||
$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;
|
||||
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";
|
||||
if (!isset($def->info[$element]->attr[$name])) {
|
||||
return "$element.$name";
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -123,10 +144,11 @@ abstract class HTMLPurifier_Injector
|
||||
|
||||
/**
|
||||
* Tests if the context node allows a certain element
|
||||
* @param $name Name of element to test for
|
||||
* @return True if element is allowed, false if it is not
|
||||
* @param string $name Name of element to test for
|
||||
* @return bool True if element is allowed, false if it is not
|
||||
*/
|
||||
public function allowsElement($name) {
|
||||
public function allowsElement($name)
|
||||
{
|
||||
if (!empty($this->currentNesting)) {
|
||||
$parent_token = array_pop($this->currentNesting);
|
||||
$this->currentNesting[] = $parent_token;
|
||||
@@ -141,7 +163,9 @@ abstract class HTMLPurifier_Injector
|
||||
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;
|
||||
if (isset($def->excludes[$name])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -151,13 +175,21 @@ abstract class HTMLPurifier_Injector
|
||||
* you reach the end of the input tokens.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
* @param int $i Current integer index variable for inputTokens
|
||||
* @param HTMLPurifier_Token $current Current token variable.
|
||||
* Do NOT use $token, as that variable is also a reference
|
||||
* @return bool
|
||||
*/
|
||||
protected function forward(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex + 1;
|
||||
else $i++;
|
||||
if (!isset($this->inputTokens[$i])) return false;
|
||||
protected function forward(&$i, &$current)
|
||||
{
|
||||
if ($i === null) {
|
||||
$i = $this->inputIndex + 1;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
if (!isset($this->inputTokens[$i])) {
|
||||
return false;
|
||||
}
|
||||
$current = $this->inputTokens[$i];
|
||||
return true;
|
||||
}
|
||||
@@ -166,14 +198,27 @@ abstract class HTMLPurifier_Injector
|
||||
* 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.
|
||||
* @param int $i Current integer index variable for inputTokens
|
||||
* @param HTMLPurifier_Token $current Current token variable.
|
||||
* Do NOT use $token, as that variable is also a reference
|
||||
* @param int $nesting
|
||||
* @return bool
|
||||
*/
|
||||
protected function forwardUntilEndToken(&$i, &$current, &$nesting) {
|
||||
protected function forwardUntilEndToken(&$i, &$current, &$nesting)
|
||||
{
|
||||
$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;
|
||||
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;
|
||||
@@ -184,13 +229,21 @@ abstract class HTMLPurifier_Injector
|
||||
* you reach the beginning of input tokens.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
* @param int $i Current integer index variable for inputTokens
|
||||
* @param HTMLPurifier_Token $current Current token variable.
|
||||
* Do NOT use $token, as that variable is also a reference
|
||||
* @return bool
|
||||
*/
|
||||
protected function backward(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex - 1;
|
||||
else $i--;
|
||||
if ($i < 0) return false;
|
||||
protected function backward(&$i, &$current)
|
||||
{
|
||||
if ($i === null) {
|
||||
$i = $this->inputIndex - 1;
|
||||
} else {
|
||||
$i--;
|
||||
}
|
||||
if ($i < 0) {
|
||||
return false;
|
||||
}
|
||||
$current = $this->inputTokens[$i];
|
||||
return true;
|
||||
}
|
||||
@@ -201,39 +254,49 @@ abstract class HTMLPurifier_Injector
|
||||
* current location.
|
||||
* @warning Please prevent previous references from interfering with this
|
||||
* functions by setting $i = null beforehand!
|
||||
* @param &$i Current integer index variable for inputTokens
|
||||
* @param &$current Current token variable. Do NOT use $token, as that variable is also a reference
|
||||
* @param int $i Current integer index variable for inputTokens
|
||||
* @param HTMLPurifier_Token $current Current token variable.
|
||||
* Do NOT use $token, as that variable is also a reference
|
||||
*/
|
||||
protected function current(&$i, &$current) {
|
||||
if ($i === null) $i = $this->inputIndex;
|
||||
protected function current(&$i, &$current)
|
||||
{
|
||||
if ($i === null) {
|
||||
$i = $this->inputIndex;
|
||||
}
|
||||
$current = $this->inputTokens[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that is called when a text token is processed
|
||||
*/
|
||||
public function handleText(&$token) {}
|
||||
public function handleText(&$token)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that is called when a start or empty token is processed
|
||||
*/
|
||||
public function handleElement(&$token) {}
|
||||
public function handleElement(&$token)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler that is called when an end token is processed
|
||||
*/
|
||||
public function handleEnd(&$token) {
|
||||
public function handleEnd(&$token)
|
||||
{
|
||||
$this->notifyEnd($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifier that is called when an end token is processed
|
||||
* @param HTMLPurifier_Token $token Current token variable.
|
||||
* @note This differs from handlers in that the token is read-only
|
||||
* @deprecated
|
||||
*/
|
||||
public function notifyEnd($token) {}
|
||||
|
||||
|
||||
public function notifyEnd($token)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
Reference in New Issue
Block a user