From: Cameron Ball Date: Fri, 20 Feb 2015 12:19:52 +0000 (+0800) Subject: Merge changes from home PC X-Git-Url: http://git.cameron1729.xyz/?p=rock.divinelegy.git;a=commitdiff_plain;h=98b9b4d0bb95ae1f3742c1caa1cffa29be6106f0 Merge changes from home PC --- diff --git a/DataAccess/DataMapper/DataMapper.php b/DataAccess/DataMapper/DataMapper.php index 5c817dc..a4e474c 100644 --- a/DataAccess/DataMapper/DataMapper.php +++ b/DataAccess/DataMapper/DataMapper.php @@ -153,14 +153,17 @@ class DataMapper implements IDataMapper implode(', ', $info['columns'])); } - $queries[$index] = $query; + //The files table has hash and filename as a unique index. + //Some packs share the same banner for every file, and we only + //ever pull them out by hash. So this saves having loads of entries + $queries[$index] = $query . ' ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)'; } // if($queries['TYPE'] == AbstractPopulationHelper::QUERY_TYPE_CREATE) // { $idMap = []; foreach($queries as $index => $query) - { + { $runQuery = true; //originally was preg_quote('%').'(.*?)'.preg_quote('%') but that failed with things like: //...VALUES ('Voyager Full 50%', %INDEX_REF_0% diff --git a/Services/BannerExtracter.php b/Services/BannerExtracter.php index 2c29373..c5fdc50 100644 --- a/Services/BannerExtracter.php +++ b/Services/BannerExtracter.php @@ -22,7 +22,7 @@ class BannerExtracter implements IBannerExtracter $this->_configManager = $configManager; } - public function extractSongBanner($zipfile, $bannerName) { + public function extractSongBanner($zipfile, $bannerIndex) { $za = new ZipArchive(); //XXX: We assume all files are zips. Should be enforced by validation elsewhere. $res = $za->open($zipfile); @@ -34,10 +34,10 @@ class BannerExtracter implements IBannerExtracter $stat = $za->statIndex($i); $type = @exif_imagetype('zip://' . realpath($zipfile) . '#' . $stat['name']); //Sometimes simfiles specify a video as their banner. Fuck dat. - if(basename($stat['name']) == $bannerName && $type !== false) + if($stat['name'] == $bannerIndex && $type !== false) { $this->_hash = md5_file('zip://' . $zipfile . '#' . $stat['name']); - $this->_destinationFileName = $this->_hash . '.' . pathinfo($bannerName, PATHINFO_EXTENSION); + $this->_destinationFileName = $this->_hash . '.' . pathinfo($bannerIndex, PATHINFO_EXTENSION); $result = copy('zip://' . $zipfile . '#' . $stat['name'], $this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName); break; } @@ -51,7 +51,7 @@ class BannerExtracter implements IBannerExtracter /* @var $fff \Domain\Entities\FileStepByStepBuilder */ return $this->_builder->With_Hash($this->_hash) ->With_Path('banners') - ->With_Filename($bannerName) + ->With_Filename(basename($bannerIndex)) ->With_Mimetype($mimetype) ->With_Size($size) ->With_UploadDate(time()) diff --git a/Services/IBannerExtracter.php b/Services/IBannerExtracter.php index a56a31f..ec963ee 100644 --- a/Services/IBannerExtracter.php +++ b/Services/IBannerExtracter.php @@ -4,6 +4,6 @@ namespace Services; interface IBannerExtracter { - public function extractSongBanner($zipfile, $bannerName); + public function extractSongBanner($zipfile, $bannerIndex); public function extractPackBanner($zipfile, $packname); } diff --git a/Services/ZipParser.php b/Services/ZipParser.php index 2286eb5..e349e6a 100644 --- a/Services/ZipParser.php +++ b/Services/ZipParser.php @@ -114,7 +114,7 @@ class ZipParser implements IZipParser { try { - $this->_smFiles[$index] = $this->SmDataToSmClass($data); + $this->_smFiles[$index] = $this->SmDataToSmClass($data, $index); } catch(Exception $e) { //Exceptions we care about at this stage if(!$e instanceof InvalidSmFileException && @@ -149,11 +149,14 @@ class ZipParser implements IZipParser return $packName; } - private function SmDataToSmClass($smData) - { + private function SmDataToSmClass($smData, $index) + { $parser = $this->_smParser; $parser->parse($smData); - $banner = $this->_bannerExtracter->extractSongBanner(realpath($this->_configManager->getDirective('filesPath') . '/StepMania/' . $this->_file->getHash() . '.zip'), $parser->banner()); + + $bannerIndex = $this->resolveBannerIndex($parser->banner(), $index); + $banner = $this->_bannerExtracter->extractSongBanner(realpath($this->_configManager->getDirective('filesPath') . '/StepMania/' . $this->_file->getHash() . '.zip'), $bannerIndex); + $file = $this->isPack() ? null : $this->_file; return $this->_smBuilder->With_Title($parser->title()) @@ -169,4 +172,15 @@ class ZipParser implements IZipParser ->With_Banner($banner) ->build(); } + + private function resolveBannerIndex($bannerDirective, $smFileIndex) + { + if(strpos($bannerDirective, '../') !== false || strpos($bannerDirective, '..\\') !== false) + { + $pathInfo = pathinfo($smFileIndex); + return str_replace('..', dirname($pathInfo['dirname']), $bannerDirective); + } + + return dirname($smFileIndex) . '/' . $bannerDirective; + } } \ No newline at end of file diff --git a/files/banners/default.png b/files/banners/default.png deleted file mode 100644 index 68df6b7..0000000 Binary files a/files/banners/default.png and /dev/null differ diff --git a/public_html/upload.html b/public_html/upload.html index a551bb2..eb59711 100644 --- a/public_html/upload.html +++ b/public_html/upload.html @@ -2,7 +2,7 @@
- +