3 class HTMLPurifier_URIDefinition
extends HTMLPurifier_Definition
7 protected $filters = array();
8 protected $postFilters = array();
9 protected $registeredFilters = array();
12 * HTMLPurifier_URI object of the base specified at %URI.Base
17 * String host to consider "home" base, derived off of $base
22 * Name of default scheme based on %URI.DefaultScheme and %URI.Base
24 public $defaultScheme;
26 public function __construct() {
27 $this->registerFilter(new HTMLPurifier_URIFilter_DisableExternal());
28 $this->registerFilter(new HTMLPurifier_URIFilter_DisableExternalResources());
29 $this->registerFilter(new HTMLPurifier_URIFilter_HostBlacklist());
30 $this->registerFilter(new HTMLPurifier_URIFilter_MakeAbsolute());
31 $this->registerFilter(new HTMLPurifier_URIFilter_Munge());
34 public function registerFilter($filter) {
35 $this->registeredFilters
[$filter->name
] = $filter;
38 public function addFilter($filter, $config) {
39 $r = $filter->prepare($config);
40 if ($r === false) return; // null is ok, for backwards compat
42 $this->postFilters
[$filter->name
] = $filter;
44 $this->filters
[$filter->name
] = $filter;
48 protected function doSetup($config) {
49 $this->setupMemberVariables($config);
50 $this->setupFilters($config);
53 protected function setupFilters($config) {
54 foreach ($this->registeredFilters
as $name => $filter) {
55 $conf = $config->get('URI.' . $name);
56 if ($conf !== false && $conf !== null) {
57 $this->addFilter($filter, $config);
60 unset($this->registeredFilters
);
63 protected function setupMemberVariables($config) {
64 $this->host
= $config->get('URI.Host');
65 $base_uri = $config->get('URI.Base');
66 if (!is_null($base_uri)) {
67 $parser = new HTMLPurifier_URIParser();
68 $this->base
= $parser->parse($base_uri);
69 $this->defaultScheme
= $this->base
->scheme
;
70 if (is_null($this->host
)) $this->host
= $this->base
->host
;
72 if (is_null($this->defaultScheme
)) $this->defaultScheme
= $config->get('URI.DefaultScheme');
75 public function filter(&$uri, $config, $context) {
76 foreach ($this->filters
as $name => $f) {
77 $result = $f->filter($uri, $config, $context);
78 if (!$result) return false;
83 public function postFilter(&$uri, $config, $context) {
84 foreach ($this->postFilters
as $name => $f) {
85 $result = $f->filter($uri, $config, $context);
86 if (!$result) return false;