use mb_ functions on strings
This commit is contained in:
parent
c1d3a4672a
commit
c8aafe1a07
15 changed files with 31 additions and 30 deletions
|
@ -2,6 +2,7 @@
|
||||||
namespace Misuzu;
|
namespace Misuzu;
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
mb_internal_encoding('UTF-8');
|
||||||
|
|
||||||
define('MSZ_DEBUG', file_exists(__DIR__ . '/vendor/phpunit/phpunit/composer.json'));
|
define('MSZ_DEBUG', file_exists(__DIR__ . '/vendor/phpunit/phpunit/composer.json'));
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ switch ($_GET['m'] ?? null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($commentText) > 5000) {
|
if (mb_strlen($commentText) > 5000) {
|
||||||
echo render_info_or_json($isXHR, 'Your comment is too long.', 400);
|
echo render_info_or_json($isXHR, 'Your comment is too long.', 400);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ $usersOffset = max((int)($_GET['o'] ?? 0), 0);
|
||||||
$usersTake = 30;
|
$usersTake = 30;
|
||||||
|
|
||||||
$roleId = (int)($_GET['r'] ?? MSZ_ROLE_MAIN);
|
$roleId = (int)($_GET['r'] ?? MSZ_ROLE_MAIN);
|
||||||
$orderBy = strtolower($_GET['ss'] ?? '');
|
$orderBy = mb_strtolower($_GET['ss'] ?? '');
|
||||||
$orderDir = strtolower($_GET['sd'] ?? '');
|
$orderDir = mb_strtolower($_GET['sd'] ?? '');
|
||||||
|
|
||||||
$orderDirs = [
|
$orderDirs = [
|
||||||
'asc' => 'Ascending',
|
'asc' => 'Ascending',
|
||||||
|
|
|
@ -242,7 +242,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$settingsErrors[] = 'Unknown e-mail validation error.';
|
$settingsErrors[] = 'Unknown e-mail validation error.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$updateAccountFields['email'] = strtolower($_POST['email']['new']);
|
$updateAccountFields['email'] = mb_strtolower($_POST['email']['new']);
|
||||||
audit_log('PERSONAL_EMAIL_CHANGE', $app->getUserId(), [
|
audit_log('PERSONAL_EMAIL_CHANGE', $app->getUserId(), [
|
||||||
$updateAccountFields['email'],
|
$updateAccountFields['email'],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Application extends ApplicationBase
|
||||||
*/
|
*/
|
||||||
public function getPath(string $path): string
|
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;
|
$path = __DIR__ . '/../' . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ class Application extends ApplicationBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->configInstance->contains('Mail')) {
|
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)) {
|
if (empty($method) || !array_key_exists($method, self::MAIL_TRANSPORT)) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ class ConfigManager
|
||||||
switch (strtolower($type)) {
|
switch (strtolower($type)) {
|
||||||
case "bool":
|
case "bool":
|
||||||
case "boolean":
|
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;
|
break;
|
||||||
|
|
||||||
case "int":
|
case "int":
|
||||||
|
@ -124,7 +124,7 @@ class ConfigManager
|
||||||
$type = gettype($value);
|
$type = gettype($value);
|
||||||
$store = null;
|
$store = null;
|
||||||
|
|
||||||
switch (strtolower($type)) {
|
switch (mb_strtolower($type)) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$store = $value ? '1' : '0';
|
$store = $value ? '1' : '0';
|
||||||
break;
|
break;
|
||||||
|
@ -209,7 +209,7 @@ class ConfigManager
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$line = trim($line, "\r\n");
|
$line = trim($line, "\r\n");
|
||||||
$length = strlen($line);
|
$length = mb_strlen($line);
|
||||||
|
|
||||||
if ($length < 1
|
if ($length < 1
|
||||||
|| starts_with($line, '#')
|
|| starts_with($line, '#')
|
||||||
|
@ -228,7 +228,7 @@ class ConfigManager
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, '=') !== false) {
|
if (mb_strpos($line, '=') !== false) {
|
||||||
$split = explode('=', $line, 2);
|
$split = explode('=', $line, 2);
|
||||||
|
|
||||||
if (count($split) < 2) {
|
if (count($split) < 2) {
|
||||||
|
@ -238,7 +238,7 @@ class ConfigManager
|
||||||
$key = trim($split[0]);
|
$key = trim($split[0]);
|
||||||
$value = trim($split[1]);
|
$value = trim($split[1]);
|
||||||
|
|
||||||
if (strlen($key) > 0 && strlen($value) > 0) {
|
if (mb_strlen($key) > 0 && mb_strlen($value) > 0) {
|
||||||
$collection[$section][$key] = $value;
|
$collection[$section][$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ final class DatabaseMigrationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 4; $i < count($filenameSplit); $i++) {
|
for ($i = 4; $i < count($filenameSplit); $i++) {
|
||||||
$migrationName .= ucfirst(strtolower($filenameSplit[$i]));
|
$migrationName .= ucfirst(mb_strtolower($filenameSplit[$i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once $migration;
|
include_once $migration;
|
||||||
|
@ -217,7 +217,7 @@ final class DatabaseMigrationManager
|
||||||
$migrationName = '';
|
$migrationName = '';
|
||||||
|
|
||||||
for ($i = 4; $i < count($nameSplit); $i++) {
|
for ($i = 4; $i < count($nameSplit); $i++) {
|
||||||
$migrationName .= ucfirst(strtolower($nameSplit[$i]));
|
$migrationName .= ucfirst(mb_strtolower($nameSplit[$i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once $migration['migration_path'];
|
include_once $migration['migration_path'];
|
||||||
|
|
|
@ -92,7 +92,7 @@ class ExceptionHandler
|
||||||
*/
|
*/
|
||||||
private static function report(Throwable $throwable): bool
|
private static function report(Throwable $throwable): bool
|
||||||
{
|
{
|
||||||
if (!strlen(self::$reportUrl)) {
|
if (!mb_strlen(self::$reportUrl)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class ExceptionHandler
|
||||||
'Content-Type: application/json;charset=utf-8',
|
'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);
|
$headers[] = 'X-Misuzu-Signature: sha256=' . hash_hmac('sha256', $json, self::$reportSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ define('MSZ_POST_TEXT_LENGTH_MAX', 60000);
|
||||||
|
|
||||||
function forum_validate_title(string $title): string
|
function forum_validate_title(string $title): string
|
||||||
{
|
{
|
||||||
$length = strlen($title);
|
$length = mb_strlen($title);
|
||||||
|
|
||||||
if ($length < MSZ_TOPIC_TITLE_LENGTH_MIN) {
|
if ($length < MSZ_TOPIC_TITLE_LENGTH_MIN) {
|
||||||
return 'too-short';
|
return 'too-short';
|
||||||
|
@ -21,7 +21,7 @@ function forum_validate_title(string $title): string
|
||||||
|
|
||||||
function forum_validate_post(string $text): string
|
function forum_validate_post(string $text): string
|
||||||
{
|
{
|
||||||
$length = strlen($text);
|
$length = mb_strlen($text);
|
||||||
|
|
||||||
if ($length < MSZ_POST_TEXT_LENGTH_MIN) {
|
if ($length < MSZ_POST_TEXT_LENGTH_MIN) {
|
||||||
return 'too-short';
|
return 'too-short';
|
||||||
|
|
|
@ -102,7 +102,7 @@ class Directory
|
||||||
foreach ($split_path as $path_part) {
|
foreach ($split_path as $path_part) {
|
||||||
$existing_path .= $path_part . self::SEPARATOR;
|
$existing_path .= $path_part . self::SEPARATOR;
|
||||||
|
|
||||||
if ($on_windows && substr($path_part, 1, 2) === ':\\') {
|
if ($on_windows && mb_substr($path_part, 1, 2) === ':\\') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ final class IPAddressRange
|
||||||
*/
|
*/
|
||||||
public static function fromMaskedString(string $maskedString): IPAddressRange
|
public static function fromMaskedString(string $maskedString): IPAddressRange
|
||||||
{
|
{
|
||||||
if (strpos($maskedString, '/') === false) {
|
if (mb_strpos($maskedString, '/') === false) {
|
||||||
throw new InvalidArgumentException('Invalid masked string.');
|
throw new InvalidArgumentException('Invalid masked string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ final class IPAddressRange
|
||||||
*/
|
*/
|
||||||
public static function fromRangeString(string $rangeString): IPAddressRange
|
public static function fromRangeString(string $rangeString): IPAddressRange
|
||||||
{
|
{
|
||||||
if (strpos($rangeString, '-') === false) {
|
if (mb_strpos($rangeString, '-') === false) {
|
||||||
throw new InvalidArgumentException('Invalid range string.');
|
throw new InvalidArgumentException('Invalid range string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ define('MSZ_PASSWORD_MIN_ENTROPY', 32);
|
||||||
|
|
||||||
function user_validate_username(string $username, bool $checkInUse = false): string
|
function user_validate_username(string $username, bool $checkInUse = false): string
|
||||||
{
|
{
|
||||||
$username_length = strlen($username);
|
$username_length = mb_strlen($username);
|
||||||
|
|
||||||
if ($username !== trim($username)) {
|
if ($username !== trim($username)) {
|
||||||
return 'trim';
|
return 'trim';
|
||||||
|
|
|
@ -11,7 +11,7 @@ function changelog_action_add(string $name, ?int $colour = null, ?string $class
|
||||||
$colour = colour_none();
|
$colour = colour_none();
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = preg_replace('#[^a-z]#', '', strtolower($class ?? $name));
|
$class = preg_replace('#[^a-z]#', '', mb_strtolower($class ?? $name));
|
||||||
|
|
||||||
$addAction = Database::prepare('
|
$addAction = Database::prepare('
|
||||||
INSERT INTO `msz_changelog_actions`
|
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
|
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;
|
$hasUser = $user > 0;
|
||||||
|
|
||||||
$query = sprintf(
|
$query = sprintf(
|
||||||
|
@ -101,7 +101,7 @@ define('CHANGELOG_COUNT_QUERY', '
|
||||||
|
|
||||||
function changelog_count_changes(string $date, int $user): int
|
function changelog_count_changes(string $date, int $user): int
|
||||||
{
|
{
|
||||||
$hasDate = strlen($date) > 0;
|
$hasDate = mb_strlen($date) > 0;
|
||||||
$hasUser = $user > 0;
|
$hasUser = $user > 0;
|
||||||
|
|
||||||
$query = sprintf(
|
$query = sprintf(
|
||||||
|
|
|
@ -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
|
function colour_from_hex(int &$colour, string $hex): bool
|
||||||
{
|
{
|
||||||
if ($hex[0] === '#') {
|
if ($hex[0] === '#') {
|
||||||
$hex = substr($hex, 1);
|
$hex = mb_substr($hex, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$length = strlen($hex);
|
$length = mb_strlen($hex);
|
||||||
|
|
||||||
if ($length === 3) {
|
if ($length === 3) {
|
||||||
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
|
$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_from_rgb(
|
||||||
$colour,
|
$colour,
|
||||||
hexdec(substr($hex, 0, 2)),
|
hexdec(mb_substr($hex, 0, 2)),
|
||||||
hexdec(substr($hex, 2, 2)),
|
hexdec(mb_substr($hex, 2, 2)),
|
||||||
hexdec(substr($hex, 4, 2))
|
hexdec(mb_substr($hex, 4, 2))
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -74,7 +74,7 @@ function zalgo_run(
|
||||||
int $mode = MSZ_ZALGO_MODE_MINI,
|
int $mode = MSZ_ZALGO_MODE_MINI,
|
||||||
int $direction = MSZ_ZALGO_DIR_MID | MSZ_ZALGO_DIR_DOWN
|
int $direction = MSZ_ZALGO_DIR_MID | MSZ_ZALGO_DIR_DOWN
|
||||||
): string {
|
): string {
|
||||||
$text_length = strlen($text);
|
$text_length = mb_strlen($text);
|
||||||
|
|
||||||
if (!$text_length || !$mode || !$direction) {
|
if (!$text_length || !$mode || !$direction) {
|
||||||
return $text;
|
return $text;
|
||||||
|
|
Loading…
Add table
Reference in a new issue