2006-08-12 01:12:35 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Registry for retrieving specific URI scheme validator objects.
|
|
|
|
*/
|
2006-08-12 01:12:35 +00:00
|
|
|
class HTMLPurifier_URISchemeRegistry
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Retrieve sole instance of the registry.
|
|
|
|
* @param $prototype Optional prototype to overload sole instance with,
|
|
|
|
* or bool true to reset to default registry.
|
|
|
|
* @note Pass a registry object $prototype with a compatible interface and
|
|
|
|
* the function will copy it and return it all further times.
|
|
|
|
*/
|
2008-01-05 00:10:43 +00:00
|
|
|
public static function instance($prototype = null) {
|
2006-08-12 01:12:35 +00:00
|
|
|
static $instance = null;
|
|
|
|
if ($prototype !== null) {
|
|
|
|
$instance = $prototype;
|
|
|
|
} elseif ($instance === null || $prototype == true) {
|
|
|
|
$instance = new HTMLPurifier_URISchemeRegistry();
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Cache of retrieved schemes.
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $schemes = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a scheme validator object
|
|
|
|
* @param $scheme String scheme name like http or mailto
|
|
|
|
* @param $config HTMLPurifier_Config object
|
2006-10-27 01:20:10 +00:00
|
|
|
* @param $config HTMLPurifier_Context object
|
2006-08-20 20:59:13 +00:00
|
|
|
*/
|
2008-01-05 00:10:43 +00:00
|
|
|
public function getScheme($scheme, $config, $context) {
|
2006-08-12 03:56:27 +00:00
|
|
|
if (!$config) $config = HTMLPurifier_Config::createDefault();
|
|
|
|
$null = null; // for the sake of passing by reference
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 03:56:27 +00:00
|
|
|
// important, otherwise attacker could include arbitrary file
|
|
|
|
$allowed_schemes = $config->get('URI', 'AllowedSchemes');
|
2006-08-12 17:12:27 +00:00
|
|
|
if (!$config->get('URI', 'OverrideAllowedSchemes') &&
|
|
|
|
!isset($allowed_schemes[$scheme])
|
|
|
|
) {
|
|
|
|
return $null;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 17:12:27 +00:00
|
|
|
if (isset($this->schemes[$scheme])) return $this->schemes[$scheme];
|
2006-08-12 03:56:27 +00:00
|
|
|
if (!isset($allowed_schemes[$scheme])) return $null;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 03:56:27 +00:00
|
|
|
$class = 'HTMLPurifier_URIScheme_' . $scheme;
|
|
|
|
if (!class_exists($class)) return $null;
|
|
|
|
$this->schemes[$scheme] = new $class();
|
|
|
|
return $this->schemes[$scheme];
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
2007-08-26 15:43:17 +00:00
|
|
|
* Registers a custom scheme to the cache, bypassing reflection.
|
2006-08-20 20:59:13 +00:00
|
|
|
* @param $scheme Scheme name
|
|
|
|
* @param $scheme_obj HTMLPurifier_URIScheme object
|
|
|
|
*/
|
2008-01-05 00:10:43 +00:00
|
|
|
public function register($scheme, $scheme_obj) {
|
|
|
|
$this->schemes[$scheme] = $scheme_obj;
|
2006-08-12 17:06:14 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 01:12:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-27 13:58:32 +00:00
|
|
|
|