PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / Nofollow.php
blob1057ebee1b142f8bc5aadcc5e33d5dc81c0be6a5
1 <?php
3 // must be called POST validation
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
11 /**
12 * @type HTMLPurifier_URIParser
14 private $parser;
16 public function __construct()
18 $this->parser = new HTMLPurifier_URIParser();
21 /**
22 * @param array $attr
23 * @param HTMLPurifier_Config $config
24 * @param HTMLPurifier_Context $context
25 * @return array
27 public function transform($attr, $config, $context)
29 if (!isset($attr['href'])) {
30 return $attr;
33 // XXX Kind of inefficient
34 $url = $this->parser->parse($attr['href']);
35 $scheme = $url->getSchemeObj($config, $context);
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';
43 $attr['rel'] = implode(' ', $rels);
44 } else {
45 $attr['rel'] = 'nofollow';
48 return $attr;
52 // vim: et sw=4 sts=4