]>
Commit | Line | Data |
---|---|---|
1 | <?php\r | |
2 | \r | |
3 | /**\r | |
4 | * Validate all attributes in the tokens.\r | |
5 | */\r | |
6 | \r | |
7 | class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy\r | |
8 | {\r | |
9 | \r | |
10 | /**\r | |
11 | * @param HTMLPurifier_Token[] $tokens\r | |
12 | * @param HTMLPurifier_Config $config\r | |
13 | * @param HTMLPurifier_Context $context\r | |
14 | * @return HTMLPurifier_Token[]\r | |
15 | */\r | |
16 | public function execute($tokens, $config, $context)\r | |
17 | {\r | |
18 | // setup validator\r | |
19 | $validator = new HTMLPurifier_AttrValidator();\r | |
20 | \r | |
21 | $token = false;\r | |
22 | $context->register('CurrentToken', $token);\r | |
23 | \r | |
24 | foreach ($tokens as $key => $token) {\r | |
25 | \r | |
26 | // only process tokens that have attributes,\r | |
27 | // namely start and empty tags\r | |
28 | if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {\r | |
29 | continue;\r | |
30 | }\r | |
31 | \r | |
32 | // skip tokens that are armored\r | |
33 | if (!empty($token->armor['ValidateAttributes'])) {\r | |
34 | continue;\r | |
35 | }\r | |
36 | \r | |
37 | // note that we have no facilities here for removing tokens\r | |
38 | $validator->validateToken($token, $config, $context);\r | |
39 | }\r | |
40 | $context->destroy('CurrentToken');\r | |
41 | return $tokens;\r | |
42 | }\r | |
43 | }\r | |
44 | \r | |
45 | // vim: et sw=4 sts=4\r |