3
require_once 'HTMLPurifier/URIFilter.php';
5
HTMLPurifier_ConfigSchema::define(
6
'URI', 'DisableExternal', false, 'bool',
7
'Disables links to external websites. This is a highly effective '.
8
'anti-spam and anti-pagerank-leech measure, but comes at a hefty price: no'.
9
'links or images outside of your domain will be allowed. Non-linkified '.
10
'URIs will still be preserved. If you want to be able to link to '.
11
'subdomains or use absolute URIs, specify %URI.Host for your website. '.
12
'This directive has been available since 1.2.0.'
15
class HTMLPurifier_URIFilter_DisableExternal extends HTMLPurifier_URIFilter
17
var $name = 'DisableExternal';
18
var $ourHostParts = false;
19
function prepare($config) {
20
$our_host = $config->get('URI', 'Host');
21
if ($our_host !== null) $this->ourHostParts = array_reverse(explode('.', $our_host));
23
function filter(&$uri, $config, &$context) {
24
if (is_null($uri->host)) return true;
25
if ($this->ourHostParts === false) return false;
26
$host_parts = array_reverse(explode('.', $uri->host));
27
foreach ($this->ourHostParts as $i => $x) {
28
if (!isset($host_parts[$i])) return false;
29
if ($host_parts[$i] != $this->ourHostParts[$i]) return false;