Skip to content

Commit

Permalink
Remove legacy style preview uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla committed Jul 21, 2020
1 parent 5c1f792 commit 40132f4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 140 deletions.
4 changes: 2 additions & 2 deletions wcfsetup/install/files/acp/templates/styleAdd.tpl
Expand Up @@ -6,10 +6,10 @@
{js application='wcf' file='WCF.ColorPicker' bundle='WCF.Combined'}
<script data-relocate="true">
require([
'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Delete', 'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Upload', 'WoltLabSuite/Core/Acp/Ui/Style/Favicon/Upload', 'WoltLabSuite/Core/Acp/Ui/Style/Image/Upload',
'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Delete', 'WoltLabSuite/Core/Acp/Ui/Style/CoverPhoto/Upload', 'WoltLabSuite/Core/Acp/Ui/Style/Favicon/Upload',
'WoltLabSuite/Core/Acp/Ui/Style/Editor', 'WoltLabSuite/Core/Ui/Toggle/Input', 'Language'
], function(
AcpUiStyleCoverPhotoDelete, AcpUiStyleCoverPhotoUpload, AcpUiStyleFaviconUpload, AcpUiStyleImageUpload,
AcpUiStyleCoverPhotoDelete, AcpUiStyleCoverPhotoUpload, AcpUiStyleFaviconUpload,
AcpUiStyleEditor, UiToggleInput, Language
) {
AcpUiStyleEditor.setup({
Expand Down

This file was deleted.

77 changes: 1 addition & 76 deletions wcfsetup/install/files/lib/data/style/StyleAction.class.php
Expand Up @@ -5,7 +5,6 @@
use wcf\data\user\UserAction;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\IToggleAction;
use wcf\data\IUploadAction;
use wcf\system\cache\builder\StyleCacheBuilder;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
Expand Down Expand Up @@ -34,7 +33,7 @@
* @method StyleEditor[] getObjects()
* @method StyleEditor getSingleObject()
*/
class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction, IUploadAction {
class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction {
use TDatabaseObjectToggle;

/**
Expand Down Expand Up @@ -428,80 +427,6 @@ public function validateUpload() {
$uploadHandler->validateFiles(new DefaultUploadFileValidationStrategy(PHP_INT_MAX, ['jpg', 'jpeg', 'png', 'gif', 'svg']));
}

/**
* @inheritDoc
*/
public function upload() {
// save files
/** @noinspection PhpUndefinedMethodInspection */
/** @var UploadFile[] $files */
$files = $this->parameters['__files']->getFiles();
$file = $files[0];

$multiplier = ($this->parameters['is2x']) ? 2 : 1;

try {
if (!$file->getValidationErrorType()) {
// shrink preview image if necessary
$fileLocation = $file->getLocation();
try {
if (($imageData = getimagesize($fileLocation)) === false) {
throw new UserInputException('image');
}
switch ($imageData[2]) {
case IMAGETYPE_PNG:
case IMAGETYPE_JPEG:
case IMAGETYPE_GIF:
// fine
break;
default:
throw new UserInputException('image');
}

if ($imageData[0] > (Style::PREVIEW_IMAGE_MAX_WIDTH * $multiplier) || $imageData[1] > (Style::PREVIEW_IMAGE_MAX_HEIGHT * $multiplier)) {
$adapter = ImageHandler::getInstance()->getAdapter();
$adapter->loadFile($fileLocation);
$fileLocation = FileUtil::getTemporaryFilename();
$thumbnail = $adapter->createThumbnail(Style::PREVIEW_IMAGE_MAX_WIDTH * $multiplier, Style::PREVIEW_IMAGE_MAX_HEIGHT * $multiplier, false);
$adapter->writeImage($thumbnail, $fileLocation);
}
}
catch (SystemException $e) {
throw new UserInputException('image');
}

// move uploaded file
if (@copy($fileLocation, WCF_DIR.'images/stylePreview-'.$this->parameters['tmpHash'].($this->parameters['is2x'] ? '@2x' : '').'.'.$file->getFileExtension())) {
@unlink($fileLocation);

// store extension within session variables
WCF::getSession()->register('stylePreview-'.$this->parameters['tmpHash'].($this->parameters['is2x'] ? '@2x' : ''), $file->getFileExtension());

if ($this->parameters['styleID']) {
$this->updateStylePreviewImage($this->style);

return [
'url' => WCF::getPath().'images/stylePreview-'.$this->parameters['styleID'].($this->parameters['is2x'] ? '@2x' : '').'.'.$file->getFileExtension()
];
}

// return result
return [
'url' => WCF::getPath().'images/stylePreview-'.$this->parameters['tmpHash'].($this->parameters['is2x'] ? '@2x' : '').'.'.$file->getFileExtension()
];
}
else {
throw new UserInputException('image', 'uploadFailed');
}
}
}
catch (UserInputException $e) {
$file->setValidationErrorType($e->getType());
}

return ['errorType' => $file->getValidationErrorType()];
}

/**
* Validates parameters to update a logo.
*/
Expand Down

0 comments on commit 40132f4

Please sign in to comment.