summaryrefslogtreecommitdiff
path: root/lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2009-06-22 13:56:49 +0400
committerAndrew Dolgov <[email protected]>2009-06-22 13:56:49 +0400
commitf45a286b8d62f710b519a98c7d4b75a0c34d5d10 (patch)
tree0c310b7b9d44e12fac1cd11e1563c4cef9b5eab2 /lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php
parent5c4461432c290ad4863fd7dc4107121db59b298c (diff)
strip_tags_long: use htmlpurifier to properly reformat html content
Diffstat (limited to 'lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php')
-rwxr-xr-xlib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php b/lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php
new file mode 100755
index 000000000..d24732c18
--- /dev/null
+++ b/lib/htmlpurifier/library/HTMLPurifier/URISchemeRegistry.php
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * Registry for retrieving specific URI scheme validator objects.
+ */
+class HTMLPurifier_URISchemeRegistry
+{
+
+ /**
+ * 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.
+ */
+ public static function instance($prototype = null) {
+ static $instance = null;
+ if ($prototype !== null) {
+ $instance = $prototype;
+ } elseif ($instance === null || $prototype == true) {
+ $instance = new HTMLPurifier_URISchemeRegistry();
+ }
+ return $instance;
+ }
+
+ /**
+ * Cache of retrieved schemes.
+ */
+ protected $schemes = array();
+
+ /**
+ * Retrieves a scheme validator object
+ * @param $scheme String scheme name like http or mailto
+ * @param $config HTMLPurifier_Config object
+ * @param $config HTMLPurifier_Context object
+ */
+ public function getScheme($scheme, $config, $context) {
+ if (!$config) $config = HTMLPurifier_Config::createDefault();
+ $null = null; // for the sake of passing by reference
+
+ // important, otherwise attacker could include arbitrary file
+ $allowed_schemes = $config->get('URI', 'AllowedSchemes');
+ if (!$config->get('URI', 'OverrideAllowedSchemes') &&
+ !isset($allowed_schemes[$scheme])
+ ) {
+ return $null;
+ }
+
+ if (isset($this->schemes[$scheme])) return $this->schemes[$scheme];
+ if (!isset($allowed_schemes[$scheme])) return $null;
+
+ $class = 'HTMLPurifier_URIScheme_' . $scheme;
+ if (!class_exists($class)) return $null;
+ $this->schemes[$scheme] = new $class();
+ return $this->schemes[$scheme];
+ }
+
+ /**
+ * Registers a custom scheme to the cache, bypassing reflection.
+ * @param $scheme Scheme name
+ * @param $scheme_obj HTMLPurifier_URIScheme object
+ */
+ public function register($scheme, $scheme_obj) {
+ $this->schemes[$scheme] = $scheme_obj;
+ }
+
+}
+
+// vim: et sw=4 sts=4