Update PHPT instructions.
[htmlpurifier.git] / library / HTMLPurifier / Injector / RemoveSpansWithoutAttributes.php
blobb21313470e4e5d93ab3b7ac3f9e366b3da41571f
1 <?php
3 /**
4 * Injector that removes spans with no attributes
5 */
6 class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector
8 public $name = 'RemoveSpansWithoutAttributes';
9 public $needed = array('span');
11 private $attrValidator;
13 /**
14 * Used by AttrValidator
16 private $config;
17 private $context;
19 public function prepare($config, $context) {
20 $this->attrValidator = new HTMLPurifier_AttrValidator();
21 $this->config = $config;
22 $this->context = $context;
23 return parent::prepare($config, $context);
26 public function handleElement(&$token) {
27 if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {
28 return;
31 // We need to validate the attributes now since this doesn't normally
32 // happen until after MakeWellFormed. If all the attributes are removed
33 // the span needs to be removed too.
34 $this->attrValidator->validateToken($token, $this->config, $this->context);
35 $token->armor['ValidateAttributes'] = true;
37 if (!empty($token->attr)) {
38 return;
41 $nesting = 0;
42 $spanContentTokens = array();
43 while ($this->forwardUntilEndToken($i, $current, $nesting)) {}
45 if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
46 // Mark closing span tag for deletion
47 $current->markForDeletion = true;
48 // Delete open span tag
49 $token = false;
53 public function handleEnd(&$token) {
54 if ($token->markForDeletion) {
55 $token = false;
60 // vim: et sw=4 sts=4