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