From 512ff8e48c1327e0cc9175e0044c6938d31bedc9 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sat, 15 Jan 2022 18:24:01 +0100 Subject: [PATCH] Add replacing [Regional Indicator Symbols](https://en.wikipedia.org/wiki/Regional_indicator_symbol) with latin letters. Feel free to add more emoji translations. --- include/functions_permalinks.inc.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/include/functions_permalinks.inc.php b/include/functions_permalinks.inc.php index 7238e3c2..73b12db7 100644 --- a/include/functions_permalinks.inc.php +++ b/include/functions_permalinks.inc.php @@ -15,6 +15,64 @@ if (IN_serendipity !== true) { * @return string output string */ function serendipity_makeFilename($str, $stripDots = false) { + + // These are UTF-8 replacements happening regardless of selected locale + static $pre_from = array( + '🇦', + '🇧', + '🇨', + '🇩', + '🇪', + '🇫', + '🇬', + '🇭', + '🇮', + '🇯', + '🇰', + '🇱', + '🇲', + '🇳', + '🇴', + '🇵', + '🇶', + '🇷', + '🇸', + '🇹', + '🇺', + '🇻', + '🇼', + '🇽', + '🇾', + '🇿'); + + static $pre_to = array( + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z'); + + // These are replacements happening after all UTF-8 characters have been stripped away static $from = array( ' ', '%', @@ -109,6 +167,9 @@ function serendipity_makeFilename($str, $stripDots = false) { $str = str_replace('/', '%2F', $str); $str = urlencode($str); } else { + // Replace some emojis and flags into latin characters before utf8_decode() strips them away + $str = str_replace($pre_from, $pre_to, $str); + if (isset($GLOBALS['i18n_filename_from'])) { // Replace international chars not detected by every locale. // The array of chars is defined in the language file.