ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
Nofollow.php
Go to the documentation of this file.
1 <?php
2 
3 // must be called POST validation
4 
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 
27  if ($scheme->browsable && !$url->isLocal($config, $context)) {
28  if (isset($attr['rel'])) {
29  $rels = explode(' ', $attr['rel']);
30  if (!in_array('nofollow', $rels)) {
31  $rels[] = 'nofollow';
32  }
33  $attr['rel'] = implode(' ', $rels);
34  } else {
35  $attr['rel'] = 'nofollow';
36  }
37  }
38 
39  return $attr;
40 
41  }
42 
43 }
44 
45 // vim: et sw=4 sts=4
Processes an entire attribute array for corrections needing multiple values.
Adds rel="nofollow" to all outbound links.
Definition: Nofollow.php:9
Parses a URI into the components and fragment identifier as specified by RFC 3986.
Definition: URIParser.php:7
transform($attr, $config, $context)
Definition: Nofollow.php:17