ILIAS  Release_4_1_x_branch Revision 61804
 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() {
32  }
33 
34  public function registerFilter($filter) {
35  $this->registeredFilters[$filter->name] = $filter;
36  }
37 
38  public function addFilter($filter, $config) {
39  $r = $filter->prepare($config);
40  if ($r === false) return; // null is ok, for backwards compat
41  if ($filter->post) {
42  $this->postFilters[$filter->name] = $filter;
43  } else {
44  $this->filters[$filter->name] = $filter;
45  }
46  }
47 
48  protected function doSetup($config) {
50  $this->setupFilters($config);
51  }
52 
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);
58  }
59  }
60  unset($this->registeredFilters);
61  }
62 
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;
71  }
72  if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI.DefaultScheme');
73  }
74 
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;
79  }
80  return true;
81  }
82 
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;
87  }
88  return true;
89  }
90 
91 }
92 
93 // vim: et sw=4 sts=4