implode(', ', $info['columns']));\r
}\r
\r
- $queries[$index] = $query;\r
+ //The files table has hash and filename as a unique index.\r
+ //Some packs share the same banner for every file, and we only\r
+ //ever pull them out by hash. So this saves having loads of entries\r
+ $queries[$index] = $query . ' ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)';\r
}\r
\r
// if($queries['TYPE'] == AbstractPopulationHelper::QUERY_TYPE_CREATE)\r
// {\r
$idMap = [];\r
foreach($queries as $index => $query)\r
- { \r
+ {\r
$runQuery = true;\r
//originally was preg_quote('%').'(.*?)'.preg_quote('%') but that failed with things like:\r
//...VALUES ('Voyager Full 50%', %INDEX_REF_0%\r
$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);
$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;
}
/* @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())
interface IBannerExtracter
{
- public function extractSongBanner($zipfile, $bannerName);
+ public function extractSongBanner($zipfile, $bannerIndex);
public function extractPackBanner($zipfile, $packname);
}
{
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 &&
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())
->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
<body>
<form action="/simfiles/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
- <input type="hidden" name="token" value="CAAFdJomTiBABAJqHJZBRqz3CMkFMfTlSbtUJsEeZCBUuPxl1ugT9Q4mVfwnYLdfAlwblEjFcYqliNwZBNIplbEZCNCEZBZCjX2Xp3bIvflBv0YYAATZCRgJkzq0S2SdfOY5pFEvRCWxZCH9SHBh1R6eqMmuDR1h5vSq4SDY9sMpf0G1nwtw5VRGz" />
+ <input type="hidden" name="token" value="CAAFdJomTiBABAMx0eKHYDJ89mTFFTUirrFQhlziCHoUlbl5aNWbRZA9fLQxLfKDhS8KPRblAdZBXt6kDkYRiNH1v0WDDqgEDekIgv76wUelNCpi0x2PKxZCJQxpwop0N4MqpwAYgqlGHEOz4Ns4h66q2wJrujfCPExJyQrFaUbRZB5Li2FZCTkJKW5ZBUbY9AZD" />
<input type="submit" name="submit" value="submit" />
</form>
</body>