ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
HTMLPurifier_Injector_RemoveEmpty Class Reference
+ Inheritance diagram for HTMLPurifier_Injector_RemoveEmpty:
+ Collaboration diagram for HTMLPurifier_Injector_RemoveEmpty:

Public Member Functions

 prepare ($config, $context)
 
 handleElement (&$token)
 
- Public Member Functions inherited from HTMLPurifier_Injector
 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...
 

Private Attributes

 $context
 HTMLPurifier_Context More...
 
 $config
 HTMLPurifier_Config More...
 
 $attrValidator
 HTMLPurifier_AttrValidator More...
 
 $removeNbsp
 bool More...
 
 $removeNbspExceptions
 bool More...
 
 $exclude
 Cached contents of AutoFormat.RemoveEmpty.Predicate array. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_Injector
 $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 inherited from HTMLPurifier_Injector
 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 inherited from HTMLPurifier_Injector
 $htmlDefinition
 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

Definition at line 3 of file RemoveEmpty.php.

Member Function Documentation

◆ handleElement()

HTMLPurifier_Injector_RemoveEmpty::handleElement ( $token)
Parameters
HTMLPurifier_Token$token

Definition at line 61 of file RemoveEmpty.php.

References $r, and HTMLPurifier_Injector\rewindOffset().

62  {
63  if (!$token instanceof HTMLPurifier_Token_Start) {
64  return;
65  }
66  $next = false;
67  $deleted = 1; // the current tag
68  for ($i = count($this->inputZipper->back) - 1; $i >= 0; $i--, $deleted++) {
69  $next = $this->inputZipper->back[$i];
70  if ($next instanceof HTMLPurifier_Token_Text) {
71  if ($next->is_whitespace) {
72  continue;
73  }
74  if ($this->removeNbsp && !isset($this->removeNbspExceptions[$token->name])) {
75  $plain = str_replace("\xC2\xA0", "", $next->data);
76  $isWsOrNbsp = $plain === '' || ctype_space($plain);
77  if ($isWsOrNbsp) {
78  continue;
79  }
80  }
81  }
82  break;
83  }
84  if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) {
85  $this->attrValidator->validateToken($token, $this->config, $this->context);
86  $token->armor['ValidateAttributes'] = true;
87  if (isset($this->exclude[$token->name])) {
88  $r = true;
89  foreach ($this->exclude[$token->name] as $elem) {
90  if (!isset($token->attr[$elem])) $r = false;
91  }
92  if ($r) return;
93  }
94  if (isset($token->attr['id']) || isset($token->attr['name'])) {
95  return;
96  }
97  $token = $deleted + 1;
98  for ($b = 0, $c = count($this->inputZipper->front); $b < $c; $b++) {
99  $prev = $this->inputZipper->front[$b];
100  if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) {
101  continue;
102  }
103  break;
104  }
105  // This is safe because we removed the token that triggered this.
106  $this->rewindOffset($b+$deleted);
107  return;
108  }
109  }
Concrete end token class.
Definition: End.php:10
Concrete start token class.
Definition: Start.php:6
$r
Definition: example_031.php:79
rewindOffset($offset)
Rewind to a spot to re-perform processing.
Definition: Injector.php:72
Concrete text token class.
Definition: Text.php:12
+ Here is the call graph for this function:

◆ prepare()

HTMLPurifier_Injector_RemoveEmpty::prepare (   $config,
  $context 
)
Parameters
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
void

Definition at line 41 of file RemoveEmpty.php.

References $config, and $context.

42  {
43  parent::prepare($config, $context);
44  $this->config = $config;
45  $this->context = $context;
46  $this->removeNbsp = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp');
47  $this->removeNbspExceptions = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions');
48  $this->exclude = $config->get('AutoFormat.RemoveEmpty.Predicate');
49  foreach ($this->exclude as $key => $attrs) {
50  if (!is_array($attrs)) {
51  // HACK, see HTMLPurifier/Printer/ConfigForm.php
52  $this->exclude[$key] = explode(';', $attrs);
53  }
54  }
55  $this->attrValidator = new HTMLPurifier_AttrValidator();
56  }
$context
HTMLPurifier_Context
Definition: RemoveEmpty.php:8
Validates the attributes of a token.

Field Documentation

◆ $attrValidator

HTMLPurifier_Injector_RemoveEmpty::$attrValidator
private

HTMLPurifier_AttrValidator

Definition at line 18 of file RemoveEmpty.php.

◆ $config

HTMLPurifier_Injector_RemoveEmpty::$config
private

HTMLPurifier_Config

Definition at line 13 of file RemoveEmpty.php.

Referenced by prepare().

◆ $context

HTMLPurifier_Injector_RemoveEmpty::$context
private

HTMLPurifier_Context

Definition at line 8 of file RemoveEmpty.php.

Referenced by prepare().

◆ $exclude

HTMLPurifier_Injector_RemoveEmpty::$exclude
private

Cached contents of AutoFormat.RemoveEmpty.Predicate array.

Definition at line 34 of file RemoveEmpty.php.

◆ $removeNbsp

HTMLPurifier_Injector_RemoveEmpty::$removeNbsp
private

bool

Definition at line 23 of file RemoveEmpty.php.

◆ $removeNbspExceptions

HTMLPurifier_Injector_RemoveEmpty::$removeNbspExceptions
private

bool

Definition at line 28 of file RemoveEmpty.php.


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