From 4db8eada7bbd07b6c1de76b9a0506324c3b7ba72 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Sat, 13 Dec 2014 16:45:33 +0800 Subject: [PATCH] Fucking Windows bullshit. --- Controllers/FileController.php | 7 ++++--- Services/BannerExtracter.php | 4 ++-- Services/IStatusReporter.php | 2 +- Services/StatusReporter.php | 2 +- Services/ZipParser.php | 3 ++- public_html/index.php | 6 +++++- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Controllers/FileController.php b/Controllers/FileController.php index c50a623..22b000f 100644 --- a/Controllers/FileController.php +++ b/Controllers/FileController.php @@ -53,9 +53,10 @@ class FileController implements IDivineController $file = $this->_fileRepository->findByHash($hash); if($hash == 'default') $this->serveDefaultBanner(); if(!$file) $this->notFound(); - - $match = reset(glob('../files/' . $file->getPath() . '/' . $file->getHash() . '.*')); - + + $matches = glob(realpath('../files/' . $file->getPath()) . '/' . $file->getHash() . '.*'); + $match = reset($matches); + $this->_response->setHeader('Content-Type', $file->getMimetype()) ->setHeader('Content-Length', $file->getSize()) ->setBody(file_get_contents($match)) diff --git a/Services/BannerExtracter.php b/Services/BannerExtracter.php index 2de532d..63fce25 100644 --- a/Services/BannerExtracter.php +++ b/Services/BannerExtracter.php @@ -65,7 +65,7 @@ class BannerExtracter implements IBannerExtracter for($i=0; $i<$za->numFiles; $i++) { $stat = $za->statIndex($i); - $type = @exif_imagetype('zip://' . $zipfile . '#' . $stat['name']); + $type = @exif_imagetype('zip://' . realpath($zipfile) . '#' . $stat['name']); if($type !== false) { @@ -77,7 +77,7 @@ class BannerExtracter implements IBannerExtracter $this->_hash = $this->randomFilename($stat['name']); $this->_destinationFileName = $this->_hash . '.' . pathinfo($stat['name'], PATHINFO_EXTENSION); $bannerName = $pathComponents[1]; - $result = copy('zip://' . $zipfile . '#' . $stat['name'], '../files/banners/' . $this->_destinationFileName); + $result = copy('zip://' . realpath($zipfile) . '#' . $stat['name'], '../files/banners/' . $this->_destinationFileName); break; } } diff --git a/Services/IStatusReporter.php b/Services/IStatusReporter.php index 97d5da8..3214a41 100644 --- a/Services/IStatusReporter.php +++ b/Services/IStatusReporter.php @@ -8,6 +8,6 @@ interface IStatusReporter { public function success($message); public function error($message); - public function exception(Exception $exception); + public static function exception(Exception $exception); public function json(); } diff --git a/Services/StatusReporter.php b/Services/StatusReporter.php index b36a53d..3667c88 100644 --- a/Services/StatusReporter.php +++ b/Services/StatusReporter.php @@ -41,7 +41,7 @@ class StatusReporter implements IStatusReporter } //no need to exit here, exceptions stop the program. - public function exception(Exception $exception) + public static function exception(Exception $exception) { //we'll be instatic context here so I have to do it this way. header('Content-Type: application/json'); diff --git a/Services/ZipParser.php b/Services/ZipParser.php index f3a55f4..3abc391 100644 --- a/Services/ZipParser.php +++ b/Services/ZipParser.php @@ -89,7 +89,8 @@ class ZipParser implements IZipParser $stat = $this->_za->statIndex($i); if(pathinfo($stat['name'], PATHINFO_EXTENSION) == 'sm') { - $smData = file_get_contents('zip://../files/StepMania/' . $this->_file->getHash() . '.zip#' . $stat['name']); + $path = realpath('../files/StepMania/' . $this->_file->getHash() . '.zip'); + $smData = file_get_contents('zip://' . $path . '#' . $stat['name']); $this->_smFiles[$stat['name']] = $smData; } } diff --git a/public_html/index.php b/public_html/index.php index 2aa5c39..f6afb25 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -8,7 +8,11 @@ $config = require('../config/app.php'); header("Access-Control-Allow-Origin: " . $config['allow-origin']); // Nice exceptions -if($config['mode'] == 'production') set_exception_handler(array('\Services\StatusReporter', 'exception')); +if($config['mode'] == 'production') +{ + ini_set('display_errors', 0); + set_exception_handler(array('\Services\StatusReporter', 'exception')); +} // Everything time related should be UTC+0 based date_default_timezone_set('UTC'); -- 2.11.0