~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/Strategy/ValidateAttributes.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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