1: <?php
2:
3: 4: 5:
6: class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector
7: {
8: public $name = 'RemoveSpansWithoutAttributes';
9: public $needed = array('span');
10:
11: private $attrValidator;
12:
13: 14: 15:
16: private $config;
17: private $context;
18:
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);
24: }
25:
26: public function handleElement(&$token) {
27: if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {
28: return;
29: }
30:
31:
32:
33:
34: $this->attrValidator->validateToken($token, $this->config, $this->context);
35: $token->armor['ValidateAttributes'] = true;
36:
37: if (!empty($token->attr)) {
38: return;
39: }
40:
41: $nesting = 0;
42: $spanContentTokens = array();
43: while ($this->forwardUntilEndToken($i, $current, $nesting)) {}
44:
45: if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
46:
47: $current->markForDeletion = true;
48:
49: $token = false;
50: }
51: }
52:
53: public function handleEnd(&$token) {
54: if ($token->markForDeletion) {
55: $token = false;
56: }
57: }
58: }
59:
60:
61: