ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
RemoveSpansWithoutAttributes.php
Go to the documentation of this file.
1<?php
2
7{
11 public $name = 'RemoveSpansWithoutAttributes';
12
16 public $needed = array('span');
17
22
27 private $config;
28
32 private $context;
33
34 public function prepare($config, $context)
35 {
36 $this->attrValidator = new HTMLPurifier_AttrValidator();
37 $this->config = $config;
38 $this->context = $context;
39 return parent::prepare($config, $context);
40 }
41
45 public function handleElement(&$token)
46 {
47 if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {
48 return;
49 }
50
51 // We need to validate the attributes now since this doesn't normally
52 // happen until after MakeWellFormed. If all the attributes are removed
53 // the span needs to be removed too.
54 $this->attrValidator->validateToken($token, $this->config, $this->context);
55 $token->armor['ValidateAttributes'] = true;
56
57 if (!empty($token->attr)) {
58 return;
59 }
60
61 $nesting = 0;
62 while ($this->forwardUntilEndToken($i, $current, $nesting)) {
63 }
64
65 if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
66 // Mark closing span tag for deletion
67 $current->markForDeletion = true;
68 // Delete open span tag
69 $token = false;
70 }
71 }
72
76 public function handleEnd(&$token)
77 {
78 if ($token->markForDeletion) {
79 $token = false;
80 }
81 }
82}
83
84// vim: et sw=4 sts=4
Validates the attributes of a token.
Injector that removes spans with no attributes.
prepare($config, $context)
Prepares the injector by giving it the config and context objects: this allows references to importan...
Injects tokens into the document while parsing for well-formedness.
Definition: Injector.php:17
forwardUntilEndToken(&$i, &$current, &$nesting)
Similar to _forward, but accepts a third parameter $nesting (which should be initialized at 0) and st...
Definition: Injector.php:204
Concrete end token class.
Definition: End.php:11
Concrete start token class.
Definition: Start.php:7