From: Tim Düsterhus Date: Tue, 21 Jul 2020 10:17:11 +0000 (+0200) Subject: Remove legacy style logo uploader X-Git-Tag: 5.3.0_Alpha_1~100^2~24 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c0300310438879986cbf0103aa7850854c829f93;p=GitHub%2FWoltLab%2FWCF.git Remove legacy style logo uploader --- diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.Style.js b/wcfsetup/install/files/acp/js/WCF.ACP.Style.js index e58d41b082..32d3856d91 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.Style.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.Style.js @@ -162,297 +162,6 @@ WCF.ACP.Style.ImageUpload = WCF.Upload.extend({ } }); -/** - * Handles the logo upload. - * - * @param string tmpHash - */ -WCF.ACP.Style.LogoUpload = WCF.Upload.extend({ - /** - * upload button - * @var jQuery - */ - _button: null, - - /** - * image path - * @var jQuery - */ - _imagePath: null, - - /** - * logo - * @var jQuery - */ - _logo: null, - - /** - * page logo input field - * @var jQuery - */ - _pageLogo: null, - - /** - * tmp hash - * @var string - */ - _tmpHash: '', - - /** - * @see WCF.Upload.init() - */ - init: function(tmpHash) { - this._tmpHash = tmpHash; - - this._button = $('#uploadLogo'); - this._image = $('#styleLogo'); - this._imagePath = $('#imagePath'); - this._pageLogo = $('#pageLogo'); - - this._super(this._button, undefined, 'wcf\\data\\style\\StyleAction', { action: 'uploadLogo' }); - - if (!this._image.attr('src').length) { - this._updateLogo(); - } - - this._pageLogo.blur($.proxy(this._updateLogo, this)); - }, - - /** - * Updates the logo preview. - */ - _updateLogo: function() { - var $src = this._pageLogo.val(); - if ($src.length) { - if (!$src.match(/^https?:\/\//)) { - var $path = this._getImagePath(); - - $path = WCF_PATH + $path; - if ($path.substr(-1) !== '/') { - $path += '/'; - } - - $src = $path + $src; - } - } - else { - // no logo defined, fallback to application logo - $src = WCF_PATH + 'images/default-logo.png'; - $('#pageLogoWidth').val(281); - $('#pageLogoHeight').val(40); - } - - 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() - */ - _initFile: function(file) { - return this._image; - }, - - /** - * @see WCF.Upload._getParameters() - */ - _getParameters: function() { - return { - tmpHash: this._tmpHash, - imagePath: this._getImagePath(), - type: 'styleLogo', - }; - }, - - /** - * @see WCF.Upload._success() - */ - _success: function(uploadID, data) { - if (data.returnValues.url) { - // show image - this._pageLogo.val(data.returnValues.url); - this._updateLogo(); - - // hide error - this._button.next('.innerError').remove(); - - $('#pageLogoWidth').val(data.returnValues.width); - $('#pageLogoHeight').val(data.returnValues.height); - - // show success message - var $notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success')); - $notification.show(); - } - else if (data.returnValues.errorType) { - // show error - this._getInnerErrorElement().text(WCF.Language.get('wcf.acp.style.image.error.' + data.returnValues.errorType)); - } - }, - - /** - * Returns error display element. - * - * @return jQuery - */ - _getInnerErrorElement: function() { - var $span = this._button.next('.innerError'); - if (!$span.length) { - $span = $('').insertAfter(this._button); - } - - return $span; - } -}); - -/** - * Handles the mobile logo upload. - * - * @param string tmpHash - */ -WCF.ACP.Style.LogoUploadMobile = WCF.Upload.extend({ - /** - * upload button - * @var jQuery - */ - _button: null, - - /** - * image path - * @var jQuery - */ - _imagePath: null, - - /** - * logo - * @var jQuery - */ - _logo: null, - - /** - * page logo input field - * @var jQuery - */ - _pageLogo: null, - - /** - * tmp hash - * @var string - */ - _tmpHash: '', - - /** - * @see WCF.Upload.init() - */ - init: function(tmpHash) { - this._tmpHash = tmpHash; - - this._button = $('#uploadLogoMobile'); - this._image = $('#styleLogoMobile'); - this._imagePath = $('#imagePath'); - this._pageLogo = $('#pageLogoMobile'); - - this._super(this._button, undefined, 'wcf\\data\\style\\StyleAction', { action: 'uploadLogo' }); - - if (!this._image.attr('src').length) { - this._updateLogo(); - } - - this._pageLogo.blur($.proxy(this._updateLogo, this)); - }, - - /** - * Updates the logo preview. - */ - _updateLogo: function() { - var $src = this._pageLogo.val(); - if ($src.length) { - if (!$src.match(/^https?:\/\//)) { - var $path = this._getImagePath(); - - $path = WCF_PATH + $path; - if ($path.substr(-1) !== '/') { - $path += '/'; - } - - $src = $path + $src; - } - } - else { - // no logo defined, fallback to application logo - $src = WCF_PATH + 'images/default-logo-small.png'; - } - - 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() - */ - _initFile: function(file) { - return this._image; - }, - - /** - * @see WCF.Upload._getParameters() - */ - _getParameters: function() { - return { - tmpHash: this._tmpHash, - imagePath: this._getImagePath(), - type: 'styleLogo-mobile', - }; - }, - - /** - * @see WCF.Upload._success() - */ - _success: function(uploadID, data) { - if (data.returnValues.url) { - // show image - this._pageLogo.val(data.returnValues.url); - this._updateLogo(); - - // hide error - this._button.next('.innerError').remove(); - - // show success message - var $notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success')); - $notification.show(); - } - else if (data.returnValues.errorType) { - // show error - this._getInnerErrorElement().text(WCF.Language.get('wcf.acp.style.image.error.' + data.returnValues.errorType)); - } - }, - - /** - * Returns error display element. - * - * @return jQuery - */ - _getInnerErrorElement: function() { - var $span = this._button.next('.innerError'); - if (!$span.length) { - $span = $('').insertAfter(this._button); - } - - return $span; - } -}); - /** * Handles style list management buttons. */ diff --git a/wcfsetup/install/files/lib/data/style/StyleAction.class.php b/wcfsetup/install/files/lib/data/style/StyleAction.class.php index b8a0fb9242..bfbb9159ce 100644 --- a/wcfsetup/install/files/lib/data/style/StyleAction.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleAction.class.php @@ -59,7 +59,7 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction /** * @inheritDoc */ - protected $requireACP = ['copy', 'delete', 'deleteCoverPhoto', 'markAsTainted', 'setAsDefault', 'toggle', 'update', 'upload', 'uploadCoverPhoto', 'uploadLogo', 'uploadLogoMobile']; + protected $requireACP = ['copy', 'delete', 'deleteCoverPhoto', 'markAsTainted', 'setAsDefault', 'toggle', 'update', 'upload', 'uploadCoverPhoto',]; /** * style object @@ -427,68 +427,6 @@ BROWSERCONFIG; $uploadHandler->validateFiles(new DefaultUploadFileValidationStrategy(PHP_INT_MAX, ['jpg', 'jpeg', 'png', 'gif', 'svg'])); } - /** - * Validates parameters to update a logo. - */ - public function validateUploadLogo() { - $this->validateUpload(); - } - - /** - * Handles logo upload. - * - * @return string[] - */ - public function uploadLogo() { - // save files - /** @noinspection PhpUndefinedMethodInspection */ - /** @var UploadFile[] $files */ - $files = $this->parameters['__files']->getFiles(); - $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, $target)) { - @unlink($fileLocation); - - // get logo size - list($width, $height) = getimagesize($target); - - // return result - return [ - 'url' => $basename, - 'width' => $width, - 'height' => $height - ]; - } - else { - throw new UserInputException('image', 'uploadFailed'); - } - } - } - catch (UserInputException $e) { - $file->setValidationErrorType($e->getType()); - } - - return ['errorType' => $file->getValidationErrorType()]; - } - /** * Validates parameters to upload a favicon. *