From 82dd468002d5d21a5c8c391d6fce543b3df43de1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 3 Sep 2009 11:25:02 -0700 Subject: Refactor interaction with the purifier module so that the API is cleaner and we don't need to know about the module innards. Move the config file over there too. --- modules/gallery/config/purifier.php | 27 --------------------------- modules/gallery/libraries/SafeString.php | 28 ++++++++-------------------- 2 files changed, 8 insertions(+), 47 deletions(-) delete mode 100644 modules/gallery/config/purifier.php (limited to 'modules') diff --git a/modules/gallery/config/purifier.php b/modules/gallery/config/purifier.php deleted file mode 100644 index 30de9dc5..00000000 --- a/modules/gallery/config/purifier.php +++ /dev/null @@ -1,27 +0,0 @@ - TMPPATH -); - -$config["Attr"] = array( - "EnableID" => true -); diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php index 93905572..3328fed5 100644 --- a/modules/gallery/libraries/SafeString.php +++ b/modules/gallery/libraries/SafeString.php @@ -26,8 +26,6 @@ class SafeString_Core { protected $_is_safe_html = false; protected $_is_purified_html = false; - private static $_purifier = null; - /** Constructor */ function __construct($string) { if ($string instanceof SafeString) { @@ -151,29 +149,19 @@ class SafeString_Core { return $this->_raw_string; } - // Escapes special HTML chars ("<", ">", "&", etc.) to HTML entities. + /** + * Escape special HTML chars ("<", ">", "&", etc.) to HTML entities. + */ private static function _escape_for_html($dirty_html) { return html::specialchars($dirty_html); } - // Purifies the string, removing any potentially malicious or unsafe HTML / JavaScript. + /** + * Purify the string, removing any potentially malicious or unsafe HTML / JavaScript. + */ private static function _purify_for_html($dirty_html) { - if (null === self::$_purifier) { - if (module::is_active("htmlpurifier")) { - require_once(MODPATH . "htmlpurifier/lib/HTMLPurifier/HTMLPurifier.auto.php"); - $config = HTMLPurifier_Config::createDefault(); - foreach (Kohana::config('purifier') as $category => $key_value) { - foreach ($key_value as $key => $value) { - $config->set("$category.$key", $value); - } - } - self::$_purifier = new HTMLPurifier($config); - } else { - self::$_purifier = false; - } - } - if (self::$_purifier) { - return self::$_purifier->purify($dirty_html); + if (method_exists("purifier", "purify")) { + return purifier::purify($dirty_html); } else { return self::_escape_for_html($dirty_html); } -- cgit v1.2.3