{/hascontent}
</div>
-<form method="post" action="{if $action == 'add'}{link controller='SmileyAdd'}{/link}{else}{link controller='SmileyEdit' id=$smiley->smileyID}{/link}{/if}">
+<form method="post" action="{if $action == 'add'}{link controller='SmileyAdd'}{/link}{else}{link controller='SmileyEdit' id=$smiley->smileyID}{/link}{/if}" enctype="multipart/form-data">
<div class="container containerPadding marginTop">
<fieldset>
<legend>{lang}wcf.global.form.data{/lang}</legend>
</dd>
</dl>
- <dl{if $errorField == 'smileyPath'} class="formError"{/if}>
- <dt><label for="smileyPath">{lang}wcf.acp.smiley.smileyPath{/lang}</label></dt>
+ <dl{if $errorField == 'showOrder'} class="formError"{/if}>
+ <dt><label for="showOrder">{lang}wcf.acp.smiley.showOrder{/lang}</label></dt>
<dd>
- <input type="text" id="smileyPath" name="smileyPath" value="{$smileyPath}" required="required" class="long" />
+ <input type="number" id="showOrder" name="showOrder" value="{$showOrder}" min="0" class="short" />
- {if $errorField == 'smileyPath'}
+ {if $errorField == 'showOrder'}
+ <small class="innerError">
+ {lang}wcf.acp.smiley.showOrder.error.{@$errorType}{/lang}
+ </small>
+ {/if}
+ </dd>
+ </dl>
+
+ {event name='dataFields'}
+ </fieldset>
+
+ <fieldset>
+ <legend>{lang}wcf.acp.smiley.smileyFile{/lang}</legend>
+
+ <dl{if $errorField == 'fileUpload'} class="formError"{/if}>
+ <dt><label for="fileUpload">{lang}wcf.acp.smiley.fileUpload{/lang}</label></dt>
+ <dd>
+ {if $uploadedFilename}
+ <img src="{@$__wcf->getPath()}images/smilies/tmp/{$uploadedFilename}" alt="" />
+ <input type="hidden" name="uploadedFilename" value="{$uploadedFilename}" />
+ {/if}
+ <input type="file" id="fileUpload" name="fileUpload" value="" />
+
+ {if $errorField == 'fileUpload'}
<small class="innerError">
{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}
</small>
{/if}
- <small>{lang}wcf.acp.smiley.smileyPath.description{/lang}</small>
+ <small>{lang}wcf.acp.smiley.fileUpload.description{/lang}</small>
</dd>
</dl>
- <dl{if $errorField == 'showOrder'} class="formError"{/if}>
- <dt><label for="showOrder">{lang}wcf.acp.smiley.showOrder{/lang}</label></dt>
+ <dl{if $errorField == 'smileyPath'} class="formError"{/if}>
+ <dt><label for="smileyPath">{lang}wcf.acp.smiley.smileyPath{/lang}</label></dt>
<dd>
- <input type="number" id="showOrder" name="showOrder" value="{$showOrder}" min="0" class="short" />
+ <input type="text" id="smileyPath" name="smileyPath" value="{$smileyPath}" required="required" class="long" />
- {if $errorField == 'showOrder'}
+ {if $errorField == 'smileyPath'}
<small class="innerError">
- {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}
</small>
{/if}
+ <small>{lang}wcf.acp.smiley.smileyPath.description{/lang}</small>
</dd>
</dl>
- {event name='dataFields'}
+ {event name='smileyFileFields'}
</fieldset>
{event name='fieldsets'}
*/
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()
*/
'smileyCode' => $this->smileyCode,
'aliases' => $this->aliases,
'smileyPath' => $this->smileyPath,
- 'categoryNodeList' => $this->categoryNodeTree->getIterator()
+ 'categoryNodeList' => $this->categoryNodeTree->getIterator(),
+ 'uploadedFilename' => $this->uploadedFilename
));
}
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'];
}
/**
'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();
$this->showOrder = 0;
$this->smileyPath = '';
$this->aliases = '';
+ $this->uploadedFilename = '';
I18nHandler::getInstance()->reset();
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')) {
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)) {
}
// 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
*/
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()
*/
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++));
}
<item name="wcf.acp.smiley.smileyPath.description"><![CDATA[Der Smiley-Pfad wird relativ zu „{$__wcf->getPath()}“ interpretiert.]]></item>
<item name="wcf.acp.smiley.smileyPath.error.notFound"><![CDATA[Es wurde keine Datei unter dem angegebenen Pfad gefunden]]></item>
<item name="wcf.acp.smiley.showOrder"><![CDATA[Position]]></item>
+ <item name="wcf.acp.smiley.smileyFile"><![CDATA[Smiley-Datei]]></item>
+ <item name="wcf.acp.smiley.fileUpload"><![CDATA[Smiley hochladen]]></item>
+ <item name="wcf.acp.smiley.fileUpload.description"><![CDATA[Laden Sie hier die Bilddatei des Smileys hoch.]]></item>
+ <item name="wcf.acp.smiley.fileUpload.error.noImage"><![CDATA[Bei der hochgeladenen Datei handelt es sich um keine Bilddatei.]]></item>
+ <item name="wcf.acp.smiley.fileUpload.error.uploadFailed"><![CDATA[Beim Hochladen der Datei ist ein unbekannter Fehler aufgetreten.]]></item>
</category>
<category name="wcf.acp.style">
<item name="wcf.acp.smiley.smileyPath.description"><![CDATA[Smiley path is relative to “{$__wcf->getPath()}”.]]></item>
<item name="wcf.acp.smiley.smileyPath.error.notFound"><![CDATA[Unable to find a file on given path]]></item>
<item name="wcf.acp.smiley.showOrder"><![CDATA[Show Order]]></item>
+ <item name="wcf.acp.smiley.smileyFile"><![CDATA[Smiley File]]></item>
+ <item name="wcf.acp.smiley.fileUpload"><![CDATA[Upload Smiley]]></item>
+ <item name="wcf.acp.smiley.fileUpload.description"><![CDATA[Upload the image file for the smiley.]]></item>
+ <item name="wcf.acp.smiley.fileUpload.error.noImage"><![CDATA[The uploaded file is no image file.]]></item>
+ <item name="wcf.acp.smiley.fileUpload.error.uploadFailed"><![CDATA[An unknown error occured during upload.]]></item>
</category>
<category name="wcf.acp.style">