Rename special chars to unicode chars, remove special chars in username
This commit is contained in:
parent
82d7d1ae7e
commit
f98f14670c
@ -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'];
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -50,7 +50,7 @@
|
||||
"November": "November",
|
||||
"December": "Dezember"
|
||||
},
|
||||
"special-chars": {
|
||||
"unicode-chars": {
|
||||
"ä": "ae",
|
||||
"ö": "oe",
|
||||
"ü": "ue"
|
||||
|
@ -50,7 +50,7 @@
|
||||
"November": "November",
|
||||
"December": "Dezember"
|
||||
},
|
||||
"special-chars": {
|
||||
"unicode-chars": {
|
||||
"ä": "ae",
|
||||
"ö": "oe",
|
||||
"ü": "ue",
|
||||
|
Loading…
Reference in New Issue
Block a user