ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
URI.php
Go to the documentation of this file.
1 <?php
2 
13 {
14 
15  public function __construct() {
16  parent::__construct(true); // always embedded
17  }
18 
19  public function validate($uri_string, $config, $context) {
20  // parse the URI out of the string and then pass it onto
21  // the parent object
22 
23  $uri_string = $this->parseCDATA($uri_string);
24  if (strpos($uri_string, 'url(') !== 0) return false;
25  $uri_string = substr($uri_string, 4);
26  $new_length = strlen($uri_string) - 1;
27  if ($uri_string[$new_length] != ')') return false;
28  $uri = trim(substr($uri_string, 0, $new_length));
29 
30  if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
31  $quote = $uri[0];
32  $new_length = strlen($uri) - 1;
33  if ($uri[$new_length] !== $quote) return false;
34  $uri = substr($uri, 1, $new_length - 1);
35  }
36 
37  $uri = $this->expandCSSEscape($uri);
38 
39  $result = parent::validate($uri, $config, $context);
40 
41  if ($result === false) return false;
42 
43  // extra sanity check; should have been done by URI
44  $result = str_replace(array('"', "\\", "\n", "\x0c", "\r"), "", $result);
45 
46  // suspicious characters are ()'; we're going to percent encode
47  // them for safety.
48  $result = str_replace(array('(', ')', "'"), array('%28', '%29', '%27'), $result);
49 
50  // there's an extra bug where ampersands lose their escaping on
51  // an innerHTML cycle, so a very unlucky query parameter could
52  // then change the meaning of the URL. Unfortunately, there's
53  // not much we can do about that...
54 
55  return "url(\"$result\")";
56 
57  }
58 
59 }
60 
61 // vim: et sw=4 sts=4