use Services\IUserSession;
use Services\IStatusReporter;
use Services\IUserQuota;
+use Services\IConfigManager;
use Domain\Entities\IDownloadFactory;
use DataAccess\IFileRepository;
use DataAccess\IDownloadRepository;
private $_userSession;
private $_userQuota;
private $_statusReporter;
+ private $_configManager;
public function __construct(
IHttpRequest $request,
IDownloadRepository $downloadRepository,
IUserSession $userSession,
IUserQuota $userQuota,
- IStatusReporter $statusReporter
+ IStatusReporter $statusReporter,
+ IConfigManager $configManager
) {
$this->_request = $request;
$this->_response = $response;
$this->_userSession = $userSession;
$this->_userQuota = $userQuota;
$this->_statusReporter = $statusReporter;
+ $this->_configManager = $configManager;
}
public function indexAction() {
if($hash == 'default') $this->serveDefaultBanner();
if(!$file) $this->notFound();
- $matches = glob(realpath('../files/' . $file->getPath()) . '/' . $file->getHash() . '.*');
+ $matches = glob(realpath($this->_configManager->getDirective('filesPath') . '/' . $file->getPath()) . '/' . $file->getHash() . '.*');
$match = reset($matches);
$this->_response->setHeader('Content-Type', $file->getMimetype())
{
$this->_response->setHeader("HTTP/1.1 304 Not Modified", 'Nice meme!');
} else {
- $path = '../files/banners/default.png';
+ $path = $this->_configManager->getDirective('filesPath') . '/banners/default.png';
$file = realpath($path);
$this->_response->setHeader('Content-Type', 'image/png')
->setHeader('Content-Length', filesize($file))
$this->_downloadRepository->save($download);
- $zip = '../files/' . $file->getPath() . '/' . $file->getHash() . '.zip';
+ $zip = $this->_configManager->getDirective('filesPath') . '/' . $file->getPath() . '/' . $file->getHash() . '.zip';
//TODO: This may not work on all browser or something. We'll have to see. Also it may hog ram so...
$this->_response->setHeader('Content-Type', $file->getMimetype())
->setHeader('Content-Length', $file->getSize())
\r
namespace Controllers;\r
\r
-use Exception;\r
use Controllers\IDivineController;\r
use Services\Http\IHttpResponse;\r
use Services\Http\IHttpRequest;\r
use Services\IZipParser;\r
use Services\ISMOMatcher;\r
use Services\IStatusReporter;\r
+use Services\IConfigManager;\r
use DataAccess\StepMania\ISimfileRepository;\r
use DataAccess\StepMania\IPackRepository;\r
use DataAccess\IFileRepository;\r
use DataAccess\IDownloadRepository;\r
-use Domain\Entities\StepMania\ISimfile;\r
use Domain\Entities\IFile;\r
-use Domain\Entities\StepMania\IPack;\r
use Domain\Util;\r
\r
class SimfileController implements IDivineController\r
private $_downloadRepository;\r
private $_statusReporter;\r
private $_userSession;\r
+ private $_configManager;\r
\r
public function __construct(\r
IHttpResponse $response,\r
IZipParser $zipParser,\r
ISMOMatcher $smoMatcher,\r
IDownloadRepository $downloadRepository,\r
- IStatusReporter $statusReporter\r
+ IStatusReporter $statusReporter,\r
+ IConfigManager $configManager\r
) {\r
$this->_response = $response;\r
$this->_request = $request;\r
$this->_downloadRepository = $downloadRepository;\r
$this->_statusReporter = $statusReporter;\r
$this->_userSession = $userSession;\r
+ $this->_configManager = $configManager;\r
}\r
\r
public function indexAction() {\r
if(!$this->_userSession->getCurrentUser()) $this->_statusReporter->error('You must be authenticated to upload files');\r
\r
//TODO: Put directory in config ?\r
- $files = $this->_uploadManager->setFilesDirectory('../files')\r
+ $files = $this->_uploadManager->setFilesDirectory($this->_configManager->getDirective('filesPath'))\r
->setDestination('StepMania/')\r
->process();\r
\r
}
}
+ usort($singleSteps, array("Self", "cmp"));
+ usort($doubleSteps, array("Self", "cmp"));
+
return array(
'title' => $simfile->getTitle(),
'artist' => $simfile->getArtist()->getName(),
'hash' => $simfile->getSimfile() ? $simfile->getSimfile()->getHash() : null
);
}
+
+ private static function cmp($a, $b)
+ {
+ $order = array(
+ 'Novice' => 0,
+ 'Easy' => 1,
+ 'Medium' => 2,
+ 'Hard' => 3,
+ 'Expert' => 4,
+ 'Edit' => 5
+ );
+
+ return $order[$a['difficulty']] - $order[$b['difficulty']];
+ }
}
\ No newline at end of file
use finfo;
use Exception;
use Services\IBannerExtracter;
+use Services\IConfigManager;
use Domain\Entities\IFileStepByStepBuilder;
//TODO: This class can probably be refactored to be nicer. Also perhaps the methods could be static?
private $_builder;
private $_destinationFileName;
private $_hash;
+ private $_configManager;
- public function __construct(IFileStepByStepBuilder $builder) {
+ public function __construct(IFileStepByStepBuilder $builder, IConfigManager $configManager) {
$this->_builder = $builder;
+ $this->_configManager = $configManager;
}
public function extractSongBanner($zipfile, $bannerName) {
{
$this->_hash = md5_file('zip://' . $zipfile . '#' . $stat['name']);
$this->_destinationFileName = $this->_hash . '.' . pathinfo($bannerName, PATHINFO_EXTENSION);
- $result = copy('zip://' . $zipfile . '#' . $stat['name'], '../files/banners/' . $this->_destinationFileName);
+ $result = copy('zip://' . $zipfile . '#' . $stat['name'], $this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
break;
}
}
if(!isset($result) || !$result) return null;
$finfo = new finfo(FILEINFO_MIME);
- $mimetype = $finfo->file('../files/banners/' . $this->_destinationFileName);
- $size = filesize('../files/banners/' . $this->_destinationFileName);
+ $mimetype = $finfo->file($this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
+ $size = filesize($this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
/* @var $fff \Domain\Entities\FileStepByStepBuilder */
return $this->_builder->With_Hash($this->_hash)
->With_Path('banners')
$this->_hash = md5_file('zip://' . realpath($zipfile) . '#' . $stat['name']);
$this->_destinationFileName = $this->_hash . '.' . pathinfo($stat['name'], PATHINFO_EXTENSION);
$bannerName = $pathComponents[1];
- $result = copy('zip://' . realpath($zipfile) . '#' . $stat['name'], '../files/banners/' . $this->_destinationFileName);
+ $result = copy('zip://' . realpath($zipfile) . '#' . $stat['name'], $this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
break;
}
}
if(!isset($result) || !$result) return null;
$finfo = new finfo(FILEINFO_MIME);
- $mimetype = $finfo->file('../files/banners/' . $this->_destinationFileName);
- $size = filesize('../files/banners/' . $this->_destinationFileName);
+ $mimetype = $finfo->file($this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
+ $size = filesize($this->_configManager->getDirective('filesPath') . '/banners/' . $this->_destinationFileName);
/* @var $fff \Domain\Entities\FileStepByStepBuilder */
return $this->_builder->With_Hash($this->_hash)
->With_Path('banners')
use Services\IUserSession;
use Services\IStatusReporter;
use Services\InvalidSmFileException;
+use Services\IConfigManager;
class ZipParser implements IZipParser
{
private $_userSession;
private $_file;
private $_statusReporter;
+ private $_configManager;
public function __construct(
ISimfileParser $smParser,
IPackStepByStepBuilder $packBuilder,
IBannerExtracter $bannerExtracter,
IUserSession $userSession,
- IStatusReporter $statusReporter
+ IStatusReporter $statusReporter,
+ IConfigManager $configManager
) {
$this->_smParser = $smParser;
$this->_smBuilder = $smBuilder;
$this->_bannerExtracter = $bannerExtracter;
$this->_userSession = $userSession;
$this->_statusReporter = $statusReporter;
+ $this->_configManager = $configManager;
}
public function parse(IFile $file)
$this->_file = $file;
$this->_za = new ZipArchive();
//XXX: We assume all files are zips. Should be enforced by validation elsewhere.
- $res = $this->_za->open('../files/StepMania/' . $file->getHash() . '.zip');
+ $res = $this->_za->open($this->_configManager->getDirective('filesPath') . '/StepMania/' . $file->getHash() . '.zip');
if($res !== true) throw new Exception ('Could not open zip for reading.');
$this->findSms();
if(count($this->_smFiles) > 1)
{
$packname = $this->packNameFromFiles();
- $banner = $this->_bannerExtracter->extractPackBanner('../files/StepMania/' . $this->_file->getHash() . '.zip', $packname);
+ $banner = $this->_bannerExtracter->extractPackBanner($this->_configManager->getDirective('filesPath') . '/StepMania/' . $this->_file->getHash() . '.zip', $packname);
/* @var $builder \Domain\Entities\StepMania\PackStepByStepBuilder */
$builder = $this->_packBuilder;
$stat = $this->_za->statIndex($i);
if(pathinfo($stat['name'], PATHINFO_EXTENSION) == 'sm')
{
- $path = realpath('../files/StepMania/' . $this->_file->getHash() . '.zip');
+ $path = realpath($this->_configManager->getDirective('filesPath') . '/StepMania/' . $this->_file->getHash() . '.zip');
$smData = file_get_contents('zip://' . $path . '#' . $stat['name']);
$this->_smFiles[$stat['name']] = $smData;
}
{
$parser = $this->_smParser;
$parser->parse($smData);
- $banner = $this->_bannerExtracter->extractSongBanner(realpath('../files/StepMania/' . $this->_file->getHash() . '.zip'), $parser->banner());
+ $banner = $this->_bannerExtracter->extractSongBanner(realpath($this->_configManager->getDirective('filesPath') . '/StepMania/' . $this->_file->getHash() . '.zip'), $parser->banner());
$file = $this->isPack() ? null : $this->_file;
return $this->_smBuilder->With_Title($parser->title())