Commit efb567e3 authored by Hugh Davenport's avatar Hugh Davenport Committed by Gerrit Code Review
Browse files

Merge "Use mb_ funcs on new usernames with diacritics. (Bug #1026618)"

parents dbcb498f d91b44b7
......@@ -1479,20 +1479,43 @@ function load_user_institutions($userid) {
*/
function get_new_username($desired) {
$maxlen = 30;
$desired = strtolower(substr($desired, 0, $maxlen));
$taken = get_column_sql('
SELECT LOWER(username) FROM {usr}
WHERE username ' . db_ilike() . " ?",
array(substr($desired, 0, $maxlen - 6) . '%'));
if (function_exists('mb_strtolower')) {
$desired = mb_strtolower(mb_substr($desired, 0, $maxlen, 'UTF-8'), 'UTF-8');
}
else {
$desired = strtolower(substr($desired, 0, $maxlen));
}
if (function_exists('mb_substr')) {
$taken = get_column_sql('
SELECT LOWER(username) FROM {usr}
WHERE username ' . db_ilike() . " ?",
array(mb_substr($desired, 0, $maxlen - 6, 'UTF-8') . '%'));
}
else {
$taken = get_column_sql('
SELECT LOWER(username) FROM {usr}
WHERE username ' . db_ilike() . " ?",
array(substr($desired, 0, $maxlen - 6) . '%'));
}
if (!$taken) {
return $desired;
}
$taken = array_flip($taken);
$i = '';
$newname = substr($desired, 0, $maxlen - 1) . $i;
if (function_exists('mb_substr')) {
$newname = mb_substr($desired, 0, $maxlen - 1, 'UTF-8') . $i;
}
else {
$newname = substr($desired, 0, $maxlen - 1) . $i;
}
while (isset($taken[$newname])) {
$i++;
$newname = substr($desired, 0, $maxlen - strlen($i)) . $i;
if (function_exists('mb_substr')) {
$newname = mb_substr($desired, 0, $maxlen - strlen($i), 'UTF-8') . $i;
}
else {
$newname = substr($desired, 0, $maxlen - strlen($i)) . $i;
}
}
return $newname;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment