}
});
+/**
+ * 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: '',
+
+ /**
+ * absolute path to WCF directory
+ * @var string
+ */
+ _wcfPath: '',
+
+ /**
+ * @see WCF.Upload.init()
+ */
+ init: function(tmpHash, wcfPath) {
+ this._tmpHash = tmpHash;
+ this._wcfPath = wcfPath;
+
+ 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._pageLogo.val();
+ if (!$path) {
+ $path = 'images/';
+ }
+
+ $path = this._wcfPath + $path;
+ }
+ }
+ else {
+ // no logo defined, fallback to application logo
+ $src = $('#logo > a > img').prop('src');
+ }
+
+ this._image.attr('src', $src);
+ },
+
+ /**
+ * @see WCF.Upload._initFile()
+ */
+ _initFile: function(file) {
+ return this._image;
+ },
+
+ /**
+ * @see WCF.Upload._getParameters()
+ */
+ _getParameters: function() {
+ return {
+ tmpHash: this._tmpHash
+ };
+ },
+
+ /**
+ * @see WCF.Upload._success()
+ */
+ _success: function(uploadID, data) {
+ if (data.returnValues.url) {
+ // show image
+ this._image.attr('src', data.returnValues.url);
+ this._pageLogo.val(data.returnValues.url);
+
+ // 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 = $('<small class="innerError" />').insertAfter(this._button);
+ }
+
+ return $span;
+ }
+});
+
/**
* Handles style list management buttons.
*/
'wcf.style.colorPicker.button.apply': '{lang}wcf.style.colorPicker.button.apply{/lang}'
});
new WCF.ACP.Style.ImageUpload({if $action == 'add'}0{else}{@$style->styleID}{/if}, '{$tmpHash}');
+ new WCF.ACP.Style.LogoUpload('{$tmpHash}', '{@$__wcf->getPath()}images/');
{if $action == 'edit'}
new WCF.ACP.Style.CopyStyle({@$style->styleID});
<dl>
<dt><label for="pageLogo">{lang}wcf.acp.style.globals.pageLogo{/lang}</label></dt>
+ <dd class="framed">
+ <img src="" alt="" id="styleLogo" />
+ <div id="uploadLogo"></div>
+ {if $errorField == 'image'}
+ <small class="innerError">
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {else}
+ {lang}wcf.acp.style.image.error.{$errorType}{/lang}
+ {/if}
+ </small>
+ {/if}
+ <small>{lang}wcf.acp.style.image.description{/lang}</small>
+ </dd>
<dd>
<input type="text" name="pageLogo" id="pageLogo" value="{$variables[pageLogo]}" class="long" />
<small>{lang}wcf.acp.style.globals.pageLogo.description{/lang}</small>
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$requireACP
*/
- protected $requireACP = array('copy', 'delete', 'setAsDefault', 'toggle', 'update', 'upload');
+ protected $requireACP = array('copy', 'delete', 'setAsDefault', 'toggle', 'update', 'upload', 'uploadLogo');
/**
* style object
try {
if (!$file->getValidationErrorType()) {
- // shrink avatar if necessary
+ // shrink preview image if necessary
$fileLocation = $file->getLocation();
$imageData = getimagesize($fileLocation);
if ($imageData[0] > Style::PREVIEW_IMAGE_MAX_WIDTH || $imageData[1] > Style::PREVIEW_IMAGE_MAX_HEIGHT) {
return array('errorType' => $file->getValidationErrorType());
}
+ /**
+ * Validates parameters to update a logo.
+ */
+ public function validateUploadLogo() {
+ $this->validateUpload();
+ }
+
+ /**
+ * Handles logo upload.
+ *
+ * @return array<string>
+ */
+ public function uploadLogo() {
+ // save 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-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension())) {
+ @unlink($fileLocation);
+
+ // store extension within session variables
+ WCF::getSession()->register('styleLogo-'.$this->parameters['tmpHash'], $file->getFileExtension());
+
+ // return result
+ return array(
+ 'url' => WCF::getPath().'images/styleLogo-'.$this->parameters['tmpHash'].'.'.$file->getFileExtension()
+ );
+ }
+ else {
+ throw new UserInputException('image', 'uploadFailed');
+ }
+ }
+ }
+ catch (UserInputException $e) {
+ $file->setValidationErrorType($e->getType());
+ }
+
+ return array('errorType' => $file->getValidationErrorType());
+ }
+
/**
* Validates parameters to assign a new default style.
*/