1 : <?php
2 :
3 : /**
4 : * Registry for retrieving specific URI scheme validator objects.
5 : */
6 : class HTMLPurifier_URISchemeRegistry
7 1 : {
8 :
9 : /**
10 : * Retrieve sole instance of the registry.
11 : * @param $prototype Optional prototype to overload sole instance with,
12 : * or bool true to reset to default registry.
13 : * @note Pass a registry object $prototype with a compatible interface and
14 : * the function will copy it and return it all further times.
15 : */
16 : public static function instance($prototype = null) {
17 2 : static $instance = null;
18 2 : if ($prototype !== null) {
19 0 : $instance = $prototype;
20 2 : } elseif ($instance === null || $prototype == true) {
21 1 : $instance = new HTMLPurifier_URISchemeRegistry();
22 1 : }
23 2 : return $instance;
24 : }
25 :
26 : /**
27 : * Cache of retrieved schemes.
28 : */
29 : protected $schemes = array();
30 :
31 : /**
32 : * Retrieves a scheme validator object
33 : * @param $scheme String scheme name like http or mailto
34 : * @param $config HTMLPurifier_Config object
35 : * @param $config HTMLPurifier_Context object
36 : */
37 : public function getScheme($scheme, $config, $context) {
38 2 : if (!$config) $config = HTMLPurifier_Config::createDefault();
39 2 : $null = null; // for the sake of passing by reference
40 :
41 : // important, otherwise attacker could include arbitrary file
42 2 : $allowed_schemes = $config->get('URI', 'AllowedSchemes');
43 2 : if (!$config->get('URI', 'OverrideAllowedSchemes') &&
44 : !isset($allowed_schemes[$scheme])
45 2 : ) {
46 : return $null;
47 : }
48 :
49 2 : if (isset($this->schemes[$scheme])) return $this->schemes[$scheme];
50 1 : if (!isset($allowed_schemes[$scheme])) return $null;
51 :
52 1 : $class = 'HTMLPurifier_URIScheme_' . $scheme;
53 1 : if (!class_exists($class)) return $null;
54 1 : $this->schemes[$scheme] = new $class();
55 1 : return $this->schemes[$scheme];
56 : }
57 :
58 : /**
59 : * Registers a custom scheme to the cache, bypassing reflection.
60 : * @param $scheme Scheme name
61 : * @param $scheme_obj HTMLPurifier_URIScheme object
62 : */
63 : public function register($scheme, $scheme_obj) {
64 0 : $this->schemes[$scheme] = $scheme_obj;
65 0 : }
66 :
67 : }
68 :
69 :
|