From: Matthias Schmidt Date: Wed, 2 Apr 2014 18:09:09 +0000 (+0200) Subject: Add possibility to upload smiley file when adding new smiley X-Git-Tag: 2.1.0_Alpha_1~919 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2935bc94e42f35c07b98f20defff22658d5d7039;p=GitHub%2FWoltLab%2FWCF.git Add possibility to upload smiley file when adding new smiley --- diff --git a/wcfsetup/install/files/acp/templates/smileyAdd.tpl b/wcfsetup/install/files/acp/templates/smileyAdd.tpl index ca3da52980..114414c00c 100644 --- a/wcfsetup/install/files/acp/templates/smileyAdd.tpl +++ b/wcfsetup/install/files/acp/templates/smileyAdd.tpl @@ -23,7 +23,7 @@ {/hascontent} -
+
{lang}wcf.global.form.data{/lang} @@ -96,38 +96,66 @@ - -
+ +
- + - {if $errorField == 'smileyPath'} + {if $errorField == 'showOrder'} + + {lang}wcf.acp.smiley.showOrder.error.{@$errorType}{/lang} + + {/if} +
+ + + {event name='dataFields'} +
+ +
+ {lang}wcf.acp.smiley.smileyFile{/lang} + + +
+
+ {if $uploadedFilename} + + + {/if} + + + {if $errorField == 'fileUpload'} {if $errorType == 'empty'} {lang}wcf.global.form.error.empty{/lang} {else} - {lang}wcf.acp.smiley.smileyPath.error.{@$errorType}{/lang} + {lang}wcf.acp.smiley.fileUpload.error.{@$errorType}{/lang} {/if} {/if} - {lang}wcf.acp.smiley.smileyPath.description{/lang} + {lang}wcf.acp.smiley.fileUpload.description{/lang}
- -
+ +
- + - {if $errorField == 'showOrder'} + {if $errorField == 'smileyPath'} - {lang}wcf.acp.smiley.showOrder.error.{@$errorType}{/lang} + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.smiley.smileyPath.error.{@$errorType}{/lang} + {/if} {/if} + {lang}wcf.acp.smiley.smileyPath.description{/lang}
- {event name='dataFields'} + {event name='smileyFileFields'}
{event name='fieldsets'} diff --git a/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php index 50a55d1388..df08f3d6ba 100644 --- a/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php @@ -80,6 +80,18 @@ class SmileyAddForm extends AbstractForm { */ public $categoryNodeTree = null; + /** + * data of the uploaded smiley file + * @var array() + */ + public $fileUpload = array(); + + /** + * temporary name of the uploaded smiley file + * @var string + */ + public $uploadedFilename = ''; + /** * @see \wcf\page\IPage::assignVariables() */ @@ -96,7 +108,8 @@ class SmileyAddForm extends AbstractForm { 'smileyCode' => $this->smileyCode, 'aliases' => $this->aliases, 'smileyPath' => $this->smileyPath, - 'categoryNodeList' => $this->categoryNodeTree->getIterator() + 'categoryNodeList' => $this->categoryNodeTree->getIterator(), + 'uploadedFilename' => $this->uploadedFilename )); } @@ -133,6 +146,8 @@ class SmileyAddForm extends AbstractForm { if (isset($_POST['smileyCode'])) $this->smileyCode = StringUtil::trim($_POST['smileyCode']); if (isset($_POST['aliases'])) $this->aliases = StringUtil::unifyNewlines(StringUtil::trim($_POST['aliases'])); if (isset($_POST['smileyPath'])) $this->smileyPath = FileUtil::removeLeadingSlash(StringUtil::trim($_POST['smileyPath'])); + if (isset($_POST['uploadedFilename'])) $this->uploadedFilename = StringUtil::trim($_POST['uploadedFilename']); + if (isset($_FILES['fileUpload'])) $this->fileUpload = $_FILES['fileUpload']; } /** @@ -150,7 +165,8 @@ class SmileyAddForm extends AbstractForm { 'showOrder' => $this->showOrder, 'categoryID' => $this->categoryID ?: null, 'packageID' => 1 - )) + )), + 'fileLocation' => $this->uploadedFilename ? WCF_DIR.'images/smilies/tmp/'.$this->uploadedFilename : '' )); $this->objectAction->executeAction(); $returnValues = $this->objectAction->getReturnValues(); @@ -172,6 +188,7 @@ class SmileyAddForm extends AbstractForm { $this->showOrder = 0; $this->smileyPath = ''; $this->aliases = ''; + $this->uploadedFilename = ''; I18nHandler::getInstance()->reset(); @@ -187,6 +204,35 @@ class SmileyAddForm extends AbstractForm { public function validate() { parent::validate(); + if ($this->uploadedFilename) { + if (!file_exists(WCF_DIR.'images/smilies/tmp/'.$this->uploadedFilename)) { + throw new UserInputException('fileUpload', 'uploadFailed'); + } + } + else if (!empty($this->fileUpload['name'])) { + if (!getimagesize($this->fileUpload['tmp_name'])) { + throw new UserInputException('fileUpload', 'noImage'); + } + + do { + $this->uploadedFilename = StringUtil::getRandomID().'.'.mb_strtolower(mb_substr($this->fileUpload['name'], mb_strrpos($this->fileUpload['name'], '.') + 1)); + } + while (file_exists(WCF_DIR.'images/smilies/tmp/'.$this->uploadedFilename)); + + if (!@move_uploaded_file($this->fileUpload['tmp_name'], WCF_DIR.'images/smilies/tmp/'.$this->uploadedFilename)) { + throw new UserInputException('fileUpload', 'uploadFailed'); + } + } + else { + if (empty($this->smileyPath)) { + throw new UserInputException('smileyPath'); + } + + if (!is_file(WCF_DIR.$this->smileyPath)) { + throw new UserInputException('smileyPath', 'notFound'); + } + } + // validate title if (!I18nHandler::getInstance()->validateValue('smileyTitle')) { if (I18nHandler::getInstance()->isPlainValue('smileyTitle')) { @@ -208,14 +254,6 @@ class SmileyAddForm extends AbstractForm { throw new UserInputException('smileyCode'); } - if (empty($this->smileyPath)) { - throw new UserInputException('smileyPath'); - } - - if (!is_file(WCF_DIR.$this->smileyPath)) { - throw new UserInputException('smileyPath', 'notFound'); - } - // validate smiley code and aliases against existing smilies $conditionBuilder = new PreparedStatementConditionBuilder(); if (isset($this->smiley)) { diff --git a/wcfsetup/install/files/lib/acp/form/SmileyEditForm.class.php b/wcfsetup/install/files/lib/acp/form/SmileyEditForm.class.php index 79e1e7c401..b1c5e4fab4 100644 --- a/wcfsetup/install/files/lib/acp/form/SmileyEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/SmileyEditForm.class.php @@ -69,16 +69,21 @@ class SmileyEditForm extends SmileyAddForm { } // update bbcode - $this->objectAction = new SmileyAction(array($this->smileyID), 'update', array('data' => array_merge($this->additionalFields, array( - 'smileyTitle' => $this->smileyTitle, - 'smileyCode' => $this->smileyCode, - 'aliases' => $this->aliases, - 'smileyPath' => $this->smileyPath, - 'showOrder' => $this->showOrder, - 'categoryID' => $this->categoryID ?: null - )))); + $this->objectAction = new SmileyAction(array($this->smileyID), 'update', array( + 'data' => array_merge($this->additionalFields, array( + 'smileyTitle' => $this->smileyTitle, + 'smileyCode' => $this->smileyCode, + 'aliases' => $this->aliases, + 'smileyPath' => $this->smileyPath, + 'showOrder' => $this->showOrder, + 'categoryID' => $this->categoryID ?: null + )), + 'fileLocation' => $this->uploadedFilename ? WCF_DIR.'images/smilies/tmp/'.$this->uploadedFilename : '' + )); $this->objectAction->executeAction(); + $this->uploadedFilename = ''; + $this->saved(); // show success diff --git a/wcfsetup/install/files/lib/data/smiley/SmileyAction.class.php b/wcfsetup/install/files/lib/data/smiley/SmileyAction.class.php index 8c9f002d8a..3fb1fb67f3 100644 --- a/wcfsetup/install/files/lib/data/smiley/SmileyAction.class.php +++ b/wcfsetup/install/files/lib/data/smiley/SmileyAction.class.php @@ -37,6 +37,46 @@ class SmileyAction extends AbstractDatabaseObjectAction implements ISortableActi */ protected $requireACP = array('delete', 'update', 'updatePosition'); + /** + * @see \wcf\data\AbstractDatabaseObjectAction::create() + */ + public function create() { + $smiley = parent::create(); + + if (!empty($this->parameters['fileLocation'])) { + $smileyFilename = 'smiley'.$smiley->smileyID.'.'.mb_strtolower(mb_substr($this->parameters['fileLocation'], mb_strrpos($this->parameters['fileLocation'], '.') + 1)); + @rename($this->parameters['fileLocation'], WCF_DIR.'images/smilies/'.$smileyFilename); + + $smileyEditor = new SmileyEditor($smiley); + $smileyEditor->update(array( + 'smileyPath' => 'images/smilies/'.$smileyFilename + )); + + $smiley = new Smiley($smiley->smileyID); + } + + return $smiley; + } + + /** + * @see \wcf\data\AbstractDatabaseObjectAction::update() + */ + public function update() { + if (empty($this->objects)) { + $this->readObjects(); + } + + if (count($this->objects) == 1 && !empty($this->parameters['fileLocation'])) { + $smiley = reset($this->objects); + $smileyFilename = 'smiley'.$smiley->smileyID.'.'.mb_strtolower(mb_substr($this->parameters['fileLocation'], mb_strrpos($this->parameters['fileLocation'], '.') + 1)); + @rename($this->parameters['fileLocation'], WCF_DIR.'images/smilies/'.$smileyFilename); + + $this->parameters['data']['smileyPath'] = 'images/smilies/'.$smileyFilename; + } + + parent::update(); + } + /** * @see \wcf\data\ISortableAction::validateUpdatePosition() */ @@ -68,7 +108,7 @@ class SmileyAction extends AbstractDatabaseObjectAction implements ISortableActi foreach ($this->parameters['data']['structure'][0] as $smileyID) { $smiley = $smileyList->search($smileyID); if ($smiley === null) continue; - + $editor = new SmileyEditor($smiley); $editor->update(array('showOrder' => $i++)); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 116b40d9d8..f84b410dd1 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1092,6 +1092,11 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> getPath()}“ interpretiert.]]> + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 2f19456d8d..f52f3cc2b2 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1092,6 +1092,11 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> getPath()}”.]]> + + + + +