ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
URIDefinition.php
Go to the documentation of this file.
1 <?php
2 
4 {
5 
6  public $type = 'URI';
7  protected $filters = array();
8  protected $postFilters = array();
9  protected $registeredFilters = array();
10 
14  public $base;
15 
19  public $host;
20 
25 
26  public function __construct() {
33  }
34 
35  public function registerFilter($filter) {
36  $this->registeredFilters[$filter->name] = $filter;
37  }
38 
39  public function addFilter($filter, $config) {
40  $r = $filter->prepare($config);
41  if ($r === false) return; // null is ok, for backwards compat
42  if ($filter->post) {
43  $this->postFilters[$filter->name] = $filter;
44  } else {
45  $this->filters[$filter->name] = $filter;
46  }
47  }
48 
49  protected function doSetup($config) {
50  $this->setupMemberVariables($config);
51  $this->setupFilters($config);
52  }
53 
54  protected function setupFilters($config) {
55  foreach ($this->registeredFilters as $name => $filter) {
56  if ($filter->always_load) {
57  $this->addFilter($filter, $config);
58  } else {
59  $conf = $config->get('URI.' . $name);
60  if ($conf !== false && $conf !== null) {
61  $this->addFilter($filter, $config);
62  }
63  }
64  }
65  unset($this->registeredFilters);
66  }
67 
68  protected function setupMemberVariables($config) {
69  $this->host = $config->get('URI.Host');
70  $base_uri = $config->get('URI.Base');
71  if (!is_null($base_uri)) {
72  $parser = new HTMLPurifier_URIParser();
73  $this->base = $parser->parse($base_uri);
74  $this->defaultScheme = $this->base->scheme;
75  if (is_null($this->host)) $this->host = $this->base->host;
76  }
77  if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI.DefaultScheme');
78  }
79 
80  public function getDefaultScheme($config, $context) {
81  return HTMLPurifier_URISchemeRegistry::instance()->getScheme($this->defaultScheme, $config, $context);
82  }
83 
84  public function filter(&$uri, $config, $context) {
85  foreach ($this->filters as $name => $f) {
86  $result = $f->filter($uri, $config, $context);
87  if (!$result) return false;
88  }
89  return true;
90  }
91 
92  public function postFilter(&$uri, $config, $context) {
93  foreach ($this->postFilters as $name => $f) {
94  $result = $f->filter($uri, $config, $context);
95  if (!$result) return false;
96  }
97  return true;
98  }
99 
100 }
101 
102 // vim: et sw=4 sts=4