ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
RemoveSpansWithoutAttributes.php
Go to the documentation of this file.
1 <?php
2 
7 {
11  public $name = 'RemoveSpansWithoutAttributes';
12 
16  public $needed = array('span');
17 
21  private $attrValidator;
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;
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