]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | // must be called POST validation\r | |
4 | \r | |
5 | /**\r | |
6 | * Adds rel="nofollow" to all outbound links. This transform is\r | |
7 | * only attached if Attr.Nofollow is TRUE.\r | |
8 | */\r | |
9 | class HTMLPurifier_AttrTransform_Nofollow extends HTMLPurifier_AttrTransform\r | |
10 | {\r | |
11 | /**\r | |
12 | * @type HTMLPurifier_URIParser\r | |
13 | */\r | |
14 | private $parser;\r | |
15 | \r | |
16 | public function __construct()\r | |
17 | {\r | |
18 | $this->parser = new HTMLPurifier_URIParser();\r | |
19 | }\r | |
20 | \r | |
21 | /**\r | |
22 | * @param array $attr\r | |
23 | * @param HTMLPurifier_Config $config\r | |
24 | * @param HTMLPurifier_Context $context\r | |
25 | * @return array\r | |
26 | */\r | |
27 | public function transform($attr, $config, $context)\r | |
28 | {\r | |
29 | if (!isset($attr['href'])) {\r | |
30 | return $attr;\r | |
31 | }\r | |
32 | \r | |
33 | // XXX Kind of inefficient\r | |
34 | $url = $this->parser->parse($attr['href']);\r | |
35 | $scheme = $url->getSchemeObj($config, $context);\r | |
36 | \r | |
37 | if ($scheme->browsable && !$url->isLocal($config, $context)) {\r | |
38 | if (isset($attr['rel'])) {\r | |
39 | $rels = explode(' ', $attr['rel']);\r | |
40 | if (!in_array('nofollow', $rels)) {\r | |
41 | $rels[] = 'nofollow';\r | |
42 | }\r | |
43 | $attr['rel'] = implode(' ', $rels);\r | |
44 | } else {\r | |
45 | $attr['rel'] = 'nofollow';\r | |
46 | }\r | |
47 | }\r | |
48 | return $attr;\r | |
49 | }\r | |
50 | }\r | |
51 | \r | |
52 | // vim: et sw=4 sts=4\r |