]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Injector that removes spans with no attributes\r | |
5 | */\r | |
6 | class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector\r | |
7 | {\r | |
8 | /**\r | |
9 | * @type string\r | |
10 | */\r | |
11 | public $name = 'RemoveSpansWithoutAttributes';\r | |
12 | \r | |
13 | /**\r | |
14 | * @type array\r | |
15 | */\r | |
16 | public $needed = array('span');\r | |
17 | \r | |
18 | /**\r | |
19 | * @type HTMLPurifier_AttrValidator\r | |
20 | */\r | |
21 | private $attrValidator;\r | |
22 | \r | |
23 | /**\r | |
24 | * Used by AttrValidator.\r | |
25 | * @type HTMLPurifier_Config\r | |
26 | */\r | |
27 | private $config;\r | |
28 | \r | |
29 | /**\r | |
30 | * @type HTMLPurifier_Context\r | |
31 | */\r | |
32 | private $context;\r | |
33 | \r | |
34 | public function prepare($config, $context)\r | |
35 | {\r | |
36 | $this->attrValidator = new HTMLPurifier_AttrValidator();\r | |
37 | $this->config = $config;\r | |
38 | $this->context = $context;\r | |
39 | return parent::prepare($config, $context);\r | |
40 | }\r | |
41 | \r | |
42 | /**\r | |
43 | * @param HTMLPurifier_Token $token\r | |
44 | */\r | |
45 | public function handleElement(&$token)\r | |
46 | {\r | |
47 | if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {\r | |
48 | return;\r | |
49 | }\r | |
50 | \r | |
51 | // We need to validate the attributes now since this doesn't normally\r | |
52 | // happen until after MakeWellFormed. If all the attributes are removed\r | |
53 | // the span needs to be removed too.\r | |
54 | $this->attrValidator->validateToken($token, $this->config, $this->context);\r | |
55 | $token->armor['ValidateAttributes'] = true;\r | |
56 | \r | |
57 | if (!empty($token->attr)) {\r | |
58 | return;\r | |
59 | }\r | |
60 | \r | |
61 | $nesting = 0;\r | |
62 | while ($this->forwardUntilEndToken($i, $current, $nesting)) {\r | |
63 | }\r | |
64 | \r | |
65 | if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {\r | |
66 | // Mark closing span tag for deletion\r | |
67 | $current->markForDeletion = true;\r | |
68 | // Delete open span tag\r | |
69 | $token = false;\r | |
70 | }\r | |
71 | }\r | |
72 | \r | |
73 | /**\r | |
74 | * @param HTMLPurifier_Token $token\r | |
75 | */\r | |
76 | public function handleEnd(&$token)\r | |
77 | {\r | |
78 | if ($token->markForDeletion) {\r | |
79 | $token = false;\r | |
80 | }\r | |
81 | }\r | |
82 | }\r | |
83 | \r | |
84 | // vim: et sw=4 sts=4\r |