From d7c6092d5f9e3bdcdb6e07e0ca440a98b2b59d51 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 19 Sep 2015 16:11:10 +0200 Subject: [PATCH] Strings/Encoding * replaced some more uses of string functions with multibyte equivalents where it might matter note: i didn't touch the spell-tooltip parser as it seems to work as intended regardless --- includes/ajaxHandler.class.php | 8 ++++---- includes/community.class.php | 4 ++-- includes/types/basetype.class.php | 6 +++--- includes/user.class.php | 2 +- pages/admin.php | 2 +- pages/genericPage.class.php | 2 +- pages/profile.php | 2 +- pages/search.php | 10 +++++----- pages/utility.php | 2 +- setup/tools/CLISetup.class.php | 16 ++++++++-------- setup/tools/clisetup/dbconfig.func.php | 2 +- setup/tools/filegen/profiler.func.php | 4 ++-- setup/tools/filegen/simpleImg.func.php | 4 ++-- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/includes/ajaxHandler.class.php b/includes/ajaxHandler.class.php index ba73ef5c..5ae8d3c1 100644 --- a/includes/ajaxHandler.class.php +++ b/includes/ajaxHandler.class.php @@ -307,7 +307,7 @@ class AjaxHandler // trim to max length if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->post('commentbody')) > $_maxCmt) - $this->post['body'] = substr($this->post('body'), 0, $_maxCmt); + $this->post['body'] = mb_substr($this->post('body'), 0, $_maxCmt); if (User::canComment() && !empty($this->post('commentbody')) && mb_strlen($this->post('commentbody')) >= $_minCmt) { @@ -335,7 +335,7 @@ class AjaxHandler // trim to max length if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->post('body')) > $_maxCmt) - $this->post['body'] = substr($this->post('body'), 0, $_maxCmt); + $this->post['body'] = mb_substr($this->post('body'), 0, $_maxCmt); $update = array( 'body' => $this->post('body'), @@ -965,7 +965,7 @@ class AjaxHandler } } - $buff .= 'g_spells.add('.$id.", {id:".$id.", name:'".Util::jsEscape(substr($data['name'], 1))."', icon:'".$data['icon']."', modifier:".Util::toJSON($mods)."});\n"; + $buff .= 'g_spells.add('.$id.", {id:".$id.", name:'".Util::jsEscape(mb_substr($data['name'], 1))."', icon:'".$data['icon']."', modifier:".Util::toJSON($mods)."});\n"; } $buff .= "\n"; } @@ -1130,7 +1130,7 @@ class AjaxHandler if ($this->get('type') && intVal($this->get('type')) && $this->get('typeid') && intVal($this->get('typeid'))) $res = CommunityContent::getScreenshotsForManager($this->get('type'), $this->get('typeid')); - else if ($this->get('user') && strlen(urldecode($this->get('user'))) > 2) + else if ($this->get('user') && mb_strlen(urldecode($this->get('user'))) > 2) if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', strtolower(urldecode($this->get('user'))))) $res = CommunityContent::getScreenshotsForManager(0, 0, $uId); diff --git a/includes/community.class.php b/includes/community.class.php index b25c90f6..8b5feb9e 100644 --- a/includes/community.class.php +++ b/includes/community.class.php @@ -175,7 +175,7 @@ class CommunityContent // limit whitespaces to one at a time $c['preview'] = preg_replace('/\s+/', ' ', $c['preview']); // limit previews to 100 chars + whatever it takes to make the last word full - if (strlen($c['preview']) > 100) + if (mb_strlen($c['preview']) > 100) { $n = 0; $b = []; @@ -183,7 +183,7 @@ class CommunityContent while ($n < 100 && $parts) { $_ = array_shift($parts); - $n += strlen($_); + $n += mb_strlen($_); $b[] = $_; } diff --git a/includes/types/basetype.class.php b/includes/types/basetype.class.php index a34a2bb4..3d4f81ca 100644 --- a/includes/types/basetype.class.php +++ b/includes/types/basetype.class.php @@ -922,9 +922,9 @@ abstract class Filter $parts = array_filter(explode(' ', $string)); foreach ($parts as $p) { - if ($p[0] == '-' && strlen($p) > 3) - $sub[] = [$f, sprintf($exPH, substr($p, 1)), '!']; - else if ($p[0] != '-' && strlen($p) > 2) + if ($p[0] == '-' && mb_strlen($p) > 3) + $sub[] = [$f, sprintf($exPH, mb_substr($p, 1)), '!']; + else if ($p[0] != '-' && mb_strlen($p) > 2) $sub[] = [$f, sprintf($exPH, $p)]; } diff --git a/includes/user.class.php b/includes/user.class.php index b0dc04a0..ac82e491 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -370,7 +370,7 @@ class User { $errCode = 0; - if (strlen($name) < 4 || strlen($name) > 16) + if (mb_strlen($name) < 4 || mb_strlen($name) > 16) $errCode = 1; else if (preg_match('/[^\w\d]/i', $name)) $errCode = 2; diff --git a/pages/admin.php b/pages/admin.php index 245a1537..53cb2b07 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -454,7 +454,7 @@ class AdminPage extends GenericPage else if (!empty($_GET['user'])) { $name = urldecode($_GET['user']); - if (strlen($name) > 3) + if (mb_strlen($name) >= 3) { if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', ucFirst($name))) { diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 8a599e1c..87cf58b2 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -108,7 +108,7 @@ class GenericPage $this->time = microtime(true); if (CFG_CACHE_DIR && Util::checkOrCreateDirectory(CFG_CACHE_DIR)) - $this->cacheDir = substr(CFG_CACHE_DIR, -1) != '/' ? CFG_CACHE_DIR.'/' : CFG_CACHE_DIR; + $this->cacheDir = mb_substr(CFG_CACHE_DIR, -1) != '/' ? CFG_CACHE_DIR.'/' : CFG_CACHE_DIR; // force page refresh if (isset($_GET['refresh']) && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_DEV)) diff --git a/pages/profile.php b/pages/profile.php index 853d2a2b..c348f4ac 100644 --- a/pages/profile.php +++ b/pages/profile.php @@ -24,7 +24,7 @@ class ProfilePage extends GenericPage public function __construct($pageCall, $pageParam) { - $_ = strlen($pageParam) ? explode('.', $pageParam) : null; + $_ = $pageParam ? explode('.', $pageParam) : null; $this->getCategoryFromUrl($pageParam); $this->typeId &= $this->profileId; diff --git a/pages/search.php b/pages/search.php index 2fb62fe4..6918f6c5 100644 --- a/pages/search.php +++ b/pages/search.php @@ -124,14 +124,14 @@ class SearchPage extends GenericPage continue; else if ($p[0] == '-') { - if (strlen($p) < 4) - $this->invalid[] = substr($p, 1); + if (mb_strlen($p) < 4) + $this->invalid[] = mb_substr($p, 1); else - $this->excluded[] = substr($p, 1); + $this->excluded[] = mb_substr($p, 1); } else if ($p !== '') { - if (strlen($p) < 3) + if (mb_strlen($p) < 3) $this->invalid[] = $p; else $this->included[] = $p; @@ -311,7 +311,7 @@ class SearchPage extends GenericPage break; $hasQ = is_numeric($data['name'][0]) || $data['name'][0] == '@'; - $result[1][] = ($hasQ ? substr($data['name'], 1) : $data['name']).$set['appendix']; + $result[1][] = ($hasQ ? mb_substr($data['name'], 1) : $data['name']).$set['appendix']; $result[3][] = HOST_URL.'/?'.Util::$typeStrings[$set['type']].'='.$data['id']; $extra = [$set['type'], $data['id']]; diff --git a/pages/utility.php b/pages/utility.php index b8c70f36..db09c4ff 100644 --- a/pages/utility.php +++ b/pages/utility.php @@ -235,7 +235,7 @@ class UtilityPage extends GenericPage foreach ($data as $typeId => &$d) { $this->feedData[] = array( - 'title' => [true, [], htmlentities(Util::$typeStrings[$type] == 'item' ? substr($d['name'], 1) : $d['name'])], + 'title' => [true, [], htmlentities(Util::$typeStrings[$type] == 'item' ? mb_substr($d['name'], 1) : $d['name'])], 'type' => [false, [], Util::$typeStrings[$type]], 'link' => [false, [], HOST_URL.'/?'.Util::$typeStrings[$type].'='.$d['id']], 'ncomments' => [false, [], $comments[$typeId]] diff --git a/setup/tools/CLISetup.class.php b/setup/tools/CLISetup.class.php index 3705d3a6..d7f8010f 100644 --- a/setup/tools/CLISetup.class.php +++ b/setup/tools/CLISetup.class.php @@ -100,13 +100,13 @@ class CLISetup $setupDirs = glob('setup/*'); foreach ($setupDirs as $sd) { - if (substr(self::$srcDir, -1) == '/') - self::$srcDir = substr(self::$srcDir, 0, -1); + if (mb_substr(self::$srcDir, -1) == '/') + self::$srcDir = mb_substr(self::$srcDir, 0, -1); - if (substr($sd, -1) == '/') - $sd = substr($sd, 0, -1); + if (mb_substr($sd, -1) == '/') + $sd = mb_substr($sd, 0, -1); - if (strtolower($sd) == strtolower(self::$srcDir)) + if (Util::lower($sd) == Util::lower(self::$srcDir)) { self::$srcDir = $sd.'/'; break; @@ -147,8 +147,8 @@ class CLISetup $_ = strtolower(str_replace('\\', '/', $file)); // remove trailing slash - if (substr($_, -1, 1) == '/') - $_ = substr($_, 0, -1); + if (mb_substr($_, -1, 1) == '/') + $_ = mb_substr($_, 0, -1); if (isset(self::$mpqFiles[$_])) { @@ -387,7 +387,7 @@ class CLISetup if (!$charBuff) continue; - $charBuff = substr($charBuff, 0, -1); + $charBuff = mb_substr($charBuff, 0, -1); echo chr(self::CHR_BACK)." ".chr(self::CHR_BACK); } else if ($keyId == self::CHR_LF) diff --git a/setup/tools/clisetup/dbconfig.func.php b/setup/tools/clisetup/dbconfig.func.php index b5b0dda7..e259a804 100644 --- a/setup/tools/clisetup/dbconfig.func.php +++ b/setup/tools/clisetup/dbconfig.func.php @@ -36,7 +36,7 @@ function dbconfig() $errStr = '['.mysqli_connect_errno().'] '.mysqli_connect_error(); $buff .= $errStr ? CLISetup::red('ERR ') : CLISetup::green('OK '); - $buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].'/'.$dbInfo['db']; + $buff .= 'mysqli://'.$dbInfo['user'].':'.str_pad('', mb_strlen($dbInfo['pass']), '*').'@'.$dbInfo['host'].'/'.$dbInfo['db']; $buff .= ($dbInfo['prefix'] ? ' table prefix: '.$dbInfo['prefix'] : null).' '.$errStr; } else diff --git a/setup/tools/filegen/profiler.func.php b/setup/tools/filegen/profiler.func.php index f739f5f2..0afd70ce 100644 --- a/setup/tools/filegen/profiler.func.php +++ b/setup/tools/filegen/profiler.func.php @@ -163,7 +163,7 @@ if (!CLI) foreach ($mountz->getListviewData(ITEMINFO_MODEL) as $id => $data) { $data['quality'] = $data['name'][0]; - $data['name'] = substr($data['name'], 1); + $data['name'] = mb_substr($data['name'], 1); $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; } @@ -198,7 +198,7 @@ if (!CLI) foreach ($companionz->getListviewData(ITEMINFO_MODEL) as $id => $data) { $data['quality'] = $data['name'][0]; - $data['name'] = substr($data['name'], 1); + $data['name'] = mb_substr($data['name'], 1); $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; } diff --git a/setup/tools/filegen/simpleImg.func.php b/setup/tools/filegen/simpleImg.func.php index 9e9ee830..723e6316 100644 --- a/setup/tools/filegen/simpleImg.func.php +++ b/setup/tools/filegen/simpleImg.func.php @@ -21,8 +21,8 @@ if (!CLI) { $result = null; - if (in_array(substr($path, -4, 4), ['.png', '.blp', '.BLP', '.PNG'])) - $path = substr($path, 0, strlen($path) - 4); + if (in_array(mb_substr($path, -4, 4), ['.png', '.blp', '.BLP', '.PNG'])) + $path = mb_substr($path, 0, mb_strlen($path) - 4); $file = $path.'.png'; if (CLISetup::fileExists($file))