From f98f14670c3641395681cf1b419cc4391b1a887c Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Tue, 21 Aug 2018 20:11:31 +0200 Subject: [PATCH] Rename special chars to unicode chars, remove special chars in username --- bl-kernel/functions.php | 2 +- bl-kernel/helpers/text.class.php | 15 ++++++++++----- bl-kernel/language.class.php | 17 ++++++++--------- bl-kernel/pages.class.php | 4 ++-- bl-languages/de_CH.json | 2 +- bl-languages/de_DE.json | 2 +- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index a0837dfb..a207be22 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -517,7 +517,7 @@ function createUser($args) { // Filter form fields $tmp = array(); - $tmp['username'] = $args['new_username']; + $tmp['username'] = Text::removeSpecialCharacters($args['new_username']); $tmp['password'] = $args['new_password']; $tmp['role'] = $args['role']; $tmp['email'] = $args['email']; diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php index 6259bf21..fd15d378 100644 --- a/bl-kernel/helpers/text.class.php +++ b/bl-kernel/helpers/text.class.php @@ -2,7 +2,7 @@ class Text { - private static $specialChars = array( + private static $unicodeChars = array( // Latin 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'AE', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', @@ -121,6 +121,11 @@ class Text { return str_replace(array_keys($replace), array_values($replace), $text); } + public static function removeSpecialCharacters($string, $replace='') + { + return preg_replace("/[\/_|+:!@#$%^&*()'\"<>\\\`}{;=,?\[\]~. -]+/", $replace, $string); + } + // Convert unicode characters to utf-8 characters // Characters that cannot be converted will be removed from the string // This function can return an empty string @@ -131,15 +136,15 @@ class Text { if (EXTREME_FRIENDLY_URL) { $string = self::lowercase($string); $string = trim($string, $separator); - $string = preg_replace("/[\/_|+:!@#$%^&*()';=,?\[\]~. -]+/", $separator, $string); + $string = self::removeSpecialCharacters($string, $separator); $string = trim($string, $separator); return $string; } // Transliterate characters to ASCII - $specialCharsFromDictionary = $L->getSpecialChars(); - $string = str_replace(array_keys($specialCharsFromDictionary), $specialCharsFromDictionary, $string); - $string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string); + $unicodeCharsFromDictionary = $L->getunicodeChars(); + $string = str_replace(array_keys($unicodeCharsFromDictionary), $unicodeCharsFromDictionary, $string); + $string = str_replace(array_keys(self::$unicodeChars), self::$unicodeChars, $string); if (function_exists('iconv')) { if (@iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string)!==false) { diff --git a/bl-kernel/language.class.php b/bl-kernel/language.class.php index d0b544a2..774eb58a 100644 --- a/bl-kernel/language.class.php +++ b/bl-kernel/language.class.php @@ -5,7 +5,7 @@ class Language extends dbJSON { public $db; public $currentLanguage; public $dates; - public $specialChars; + public $unicodeChars; function __construct($currentLanguage) { @@ -13,7 +13,7 @@ class Language extends dbJSON { $this->db = array(); $this->currentLanguage = $currentLanguage; $this->dates = array(); - $this->specialChars = array(); + $this->unicodeChars = array(); // Load default language $filename = PATH_LANGUAGES.DEFAULT_LANGUAGE_FILE; @@ -40,10 +40,10 @@ class Language extends dbJSON { unset($this->db['dates']); } - // Special chars - if (isset($this->db['special-chars'])) { - $this->specialChars = $this->db['special-chars']; - unset($this->db['special-chars']); + // Unicode chars + if (isset($this->db['unicode-chars'])) { + $this->unicodeChars = $this->db['unicode-chars']; + unset($this->db['unicode-chars']); } } @@ -68,7 +68,6 @@ class Language extends dbJSON { return $explode[0]; } - // Return the translation, if the translation doesn't exist returns the English translation public function get($string) { @@ -147,8 +146,8 @@ class Language extends dbJSON { } // Returns array with all the special characters from this language - public function getSpecialChars() + public function getunicodeChars() { - return $this->specialChars; + return $this->unicodeChars; } } \ No newline at end of file diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php index 9954c9c7..5d65157f 100644 --- a/bl-kernel/pages.class.php +++ b/bl-kernel/pages.class.php @@ -648,7 +648,7 @@ class Pages extends dbJSON { global $L; if (Text::isEmpty($text)) { - $text = 'empty'; + $text = $L->g('empty'); } if (Text::isEmpty($parent)) { @@ -659,7 +659,7 @@ class Pages extends dbJSON { // cleanURL can return empty string if (Text::isEmpty($newKey)) { - $key = $L->g('empty'); + $newKey = $L->g('empty'); } if ($newKey!==$oldKey) { diff --git a/bl-languages/de_CH.json b/bl-languages/de_CH.json index b464b79f..d58d5e4b 100644 --- a/bl-languages/de_CH.json +++ b/bl-languages/de_CH.json @@ -50,7 +50,7 @@ "November": "November", "December": "Dezember" }, - "special-chars": { + "unicode-chars": { "ä": "ae", "ö": "oe", "ü": "ue" diff --git a/bl-languages/de_DE.json b/bl-languages/de_DE.json index 3b1ba133..c25f025e 100644 --- a/bl-languages/de_DE.json +++ b/bl-languages/de_DE.json @@ -50,7 +50,7 @@ "November": "November", "December": "Dezember" }, - "special-chars": { + "unicode-chars": { "ä": "ae", "ö": "oe", "ü": "ue",