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