*/
_tmpHash: '',
- /**
- * absolute path to WCF directory
- * @var string
- */
- _wcfPath: '',
-
/**
* @see WCF.Upload.init()
*/
- init: function(tmpHash, wcfPath) {
+ init: function(tmpHash) {
this._tmpHash = tmpHash;
- this._wcfPath = wcfPath;
this._button = $('#uploadLogo');
this._image = $('#styleLogo');
var $src = this._pageLogo.val();
if ($src.length) {
if (!$src.match(/^https?:\/\//)) {
- var $path = this._imagePath.val();
- if (!$path) {
- $path = 'images/';
- }
+ var $path = this._getImagePath();
- $path = this._wcfPath + $path.replace(/^\/?images\/?/, '');
+ $path = WCF_PATH + $path;
if ($path.substr(-1) !== '/') {
$path += '/';
}
this._image.attr('src', $src + '?timestamp=' + Date.now());
},
+ /**
+ * Returns the style's image path.
+ */
+ _getImagePath: function () {
+ return this._imagePath.val() || 'images/';
+ },
+
/**
* @see WCF.Upload._initFile()
*/
*/
_getParameters: function() {
return {
- tmpHash: this._tmpHash
+ tmpHash: this._tmpHash,
+ imagePath: this._getImagePath(),
+ type: 'styleLogo',
};
},
_success: function(uploadID, data) {
if (data.returnValues.url) {
// show image
- this._image.attr('src', data.returnValues.url + '?timestamp=' + Date.now());
this._pageLogo.val(data.returnValues.url);
+ this._updateLogo();
// hide error
this._button.next('.innerError').remove();
*/
_tmpHash: '',
- /**
- * absolute path to WCF directory
- * @var string
- */
- _wcfPath: '',
-
/**
* @see WCF.Upload.init()
*/
- init: function(tmpHash, wcfPath) {
+ init: function(tmpHash) {
this._tmpHash = tmpHash;
- this._wcfPath = wcfPath;
this._button = $('#uploadLogoMobile');
this._image = $('#styleLogoMobile');
this._imagePath = $('#imagePath');
this._pageLogo = $('#pageLogoMobile');
- this._super(this._button, undefined, 'wcf\\data\\style\\StyleAction', { action: 'uploadLogoMobile' });
+ this._super(this._button, undefined, 'wcf\\data\\style\\StyleAction', { action: 'uploadLogo' });
if (!this._image.attr('src').length) {
this._updateLogo();
var $src = this._pageLogo.val();
if ($src.length) {
if (!$src.match(/^https?:\/\//)) {
- var $path = this._imagePath.val();
- if (!$path) {
- $path = 'images/';
- }
+ var $path = this._getImagePath();
- $path = this._wcfPath + $path.replace(/^\/?images\/?/, '');
+ $path = WCF_PATH + $path;
if ($path.substr(-1) !== '/') {
$path += '/';
}
this._image.attr('src', $src + '?timestamp=' + Date.now());
},
+ /**
+ * Returns the style's image path.
+ */
+ _getImagePath: function () {
+ return this._imagePath.val() || 'images/';
+ },
+
/**
* @see WCF.Upload._initFile()
*/
*/
_getParameters: function() {
return {
- tmpHash: this._tmpHash
+ tmpHash: this._tmpHash,
+ imagePath: this._getImagePath(),
+ type: 'styleLogo-mobile',
};
},
_success: function(uploadID, data) {
if (data.returnValues.url) {
// show image
- this._image.attr('src', data.returnValues.url + '?timestamp=' + Date.now());
this._pageLogo.val(data.returnValues.url);
+ this._updateLogo();
// hide error
this._button.next('.innerError').remove();
$file = $files[0];
try {
+ $relativePath = FileUtil::unifyDirSeparator(FileUtil::getRelativePath(WCF_DIR.'images/', WCF_DIR.$this->parameters['imagePath']));
+ if (strpos($relativePath, '../') !== false) {
+ throw new UserInputException('imagePath', 'invalid');
+ }
+
+ if ($this->parameters['type'] !== 'styleLogo' && $this->parameters['type'] !== 'styleLogo-mobile') {
+ throw new UserInputException('type', 'invalid');
+ }
+
if (!$file->getValidationErrorType()) {
// shrink avatar if necessary
$fileLocation = $file->getLocation();
+ $basename = $this->parameters['type'].'-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension();;
+ $target = WCF_DIR.$this->parameters['imagePath'].'/'.$basename;
+
// move uploaded file
- if (@copy($fileLocation, WCF_DIR.'images/styleLogo-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension())) {
+ if (@copy($fileLocation, $target)) {
@unlink($fileLocation);
- // store extension within session variables
- WCF::getSession()->register('styleLogo-'.$this->parameters['tmpHash'], $file->getFileExtension());
-
// get logo size
- list($width, $height) = getimagesize(WCF_DIR.'images/styleLogo-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension());
+ list($width, $height) = getimagesize($target);
// return result
return [
- 'url' => WCF::getPath().'images/styleLogo-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension(),
+ 'url' => $basename,
'width' => $width,
'height' => $height
];
return ['errorType' => $file->getValidationErrorType()];
}
- /**
- * Validates parameters to update a mobile logo.
- */
- public function validateUploadLogoMobile() {
- $this->validateUpload();
- }
-
- /**
- * Handles mobile logo upload.
- *
- * @return string[]
- */
- public function uploadLogoMobile() {
- // save files
- /** @noinspection PhpUndefinedMethodInspection */
- /** @var UploadFile[] $files */
- $files = $this->parameters['__files']->getFiles();
- $file = $files[0];
-
- try {
- if (!$file->getValidationErrorType()) {
- // shrink avatar if necessary
- $fileLocation = $file->getLocation();
-
- // move uploaded file
- if (@copy($fileLocation, WCF_DIR.'images/styleLogo-mobile-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension())) {
- @unlink($fileLocation);
-
- // store extension within session variables
- WCF::getSession()->register('styleLogo-mobile-'.$this->parameters['tmpHash'], $file->getFileExtension());
-
- // return result
- return [
- 'url' => WCF::getPath().'images/styleLogo-mobile-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension()
- ];
- }
- else {
- throw new UserInputException('image', 'uploadFailed');
- }
- }
- }
- catch (UserInputException $e) {
- $file->setValidationErrorType($e->getType());
- }
-
- return ['errorType' => $file->getValidationErrorType()];
- }
-
/**
* Validates parameters to upload a favicon.
*