ILIAS  Release_4_4_x_branch Revision 61816
 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() {
34  }
35 
36  public function registerFilter($filter) {
37  $this->registeredFilters[$filter->name] = $filter;
38  }
39 
40  public function addFilter($filter, $config) {
41  $r = $filter->prepare($config);
42  if ($r === false) return; // null is ok, for backwards compat
43  if ($filter->post) {
44  $this->postFilters[$filter->name] = $filter;
45  } else {
46  $this->filters[$filter->name] = $filter;
47  }
48  }
49 
50  protected function doSetup($config) {
51  $this->setupMemberVariables($config);
52  $this->setupFilters($config);
53  }
54 
55  protected function setupFilters($config) {
56  foreach ($this->registeredFilters as $name => $filter) {
57  if ($filter->always_load) {
58  $this->addFilter($filter, $config);
59  } else {
60  $conf = $config->get('URI.' . $name);
61  if ($conf !== false && $conf !== null) {
62  $this->addFilter($filter, $config);
63  }
64  }
65  }
66  unset($this->registeredFilters);
67  }
68 
69  protected function setupMemberVariables($config) {
70  $this->host = $config->get('URI.Host');
71  $base_uri = $config->get('URI.Base');
72  if (!is_null($base_uri)) {
73  $parser = new HTMLPurifier_URIParser();
74  $this->base = $parser->parse($base_uri);
75  $this->defaultScheme = $this->base->scheme;
76  if (is_null($this->host)) $this->host = $this->base->host;
77  }
78  if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI.DefaultScheme');
79  }
80 
81  public function getDefaultScheme($config, $context) {
82  return HTMLPurifier_URISchemeRegistry::instance()->getScheme($this->defaultScheme, $config, $context);
83  }
84 
85  public function filter(&$uri, $config, $context) {
86  foreach ($this->filters as $name => $f) {
87  $result = $f->filter($uri, $config, $context);
88  if (!$result) return false;
89  }
90  return true;
91  }
92 
93  public function postFilter(&$uri, $config, $context) {
94  foreach ($this->postFilters as $name => $f) {
95  $result = $f->filter($uri, $config, $context);
96  if (!$result) return false;
97  }
98  return true;
99  }
100 
101 }
102 
103 // vim: et sw=4 sts=4