root/afridex/plugins/Flutter/purifier_lib/HTMLPurifier/URIDefinition.php @ 22

Revision 21, 2.4 kB (checked in by admin, 18 years ago)
Line 
1<?php
2
3class HTMLPurifier_URIDefinition extends HTMLPurifier_Definition
4{
5   
6    public $type = 'URI';
7    protected $filters = array();
8    protected $registeredFilters = array();
9   
10    /**
11     * HTMLPurifier_URI object of the base specified at %URI.Base
12     */
13    public $base;
14   
15    /**
16     * String host to consider "home" base, derived off of $base
17     */
18    public $host;
19   
20    /**
21     * Name of default scheme based on %URI.DefaultScheme and %URI.Base
22     */
23    public $defaultScheme;
24   
25    public function __construct() {
26        $this->registerFilter(new HTMLPurifier_URIFilter_DisableExternal());
27        $this->registerFilter(new HTMLPurifier_URIFilter_DisableExternalResources());
28        $this->registerFilter(new HTMLPurifier_URIFilter_HostBlacklist());
29        $this->registerFilter(new HTMLPurifier_URIFilter_MakeAbsolute());
30    }
31   
32    public function registerFilter($filter) {
33        $this->registeredFilters[$filter->name] = $filter;
34    }
35   
36    public function addFilter($filter, $config) {
37        $filter->prepare($config);
38        $this->filters[$filter->name] = $filter;
39    }
40   
41    protected function doSetup($config) {
42        $this->setupMemberVariables($config);
43        $this->setupFilters($config);
44    }
45   
46    protected function setupFilters($config) {
47        foreach ($this->registeredFilters as $name => $filter) {
48            $conf = $config->get('URI', $name);
49            if ($conf !== false && $conf !== null) {
50                $this->addFilter($filter, $config);
51            }
52        }
53        unset($this->registeredFilters);
54    }
55   
56    protected function setupMemberVariables($config) {
57        $this->host = $config->get('URI', 'Host');
58        $base_uri = $config->get('URI', 'Base');
59        if (!is_null($base_uri)) {
60            $parser = new HTMLPurifier_URIParser();
61            $this->base = $parser->parse($base_uri);
62            $this->defaultScheme = $this->base->scheme;
63            if (is_null($this->host)) $this->host = $this->base->host;
64        }
65        if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI', 'DefaultScheme');
66    }
67   
68    public function filter(&$uri, $config, $context) {
69        foreach ($this->filters as $name => $x) {
70            $result = $this->filters[$name]->filter($uri, $config, $context);
71            if (!$result) return false;
72        }
73        return true;
74    }
75   
76}
Note: See TracBrowser for help on using the browser.