unicode usernames

This commit is contained in:
Mike Macgirvin 2024-05-23 07:55:46 +10:00
parent cf331a1d0f
commit fc1ae4691d
4 changed files with 33 additions and 29 deletions

View file

@ -1680,12 +1680,12 @@ function format_mentions($item)
$txt = $x[0]['xchan_name'];
break;
case 1:
$txt = (($x[0]['xchan_addr']) ?: $x[0]['xchan_name']);
$txt = (($x[0]['xchan_addr']) ? unpunify_addr($x[0]['xchan_addr']): $x[0]['xchan_name']);
break;
case 2:
default;
if ($x[0]['xchan_addr']) {
$txt = sprintf(t('%1$s (%2$s)'), $x[0]['xchan_name'], $x[0]['xchan_addr']);
$txt = sprintf(t('%1$s (%2$s)'), $x[0]['xchan_name'], unpunify_addr($x[0]['xchan_addr']));
} else {
$txt = $x[0]['xchan_name'];
}
@ -3991,6 +3991,19 @@ function featured_sort($a, $b)
return(strcmp($s1, $s2));
}
function unpunify_addr($s)
{
$output = '';
$arr = explode('@', $s);
if ($arr) {
foreach ($arr as $str) {
$output .= unpunify($str);
$output .= '@';
}
$output = rtrim($output, '@');
}
return $output;
}
function unpunify($s)
{

View file

@ -2045,7 +2045,7 @@ class Channel
$nick = punify($nick);
// return a cached copy if there is a cached copy and it's a match.
// return a cached copy - if there is a cached copy, and it's a match.
// Also check that there is an xchan_hash to validate the App::$channel data is complete
// and that columns from both joined tables are present

View file

@ -454,8 +454,8 @@ class ThreadItem
'undo_attend' => $undo_attend,
'consensus' => '',
'conlabels' => '',
'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url'])),
'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), (($this->get_owner_addr()) ? $this->get_owner_addr() : $this->get_owner_url())),
'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? unpunify_addr($item['author']['xchan_addr']) : $item['author']['xchan_url'])),
'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), (($this->get_owner_addr()) ? unpunify_addr($this->get_owner_addr()) : $this->get_owner_url())),
'llink' => $item['llink'],
'viewthread' => $viewthread,
'to' => t('to'),

View file

@ -25,32 +25,28 @@ class New_channel extends Controller
if ($cmd === 'autofill.json') {
$n = trim($_REQUEST['name']);
$x = false;
$n = punify(mb_strtolower($n));
if (get_config('system', 'unicode_usernames')) {
$x = punify(mb_strtolower($n));
}
if ((!$x) || strlen($x) > 64) {
$x = strtolower(URLify::transliterate($n));
if (strlen($n) > 64) {
$n = strtolower(URLify::transliterate($n));
}
$test = [];
// first name
if (strpos($x, ' ')) {
$test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
if (strpos($n, ' ')) {
$test[] = legal_webbie(substr($n, 0, strpos($n, ' ')));
}
if ($test[0]) {
// first name plus first initial of last
$test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '');
$test[] = ((strpos($n, ' ')) ? $test[0] . legal_webbie(trim(substr($n, strpos($n, ' '), 2))) : '');
// first name plus random number
$test[] = $test[0] . mt_rand(1000, 9999);
}
// fullname
$test[] = legal_webbie($x);
$test[] = legal_webbie($n);
// fullname plus random number
$test[] = legal_webbie($x) . mt_rand(1000, 9999);
$test[] = legal_webbie($n) . mt_rand(1000, 9999);
json_return_and_die(check_webbie($test));
}
@ -61,31 +57,26 @@ class New_channel extends Controller
$n = trim($_REQUEST['name']);
}
$x = false;
$n = punify(mb_strtolower($n));
if (get_config('system', 'unicode_usernames')) {
$x = punify(mb_strtolower($n));
if (strlen($n) > 64) {
$n = strtolower(URLify::transliterate($n));
}
if ((!$x) || strlen($x) > 64) {
$x = strtolower(URLify::transliterate($n));
}
$test = [];
// first name
if (strpos($x, ' ')) {
$test[] = legal_webbie(substr($x, 0, strpos($x, ' ')));
if (strpos($n, ' ')) {
$test[] = legal_webbie(substr($n, 0, strpos($n, ' ')));
}
if ($test[0]) {
// first name plus first initial of last
$test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : '');
$test[] = ((strpos($n, ' ')) ? $test[0] . legal_webbie(trim(substr($n, strpos($n, ' '), 2))) : '');
// first name plus random number
$test[] = $test[0] . mt_rand(1000, 9999);
}
$n = legal_webbie($x);
$n = legal_webbie($n);
if (strlen($n)) {
$test[] = $n;
$test[] = $n . mt_rand(1000, 9999);