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
This commit is contained in:
Sarjuuk
2015-09-19 16:11:10 +02:00
parent 6dc6124673
commit d7c6092d5f
13 changed files with 32 additions and 32 deletions

View File

@@ -307,7 +307,7 @@ class AjaxHandler
// trim to max length // trim to max length
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->post('commentbody')) > $_maxCmt) 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) if (User::canComment() && !empty($this->post('commentbody')) && mb_strlen($this->post('commentbody')) >= $_minCmt)
{ {
@@ -335,7 +335,7 @@ class AjaxHandler
// trim to max length // trim to max length
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->post('body')) > $_maxCmt) 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( $update = array(
'body' => $this->post('body'), '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"; $buff .= "\n";
} }
@@ -1130,7 +1130,7 @@ class AjaxHandler
if ($this->get('type') && intVal($this->get('type')) && $this->get('typeid') && intVal($this->get('typeid'))) if ($this->get('type') && intVal($this->get('type')) && $this->get('typeid') && intVal($this->get('typeid')))
$res = CommunityContent::getScreenshotsForManager($this->get('type'), $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'))))) if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', strtolower(urldecode($this->get('user')))))
$res = CommunityContent::getScreenshotsForManager(0, 0, $uId); $res = CommunityContent::getScreenshotsForManager(0, 0, $uId);

View File

@@ -175,7 +175,7 @@ class CommunityContent
// limit whitespaces to one at a time // limit whitespaces to one at a time
$c['preview'] = preg_replace('/\s+/', ' ', $c['preview']); $c['preview'] = preg_replace('/\s+/', ' ', $c['preview']);
// limit previews to 100 chars + whatever it takes to make the last word full // 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; $n = 0;
$b = []; $b = [];
@@ -183,7 +183,7 @@ class CommunityContent
while ($n < 100 && $parts) while ($n < 100 && $parts)
{ {
$_ = array_shift($parts); $_ = array_shift($parts);
$n += strlen($_); $n += mb_strlen($_);
$b[] = $_; $b[] = $_;
} }

View File

@@ -922,9 +922,9 @@ abstract class Filter
$parts = array_filter(explode(' ', $string)); $parts = array_filter(explode(' ', $string));
foreach ($parts as $p) foreach ($parts as $p)
{ {
if ($p[0] == '-' && strlen($p) > 3) if ($p[0] == '-' && mb_strlen($p) > 3)
$sub[] = [$f, sprintf($exPH, substr($p, 1)), '!']; $sub[] = [$f, sprintf($exPH, mb_substr($p, 1)), '!'];
else if ($p[0] != '-' && strlen($p) > 2) else if ($p[0] != '-' && mb_strlen($p) > 2)
$sub[] = [$f, sprintf($exPH, $p)]; $sub[] = [$f, sprintf($exPH, $p)];
} }

View File

