Implement serendipity_mb_ucfirst() as that's not available.

This commit is contained in:
Markus Birth 2022-02-20 01:58:00 +01:00
parent f4bd9bc07a
commit 25b8dbcb42
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
2 changed files with 5 additions and 38 deletions

View File

@ -188,7 +188,7 @@ function serendipity_formatTime($format, $time, $useOffset = true, $useDate = fa
}
}
return serendipity_mb('ucfirst', serendipity_strftime($cache[$format], (int)$time, $useOffset, $useDate));
return serendipity_mb_ucfirst(serendipity_strftime($cache[$format], (int)$time, $useOffset, $useDate));
}
/**

View File

@ -68,43 +68,10 @@ if (!defined('serendipity_MB_LOADED') && defined('serendipity_LANG_LOADED')) {
* @param mixed Any input array, dynamically evaluated for best emulation
* @return mixed
*/
function serendipity_mb(string $func, ...$args) {
static $mbstring = null;
if (is_null($mbstring)) {
$mbstring = (extension_loaded('mbstring') && @mb_internal_encoding(LANG_CHARSET) ? 1 : 0);
if ($mbstring === 1) {
if (function_exists('mb_strtoupper')) {
$mbstring = 2;
}
}
}
switch($func) {
case 'ucfirst':
// there's no mb_ucfirst, so emulate it
if ($mbstring === 2) {
$enc = LANG_CHARSET;
return mb_strtoupper(mb_substr($args[0], 0, 1, $enc), $enc) . mb_substr($args[0], 1, mb_strlen($args[0], $enc), $enc);
} else {
return ucfirst($args[0]);
}
case 'strtolower':
case 'strtoupper':
if ($mbstring === 2) {
return call_user_func_array('mb_' . $func, $args);
} else {
return call_user_func_array($func, $args);
}
default:
if ($mbstring) {
return call_user_func_array('mb_' . $func, $args);
} else {
return call_user_func_array($func, $args);
}
}
function serendipity_mb_ucfirst(string $str)
{
// there's no mb_ucfirst, so emulate it
return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1);
}
define('serendipity_MB_LOADED', true);