diff --git a/misuzu.php b/misuzu.php index ca415a8b..53e43b38 100644 --- a/misuzu.php +++ b/misuzu.php @@ -2,6 +2,7 @@ namespace Misuzu; date_default_timezone_set('UTC'); +mb_internal_encoding('UTF-8'); define('MSZ_DEBUG', file_exists(__DIR__ . '/vendor/phpunit/phpunit/composer.json')); diff --git a/public/comments.php b/public/comments.php index e907fce1..97b346bd 100644 --- a/public/comments.php +++ b/public/comments.php @@ -136,7 +136,7 @@ switch ($_GET['m'] ?? null) { break; } - if (strlen($commentText) > 5000) { + if (mb_strlen($commentText) > 5000) { echo render_info_or_json($isXHR, 'Your comment is too long.', 400); break; } diff --git a/public/members.php b/public/members.php index 0edbbed2..93ad7c26 100644 --- a/public/members.php +++ b/public/members.php @@ -7,8 +7,8 @@ $usersOffset = max((int)($_GET['o'] ?? 0), 0); $usersTake = 30; $roleId = (int)($_GET['r'] ?? MSZ_ROLE_MAIN); -$orderBy = strtolower($_GET['ss'] ?? ''); -$orderDir = strtolower($_GET['sd'] ?? ''); +$orderBy = mb_strtolower($_GET['ss'] ?? ''); +$orderDir = mb_strtolower($_GET['sd'] ?? ''); $orderDirs = [ 'asc' => 'Ascending', diff --git a/public/settings.php b/public/settings.php index b2f262dd..f3b0877c 100644 --- a/public/settings.php +++ b/public/settings.php @@ -242,7 +242,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $settingsErrors[] = 'Unknown e-mail validation error.'; } } else { - $updateAccountFields['email'] = strtolower($_POST['email']['new']); + $updateAccountFields['email'] = mb_strtolower($_POST['email']['new']); audit_log('PERSONAL_EMAIL_CHANGE', $app->getUserId(), [ $updateAccountFields['email'], ]); diff --git a/src/Application.php b/src/Application.php index 5c6dd389..0dfbe45d 100644 --- a/src/Application.php +++ b/src/Application.php @@ -124,7 +124,7 @@ class Application extends ApplicationBase */ public function getPath(string $path): string { - if (!starts_with($path, '/') && substr($path, 1, 2) !== ':\\') { + if (!starts_with($path, '/') && mb_substr($path, 1, 2) !== ':\\') { $path = __DIR__ . '/../' . $path; } @@ -310,7 +310,7 @@ class Application extends ApplicationBase } if ($this->configInstance->contains('Mail')) { - $method = strtolower($this->configInstance->get('Mail', 'method')); + $method = mb_strtolower($this->configInstance->get('Mail', 'method')); } if (empty($method) || !array_key_exists($method, self::MAIL_TRANSPORT)) { diff --git a/src/Config/ConfigManager.php b/src/Config/ConfigManager.php index 792fc070..8859ca59 100644 --- a/src/Config/ConfigManager.php +++ b/src/Config/ConfigManager.php @@ -92,7 +92,7 @@ class ConfigManager switch (strtolower($type)) { case "bool": case "boolean": - $value = strlen($raw) > 0 && ($raw[0] === '1' || strtolower($raw) === "true"); + $value = mb_strlen($raw) > 0 && ($raw[0] === '1' || mb_strtolower($raw) === "true"); break; case "int": @@ -124,7 +124,7 @@ class ConfigManager $type = gettype($value); $store = null; - switch (strtolower($type)) { + switch (mb_strtolower($type)) { case 'boolean': $store = $value ? '1' : '0'; break; @@ -209,7 +209,7 @@ class ConfigManager foreach ($lines as $line) { $line = trim($line, "\r\n"); - $length = strlen($line); + $length = mb_strlen($line); if ($length < 1 || starts_with($line, '#') @@ -228,7 +228,7 @@ class ConfigManager continue; } - if (strpos($line, '=') !== false) { + if (mb_strpos($line, '=') !== false) { $split = explode('=', $line, 2); if (count($split) < 2) { @@ -238,7 +238,7 @@ class ConfigManager $key = trim($split[0]); $value = trim($split[1]); - if (strlen($key) > 0 && strlen($value) > 0) { + if (mb_strlen($key) > 0 && mb_strlen($value) > 0) { $collection[$section][$key] = $value; } } diff --git a/src/DatabaseMigrationManager.php b/src/DatabaseMigrationManager.php index b0d1cf10..b780be1a 100644 --- a/src/DatabaseMigrationManager.php +++ b/src/DatabaseMigrationManager.php @@ -146,7 +146,7 @@ final class DatabaseMigrationManager } for ($i = 4; $i < count($filenameSplit); $i++) { - $migrationName .= ucfirst(strtolower($filenameSplit[$i])); + $migrationName .= ucfirst(mb_strtolower($filenameSplit[$i])); } include_once $migration; @@ -217,7 +217,7 @@ final class DatabaseMigrationManager $migrationName = ''; for ($i = 4; $i < count($nameSplit); $i++) { - $migrationName .= ucfirst(strtolower($nameSplit[$i])); + $migrationName .= ucfirst(mb_strtolower($nameSplit[$i])); } include_once $migration['migration_path']; diff --git a/src/ExceptionHandler.php b/src/ExceptionHandler.php index 74d7fb76..f08c46b1 100644 --- a/src/ExceptionHandler.php +++ b/src/ExceptionHandler.php @@ -92,7 +92,7 @@ class ExceptionHandler */ private static function report(Throwable $throwable): bool { - if (!strlen(self::$reportUrl)) { + if (!mb_strlen(self::$reportUrl)) { return false; } @@ -119,7 +119,7 @@ class ExceptionHandler 'Content-Type: application/json;charset=utf-8', ]; - if (strlen(self::$reportSign)) { + if (mb_strlen(self::$reportSign)) { $headers[] = 'X-Misuzu-Signature: sha256=' . hash_hmac('sha256', $json, self::$reportSign); } diff --git a/src/Forum/validate.php b/src/Forum/validate.php index 850a397b..27b1e3f3 100644 --- a/src/Forum/validate.php +++ b/src/Forum/validate.php @@ -6,7 +6,7 @@ define('MSZ_POST_TEXT_LENGTH_MAX', 60000); function forum_validate_title(string $title): string { - $length = strlen($title); + $length = mb_strlen($title); if ($length < MSZ_TOPIC_TITLE_LENGTH_MIN) { return 'too-short'; @@ -21,7 +21,7 @@ function forum_validate_title(string $title): string function forum_validate_post(string $text): string { - $length = strlen($text); + $length = mb_strlen($text); if ($length < MSZ_POST_TEXT_LENGTH_MIN) { return 'too-short'; diff --git a/src/IO/Directory.php b/src/IO/Directory.php index f45518bf..2027f8fd 100644 --- a/src/IO/Directory.php +++ b/src/IO/Directory.php @@ -102,7 +102,7 @@ class Directory foreach ($split_path as $path_part) { $existing_path .= $path_part . self::SEPARATOR; - if ($on_windows && substr($path_part, 1, 2) === ':\\') { + if ($on_windows && mb_substr($path_part, 1, 2) === ':\\') { continue; } diff --git a/src/Net/IPAddressRange.php b/src/Net/IPAddressRange.php index 189e5797..7f9574c2 100644 --- a/src/Net/IPAddressRange.php +++ b/src/Net/IPAddressRange.php @@ -97,7 +97,7 @@ final class IPAddressRange */ public static function fromMaskedString(string $maskedString): IPAddressRange { - if (strpos($maskedString, '/') === false) { + if (mb_strpos($maskedString, '/') === false) { throw new InvalidArgumentException('Invalid masked string.'); } @@ -118,7 +118,7 @@ final class IPAddressRange */ public static function fromRangeString(string $rangeString): IPAddressRange { - if (strpos($rangeString, '-') === false) { + if (mb_strpos($rangeString, '-') === false) { throw new InvalidArgumentException('Invalid range string.'); } diff --git a/src/Users/validation.php b/src/Users/validation.php index 21567d23..df42029e 100644 --- a/src/Users/validation.php +++ b/src/Users/validation.php @@ -16,7 +16,7 @@ define('MSZ_PASSWORD_MIN_ENTROPY', 32); function user_validate_username(string $username, bool $checkInUse = false): string { - $username_length = strlen($username); + $username_length = mb_strlen($username); if ($username !== trim($username)) { return 'trim'; diff --git a/src/changelog.php b/src/changelog.php index b1833645..593ad808 100644 --- a/src/changelog.php +++ b/src/changelog.php @@ -11,7 +11,7 @@ function changelog_action_add(string $name, ?int $colour = null, ?string $class $colour = colour_none(); } - $class = preg_replace('#[^a-z]#', '', strtolower($class ?? $name)); + $class = preg_replace('#[^a-z]#', '', mb_strtolower($class ?? $name)); $addAction = Database::prepare(' INSERT INTO `msz_changelog_actions` @@ -66,7 +66,7 @@ define('MSZ_CHANGELOG_GET_QUERY', ' function changelog_get_changes(string $date, int $user, int $offset, int $take): array { - $hasDate = strlen($date) > 0; + $hasDate = mb_strlen($date) > 0; $hasUser = $user > 0; $query = sprintf( @@ -101,7 +101,7 @@ define('CHANGELOG_COUNT_QUERY', ' function changelog_count_changes(string $date, int $user): int { - $hasDate = strlen($date) > 0; + $hasDate = mb_strlen($date) > 0; $hasUser = $user > 0; $query = sprintf( diff --git a/src/colour.php b/src/colour.php index 224f2a51..536d1d12 100644 --- a/src/colour.php +++ b/src/colour.php @@ -115,10 +115,10 @@ function colour_from_rgb(int &$colour, int $red, int $green, int $blue): bool function colour_from_hex(int &$colour, string $hex): bool { if ($hex[0] === '#') { - $hex = substr($hex, 1); + $hex = mb_substr($hex, 1); } - $length = strlen($hex); + $length = mb_strlen($hex); if ($length === 3) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; @@ -128,9 +128,9 @@ function colour_from_hex(int &$colour, string $hex): bool colour_from_rgb( $colour, - hexdec(substr($hex, 0, 2)), - hexdec(substr($hex, 2, 2)), - hexdec(substr($hex, 4, 2)) + hexdec(mb_substr($hex, 0, 2)), + hexdec(mb_substr($hex, 2, 2)), + hexdec(mb_substr($hex, 4, 2)) ); return true; diff --git a/src/zalgo.php b/src/zalgo.php index d013291b..ba9e6145 100644 --- a/src/zalgo.php +++ b/src/zalgo.php @@ -74,7 +74,7 @@ function zalgo_run( int $mode = MSZ_ZALGO_MODE_MINI, int $direction = MSZ_ZALGO_DIR_MID | MSZ_ZALGO_DIR_DOWN ): string { - $text_length = strlen($text); + $text_length = mb_strlen($text); if (!$text_length || !$mode || !$direction) { return $text;