@@ -370,7 +370,7 @@ class User
{ {
$errCode = 0; $errCode = 0;
if (strlen($name) < 4 || strlen($name) > 16) if (mb_strlen($name) < 4 || mb_strlen($name) > 16)
$errCode = 1; $errCode = 1;
else if (preg_match('/[^\w\d]/i', $name)) else if (preg_match('/[^\w\d]/i', $name))
$errCode = 2; $errCode = 2;

View File

@@ -454,7 +454,7 @@ class AdminPage extends GenericPage
else if (!empty($_GET['user'])) else if (!empty($_GET['user']))
{ {
$name = urldecode($_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))) if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', ucFirst($name)))
{ {

View File

@@ -108,7 +108,7 @@ class GenericPage
$this->time = microtime(true); $this->time = microtime(true);
if (CFG_CACHE_DIR && Util::checkOrCreateDirectory(CFG_CACHE_DIR)) 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 // force page refresh
if (isset($_GET['refresh']) && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_DEV)) if (isset($_GET['refresh']) && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_DEV))

View File

@@ -24,7 +24,7 @@ class ProfilePage extends GenericPage
public function __construct($pageCall, $pageParam) public function __construct($pageCall, $pageParam)
{ {
$_ = strlen($pageParam) ? explode('.', $pageParam) : null; $_ = $pageParam ? explode('.', $pageParam) : null;
$this->getCategoryFromUrl($pageParam); $this->getCategoryFromUrl($pageParam);
$this->typeId &= $this->profileId; $this->typeId &= $this->profileId;

View File

@@ -124,14 +124,14 @@ class SearchPage extends GenericPage
continue; continue;
else if ($p[0] == '-') else if ($p[0] == '-')
{ {
if (strlen($p) < 4) if (mb_strlen($p) < 4)
$this->invalid[] = substr($p, 1); $this->invalid[] = mb_substr($p, 1);
else else
$this->excluded[] = substr($p, 1); $this->excluded[] = mb_substr($p, 1);
} }
else if ($p !== '') else if ($p !== '')
{ {
if (strlen($p) < 3) if (mb_strlen($p) < 3)
$this->invalid[] = $p; $this->invalid[] = $p;
else else
$this->included[] = $p; $this->included[] = $p;
@@ -311,7 +311,7 @@ class SearchPage extends GenericPage
break; break;
$hasQ = is_numeric($data['name'][0]) || $data['name'][0] == '@'; $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']; $result[3][] = HOST_URL.'/?'.Util::$typeStrings[$set['type']].'='.$data['id'];
$extra = [$set['type'], $data['id']]; $extra = [$set['type'], $data['id']];

View File

@@ -235,7 +235,7 @@ class UtilityPage extends GenericPage
foreach ($data as $typeId => &$d) foreach ($data as $typeId => &$d)
{ {
$this->feedData[] = array( $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]], 'type' => [false, [], Util::$typeStrings[$type]],
'link' => [false, [], HOST_URL.'/?'.Util::$typeStrings[$type].'='.$d['id']], 'link' => [false, [], HOST_URL.'/?'.Util::$typeStrings[$type].'='.$d['id']],
'ncomments' => [false, [], $comments[$typeId]] 'ncomments' => [false, [], $comments[$typeId]]

View File

@@ -100,13 +100,13 @@ class CLISetup
$setupDirs = glob('setup/*'); $setupDirs = glob('setup/*');
foreach ($setupDirs as $sd) foreach ($setupDirs as $sd)
{ {
if (substr(self::$srcDir, -1) == '/') if (mb_substr(self::$srcDir, -1) == '/')
self::$srcDir = substr(self::$srcDir, 0, -1); self::$srcDir = mb_substr(self::$srcDir, 0, -1);
if (substr($sd, -1) == '/') if (mb_substr($sd, -1) == '/')
$sd = substr($sd, 0, -1); $sd = mb_substr($sd, 0, -1);
if (strtolower($sd) == strtolower(self::$srcDir)) if (Util::lower($sd) == Util::lower(self::$srcDir))
{ {
self::$srcDir = $sd.'/'; self::$srcDir = $sd.'/';
break; break;
@@ -147,8 +147,8 @@ class CLISetup
$_ = strtolower(str_replace('\\', '/', $file)); $_ = strtolower(str_replace('\\', '/', $file));
// remove trailing slash // remove trailing slash
if (substr($_, -1, 1) == '/') if (mb_substr($_, -1, 1) == '/')
$_ = substr($_, 0, -1); $_ = mb_substr($_, 0, -1);
if (isset(self::$mpqFiles[$_])) if (isset(self::$mpqFiles[$_]))
{ {
@@ -387,7 +387,7 @@ class CLISetup
if (!$charBuff) if (!$charBuff)
continue; continue;
$charBuff = substr($charBuff, 0, -1); $charBuff = mb_substr($charBuff, 0, -1);
echo chr(self::CHR_BACK)." ".chr(self::CHR_BACK); echo chr(self::CHR_BACK)." ".chr(self::CHR_BACK);
} }
else if ($keyId == self::CHR_LF) else if ($keyId == self::CHR_LF)

View File

@@ -36,7 +36,7 @@ function dbconfig()
$errStr = '['.mysqli_connect_errno().'] '.mysqli_connect_error(); $errStr = '['.mysqli_connect_errno().'] '.mysqli_connect_error();
$buff .= $errStr ? CLISetup::red('ERR ') : CLISetup::green('OK '); $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; $buff .= ($dbInfo['prefix'] ? ' table prefix: '.$dbInfo['prefix'] : null).' '.$errStr;
} }
else else

View File

@@ -163,7 +163,7 @@ if (!CLI)
foreach ($mountz->getListviewData(ITEMINFO_MODEL) as $id => $data) foreach ($mountz->getListviewData(ITEMINFO_MODEL) as $id => $data)
{ {
$data['quality'] = $data['name'][0]; $data['quality'] = $data['name'][0];
$data['name'] = substr($data['name'], 1); $data['name'] = mb_substr($data['name'], 1);
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
} }
@@ -198,7 +198,7 @@ if (!CLI)
foreach ($companionz->getListviewData(ITEMINFO_MODEL) as $id => $data) foreach ($companionz->getListviewData(ITEMINFO_MODEL) as $id => $data)
{ {
$data['quality'] = $data['name'][0]; $data['quality'] = $data['name'][0];
$data['name'] = substr($data['name'], 1); $data['name'] = mb_substr($data['name'], 1);
$buff .= '_['.$id.'] = '.Util::toJSON($data).";\n"; $buff .= '_['.$id.'] = '.Util::toJSON($data).";\n";
} }

View File

@@ -21,8 +21,8 @@ if (!CLI)
{ {
$result = null; $result = null;
if (in_array(substr($path, -4, 4), ['.png', '.blp', '.BLP', '.PNG'])) if (in_array(mb_substr($path, -4, 4), ['.png', '.blp', '.BLP', '.PNG']))
$path = substr($path, 0, strlen($path) - 4); $path = mb_substr($path, 0, mb_strlen($path) - 4);
$file = $path.'.png'; $file = $path.'.png';
if (CLISetup::fileExists($file)) if (CLISetup::fileExists($file))