~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/URIFilter/DisableExternal.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require_once 'HTMLPurifier/URIFilter.php';
 
4
 
 
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.'
 
13
);
 
14
 
 
15
class HTMLPurifier_URIFilter_DisableExternal extends HTMLPurifier_URIFilter
 
16
{
 
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));
 
22
    }
 
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;
 
30
        }
 
31
        return true;
 
32
    }
 
33
}
 
34