Do not duplicate nofollow attribute in transform.
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / Nofollow.php
blob8143409a0c1624048fbe7b04da388f50aeb55cff
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 private $parser;
13 public function __construct() {
14 $this->parser = new HTMLPurifier_URIParser();
17 public function transform($attr, $config, $context) {
19 if (!isset($attr['href'])) {
20 return $attr;
23 // XXX Kind of inefficient
24 $url = $this->parser->parse($attr['href']);
25 $scheme = $url->getSchemeObj($config, $context);
27 if (!is_null($url->host) && $scheme !== false && $scheme->browsable) {
28 if (isset($attr['rel'])) {
29 $rels = explode(' ', $attr);
30 if (!in_array('nofollow', $rels)) {
31 $rels[] = 'nofollow';
33 $attr['rel'] = implode(' ', $rels);
34 } else {
35 $attr['rel'] = 'nofollow';
39 return $attr;
45 // vim: et sw=4 sts=4