Merge branch '3.3.x'

This commit is contained in:
Marc Alexander 2019-10-28 20:23:02 +01:00
commit 6e961a6954
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
2 changed files with 42 additions and 13 deletions

View file

@ -986,10 +986,20 @@ class acp_forums
$errors[] = $user->lang['FORUM_NAME_EMPTY'];
}
// No Emojis
/**
* Replace Emojis and other 4bit UTF-8 chars not allowed by MySql to UCR / NCR.
* Using their Numeric Character Reference's Hexadecimal notation.
*/
$forum_data_ary['forum_name'] = utf8_encode_ucr($forum_data_ary['forum_name']);
/**
* This should never happen again.
* Leaving the fallback here just in case there will be the need of it.
*/
if (preg_match_all('/[\x{10000}-\x{10FFFF}]/u', $forum_data_ary['forum_name'], $matches))
{
$character_list = implode('<br>', $matches[0]);
$errors[] = $user->lang('FORUM_NAME_EMOJI', $character_list);
}

View file

@ -417,8 +417,27 @@ function utf8_recode($string, $encoding)
trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
}
/**
* Replace some special UTF-8 chars that are not in ASCII with their UCR.
* using their Numeric Character Reference's Hexadecimal notation.
*
* Doesn't interfere with Japanese or Cyrillic etc.
* Unicode character visualization will depend on the character support
* of your web browser and the fonts installed on your system.
*
* @see https://en.wikibooks.org/wiki/Unicode/Character_reference/1F000-1FFFF
*
* @param string $text UTF-8 string in NFC
* @return string ASCII string using NCR for non-ASCII chars
*/
function utf8_encode_ucr($text)
{
return preg_replace_callback('/[\\xF0-\\xF4].../', 'utf8_encode_ncr_callback', $text);
}
/**
* Replace all UTF-8 chars that are not in ASCII with their NCR
* using their Numeric Character Reference's Hexadecimal notation.
*
* @param string $text UTF-8 string in NFC
* @return string ASCII string using NCRs for non-ASCII chars
@ -429,7 +448,7 @@ function utf8_encode_ncr($text)
}
/**
* Callback used in encode_ncr()
* Callback used in utf8_encode_ncr() and utf8_encode_ucr()
*
* Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array
*