| 1: | <?php
|
| 2: |
|
| 3: |
|
| 4: |
|
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class HTMLPurifier_AttrTransform_Nofollow extends HTMLPurifier_AttrTransform
|
| 10: | {
|
| 11: | |
| 12: | |
| 13: |
|
| 14: | private $parser;
|
| 15: |
|
| 16: | public function __construct()
|
| 17: | {
|
| 18: | $this->parser = new HTMLPurifier_URIParser();
|
| 19: | }
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: |
|
| 27: | public function transform($attr, $config, $context)
|
| 28: | {
|
| 29: | if (!isset($attr['href'])) {
|
| 30: | return $attr;
|
| 31: | }
|
| 32: |
|
| 33: |
|
| 34: | $url = $this->parser->parse($attr['href']);
|
| 35: | $scheme = $url->getSchemeObj($config, $context);
|
| 36: |
|
| 37: | if ($scheme->browsable && !$url->isLocal($config, $context)) {
|
| 38: | if (isset($attr['rel'])) {
|
| 39: | $rels = explode(' ', $attr['rel']);
|
| 40: | if (!in_array('nofollow', $rels)) {
|
| 41: | $rels[] = 'nofollow';
|
| 42: | }
|
| 43: | $attr['rel'] = implode(' ', $rels);
|
| 44: | } else {
|
| 45: | $attr['rel'] = 'nofollow';
|
| 46: | }
|
| 47: | }
|
| 48: | return $attr;
|
| 49: | }
|
| 50: | }
|
| 51: |
|
| 52: |
|
| 53: | |