From 47cf5c7c14a13ae96a6bf98b400cff866c80e705 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Mon, 29 Dec 2014 01:38:29 +0800 Subject: [PATCH] Better character encoding handling. --- .gitignore | 1 + DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php | 2 ++ Services/SimfileParser.php | 9 ++++----- Services/Uploads/UploadManager.php | 2 +- Services/ZipParser.php | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c1cdda3..75bb758 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ logs composer.lock vendor db.php +files/* files/StepMania/* files/banners/* !files/banners/default.png diff --git a/DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php b/DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php index 00a442a..8e9ac84 100644 --- a/DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php +++ b/DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php @@ -202,6 +202,8 @@ class AbstractPopulationHelper } break; case 'DataAccess\DataMapper\Helpers\VarcharMapsHelper': + //XXX: pls magically fix all my character encoding issues. + $property = mb_convert_encoding($property, "UTF-8", mb_detect_encoding($property, "UTF-8, ISO-8859-1, ISO-8859-15", true)); if($id){ //easy case, plain values in our table. $query .= sprintf('%s="%s", ', diff --git a/Services/SimfileParser.php b/Services/SimfileParser.php index fcb5618..c0245cb 100644 --- a/Services/SimfileParser.php +++ b/Services/SimfileParser.php @@ -33,9 +33,8 @@ class SimfileParser implements ISimfileParser { $title = $this->extractKey('TITLE'); if(!$title) throw new InvalidSmFileException('Invalid SM file. TITLE missing'); - - //XXX: UTF8 encode to deal with unusual character that crop up in weeaboo shit. - return utf8_encode($title); + + return $title; } public function artist() @@ -45,7 +44,7 @@ class SimfileParser implements ISimfileParser if(!$artist)return null; //XXX: UTF8 encode to deal with unusual character that crop up in weeaboo shit. - return new \Domain\VOs\StepMania\Artist(utf8_encode($artist)); + return new \Domain\VOs\StepMania\Artist($artist); } public function stops() @@ -148,7 +147,7 @@ class SimfileParser implements ISimfileParser return new \Domain\VOs\StepMania\StepChart( new \Domain\VOs\StepMania\DanceMode($stepData[0]), new \Domain\VOs\StepMania\Difficulty($stepData[2]), - empty($stepData[1]) ? null : new \Domain\VOs\StepMania\StepArtist(utf8_encode($stepData[1])), + empty($stepData[1]) ? null : new \Domain\VOs\StepMania\StepArtist($stepData[1]), //XXX: Fuck you whoever made me do this. http://dev.mysql.com/doc/refman/5.5/en/integer-types.html //XXX: Originally I was using MySQL unsigned bigint max value, but PHP does not have unsigned ints so $stepData[3] <= 9223372036854775807 ? $stepData[3] : 9223372036854775807 diff --git a/Services/Uploads/UploadManager.php b/Services/Uploads/UploadManager.php index 81a6413..c1356ae 100644 --- a/Services/Uploads/UploadManager.php +++ b/Services/Uploads/UploadManager.php @@ -26,7 +26,7 @@ class UploadManager implements IUploadManager{ foreach($_FILES as $file) { $this->_files[] = $this->_fileFactory->createInstance( - utf8_encode($file['name']), + $file['name'], $file['type'], $file['tmp_name'], $file['size'] diff --git a/Services/ZipParser.php b/Services/ZipParser.php index 380a6c4..528771c 100644 --- a/Services/ZipParser.php +++ b/Services/ZipParser.php @@ -142,7 +142,7 @@ class ZipParser implements IZipParser throw new Exception('Malformed zip. I found more than 1 sm file but the directory structure is not consistent with a pack.'); } - return utf8_encode($packName); + return $packName; } private function SmDataToSmClass($smData) -- 2.11.0