Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / CSS / URI.php
blobb310907cd51f60297b98df928a5878bd8ced7309
1 <?php
3 require_once 'HTMLPurifier/AttrDef/URI.php';
5 /**
6 * Validates a URI in CSS syntax, which uses url('http://example.com')
7 * @note While theoretically speaking a URI in a CSS document could
8 * be non-embedded, as of CSS2 there is no such usage so we're
9 * generalizing it. This may need to be changed in the future.
10 * @warning Since HTMLPurifier_AttrDef_CSS blindly uses semicolons as
11 * the separator, you cannot put a literal semicolon in
12 * in the URI. Try percent encoding it, in that case.
14 class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
17 function HTMLPurifier_AttrDef_CSS_URI() {
18 $this->HTMLPurifier_AttrDef_URI(true); // always embedded
21 function validate($uri_string, $config, &$context) {
22 // parse the URI out of the string and then pass it onto
23 // the parent object
25 $uri_string = $this->parseCDATA($uri_string);
26 if (strpos($uri_string, 'url(') !== 0) return false;
27 $uri_string = substr($uri_string, 4);
28 $new_length = strlen($uri_string) - 1;
29 if ($uri_string[$new_length] != ')') return false;
30 $uri = trim(substr($uri_string, 0, $new_length));
32 if (isset($uri[0]) && ($uri[0] == "'" || $uri[0] == '"')) {
33 $quote = $uri[0];
34 $new_length = strlen($uri) - 1;
35 if ($uri[$new_length] !== $quote) return false;
36 $uri = substr($uri, 1, $new_length - 1);
39 $keys = array( '(', ')', ',', ' ', '"', "'");
40 $values = array('\\(', '\\)', '\\,', '\\ ', '\\"', "\\'");
41 $uri = str_replace($values, $keys, $uri);
43 $result = parent::validate($uri, $config, $context);
45 if ($result === false) return false;
47 // escape necessary characters according to CSS spec
48 // except for the comma, none of these should appear in the
49 // URI at all
50 $result = str_replace($keys, $values, $result);
52 return "url($result)";