use mb_ functions on strings

This commit is contained in:
flash 2018-09-15 23:55:26 +02:00
parent c1d3a4672a
commit c8aafe1a07
15 changed files with 31 additions and 30 deletions

View file

@ -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'));

View file

@ -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;
}

View file

@ -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',

View file

@ -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'],
]);

View file

@ -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)) {

View file

@ -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;
}
}

View file

@ -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'];

View file

@ -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);
}

View file

@ -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';

View file

@ -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;
}

View file

@ -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.');
}

View file

@ -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';

View file

@ -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(

View file

@ -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;

View file

@ -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;