1: <?php
2:
3:
4:
5: 6: 7: 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:
24: $url = $this->parser->parse($attr['href']);
25: $scheme = $url->getSchemeObj($config, $context);
26:
27: if (!is_null($url->host) && $scheme !== false && $scheme->browsable) {
28: if (isset($attr['rel'])) {
29: $attr['rel'] .= ' nofollow';
30: } else {
31: $attr['rel'] = 'nofollow';
32: }
33: }
34:
35: return $attr;
36:
37: }
38:
39: }
40:
41:
42: