From a0052f0176bd079e6a94baec59fea2ec5a8d651e Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 1 Jan 2015 22:18:27 -0800 Subject: htmlpurifier update - compatibility issue with language library autoloader --- library/HTMLPurifier/LanguageFactory.php | 81 ++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'library/HTMLPurifier/LanguageFactory.php') diff --git a/library/HTMLPurifier/LanguageFactory.php b/library/HTMLPurifier/LanguageFactory.php index 134ef8c74..4e35272d8 100644 --- a/library/HTMLPurifier/LanguageFactory.php +++ b/library/HTMLPurifier/LanguageFactory.php @@ -11,50 +11,53 @@ class HTMLPurifier_LanguageFactory { /** - * Cache of language code information used to load HTMLPurifier_Language objects + * Cache of language code information used to load HTMLPurifier_Language objects. * Structure is: $factory->cache[$language_code][$key] = $value - * @value array map + * @type array */ public $cache; /** * Valid keys in the HTMLPurifier_Language object. Designates which * variables to slurp out of a message file. - * @value array list + * @type array */ public $keys = array('fallback', 'messages', 'errorNames'); /** - * Instance of HTMLPurifier_AttrDef_Lang to validate language codes - * @value object HTMLPurifier_AttrDef_Lang + * Instance to validate language codes. + * @type HTMLPurifier_AttrDef_Lang + * */ protected $validator; /** * Cached copy of dirname(__FILE__), directory of current file without - * trailing slash - * @value string filename + * trailing slash. + * @type string */ protected $dir; /** - * Keys whose contents are a hash map and can be merged - * @value array lookup + * Keys whose contents are a hash map and can be merged. + * @type array */ protected $mergeable_keys_map = array('messages' => true, 'errorNames' => true); /** - * Keys whose contents are a list and can be merged + * Keys whose contents are a list and can be merged. * @value array lookup */ protected $mergeable_keys_list = array(); /** * Retrieve sole instance of the factory. - * @param $prototype Optional prototype to overload sole instance with, + * @param HTMLPurifier_LanguageFactory $prototype Optional prototype to overload sole instance with, * or bool true to reset to default factory. + * @return HTMLPurifier_LanguageFactory */ - public static function instance($prototype = null) { + public static function instance($prototype = null) + { static $instance = null; if ($prototype !== null) { $instance = $prototype; @@ -69,28 +72,34 @@ class HTMLPurifier_LanguageFactory * Sets up the singleton, much like a constructor * @note Prevents people from getting this outside of the singleton */ - public function setup() { + public function setup() + { $this->validator = new HTMLPurifier_AttrDef_Lang(); $this->dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier'; } /** * Creates a language object, handles class fallbacks - * @param $config Instance of HTMLPurifier_Config - * @param $context Instance of HTMLPurifier_Context - * @param $code Code to override configuration with. Private parameter. + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @param bool|string $code Code to override configuration with. Private parameter. + * @return HTMLPurifier_Language */ - public function create($config, $context, $code = false) { - + public function create($config, $context, $code = false) + { // validate language code if ($code === false) { $code = $this->validator->validate( - $config->get('Core.Language'), $config, $context + $config->get('Core.Language'), + $config, + $context ); } else { $code = $this->validator->validate($code, $config, $context); } - if ($code === false) $code = 'en'; // malformed code becomes English + if ($code === false) { + $code = 'en'; // malformed code becomes English + } $pcode = str_replace('-', '_', $code); // make valid PHP classname static $depth = 0; // recursion protection @@ -114,32 +123,34 @@ class HTMLPurifier_LanguageFactory $depth--; } } - $lang->code = $code; - return $lang; - } /** * Returns the fallback language for language * @note Loads the original language into cache - * @param $code string language code + * @param string $code language code + * @return string|bool */ - public function getFallbackFor($code) { + public function getFallbackFor($code) + { $this->loadLanguage($code); return $this->cache[$code]['fallback']; } /** * Loads language into the cache, handles message file and fallbacks - * @param $code string language code + * @param string $code language code */ - public function loadLanguage($code) { + public function loadLanguage($code) + { static $languages_seen = array(); // recursion guard // abort if we've already loaded it - if (isset($this->cache[$code])) return; + if (isset($this->cache[$code])) { + return; + } // generate filename $filename = $this->dir . '/Language/messages/' . $code . '.php'; @@ -162,8 +173,11 @@ class HTMLPurifier_LanguageFactory // infinite recursion guard if (isset($languages_seen[$code])) { - trigger_error('Circular fallback reference in language ' . - $code, E_USER_ERROR); + trigger_error( + 'Circular fallback reference in language ' . + $code, + E_USER_ERROR + ); $fallback = 'en'; } $language_seen[$code] = true; @@ -173,26 +187,23 @@ class HTMLPurifier_LanguageFactory $fallback_cache = $this->cache[$fallback]; // merge fallback with current language - foreach ( $this->keys as $key ) { + foreach ($this->keys as $key) { if (isset($cache[$key]) && isset($fallback_cache[$key])) { if (isset($this->mergeable_keys_map[$key])) { $cache[$key] = $cache[$key] + $fallback_cache[$key]; } elseif (isset($this->mergeable_keys_list[$key])) { - $cache[$key] = array_merge( $fallback_cache[$key], $cache[$key] ); + $cache[$key] = array_merge($fallback_cache[$key], $cache[$key]); } } else { $cache[$key] = $fallback_cache[$key]; } } - } // save to cache for later retrieval $this->cache[$code] = $cache; - return; } - } // vim: et sw=4 sts=4 -- cgit v1.2.3