diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2014-02-21 15:43:14 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2014-02-21 15:43:14 +0100 |
commit | d4949327efa15b492cab1bef3fe074290a328a17 (patch) | |
tree | e89e0322bb1f1b06d663fd10fdded21bac867e5d /inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php | |
parent | c9bd17a1007bb78e5de0775efca01df0fb515031 (diff) | |
download | wallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.gz wallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.zst wallabag-d4949327efa15b492cab1bef3fe074290a328a17.zip |
[add] HTML Purifier added to clean code
Diffstat (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php')
-rw-r--r-- | inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php new file mode 100644 index 00000000..270b7f82 --- /dev/null +++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php | |||
@@ -0,0 +1,84 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Injector that removes spans with no attributes | ||
5 | */ | ||
6 | class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector | ||
7 | { | ||
8 | /** | ||
9 | * @type string | ||
10 | */ | ||
11 | public $name = 'RemoveSpansWithoutAttributes'; | ||
12 | |||
13 | /** | ||
14 | * @type array | ||
15 | */ | ||
16 | public $needed = array('span'); | ||
17 | |||
18 | /** | ||
19 | * @type HTMLPurifier_AttrValidator | ||
20 | */ | ||
21 | private $attrValidator; | ||
22 | |||
23 | /** | ||
24 | * Used by AttrValidator. | ||
25 | * @type HTMLPurifier_Config | ||
26 | */ | ||
27 | private $config; | ||
28 | |||
29 | /** | ||
30 | * @type HTMLPurifier_Context | ||
31 | */ | ||
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 | |||
42 | /** | ||
43 | * @param HTMLPurifier_Token $token | ||
44 | */ | ||
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 | |||
73 | /** | ||
74 | * @param HTMLPurifier_Token $token | ||
75 | */ | ||
76 | public function handleEnd(&$token) | ||
77 | { | ||
78 | if ($token->markForDeletion) { | ||
79 | $token = false; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | // vim: et sw=4 sts=4 | ||