From: Marcel Werk Date: Thu, 8 Mar 2012 21:24:55 +0000 (+0100) Subject: Improved attachment support (still work in progress) X-Git-Tag: 2.0.0_Beta_1~1246 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=32f6cd95178d47d8b105ded72ea434b36ebebd38;p=GitHub%2FWoltLab%2FWCF.git Improved attachment support (still work in progress) --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 6635565da4..5dd96f4ea7 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -4054,11 +4054,17 @@ WCF.Upload = Class.extend({ this._uploadMatrix[$uploadID] = []; for (var $i = 0; $i < $files.length; $i++) { - this._uploadMatrix[$uploadID].push(this._initFile($files[$i])); + var $li = this._initFile($files[$i]); + $li.data('filename', $files[$i].name); + this._uploadMatrix[$uploadID].push($li); $fd.append('__files[]', $files[$i]); } $fd.append('actionName', this._options.action); $fd.append('className', this._className); + var $additionalParameters = this._getParameters(); + for (var $name in $additionalParameters) { + $fd.append('parameters['+$name+']', $additionalParameters[$name]); + } $.ajax({ type: 'POST', @@ -4067,13 +4073,15 @@ WCF.Upload = Class.extend({ data: $fd, contentType: false, processData: false, - success: $.proxy(this._success, this), + success: function(data, textStatus, jqXHR) { + self._success($uploadID, data); + }, error: $.proxy(this._error, this), xhr: function() { var $xhr = $.ajaxSettings.xhr(); if ($xhr) { $xhr.upload.addEventListener('progress', function(event) { - self._progress(event, $uploadID); + self._progress($uploadID, event); }, false); } return $xhr; @@ -4085,8 +4093,8 @@ WCF.Upload = Class.extend({ /** * Callback for success event */ - _success: function(data, textStatus, jqXHR) { - console.debug(jqXHR.responseText); + _success: function(uploadID, data) { + console.debug(data); }, /** @@ -4099,7 +4107,7 @@ WCF.Upload = Class.extend({ /** * Callback for progress event */ - _progress: function(event, uploadID) { + _progress: function(uploadID, event) { var $percentComplete = Math.round(event.loaded * 100 / event.total); for (var $i = 0; $i < this._uploadMatrix[uploadID].length; $i++) { @@ -4107,6 +4115,12 @@ WCF.Upload = Class.extend({ } }, + /** + * Returns additional parameters. + */ + _getParameters: function() { + return {}; + }, _initFile: function(file) { var $li = $('
  • '+file.name+' ('+file.size+')
  • '); diff --git a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php index c5de8ae30f..9b727763ed 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php @@ -91,6 +91,8 @@ class GDImageAdapter implements IImageAdapter { */ public function createThumbnail($maxWidth, $maxHeight, $obtainDimensions = true) { $width = $height = $x = $y = 0; + $sourceWidth = $this->width; + $sourceHeight = $this->height; if ($obtainDimensions) { if ($maxWidth / $this->width < $maxHeight / $this->height) { @@ -106,20 +108,20 @@ class GDImageAdapter implements IImageAdapter { else { $width = $height = $maxWidth; - if ($width > $height) { - $x = ceil(($width - $height) / 2); - $width = $height; + if ($sourceWidth > $sourceHeight) { + $x = ceil(($sourceWidth - $sourceHeight) / 2); + $sourceWidth = $sourceHeight; } else { - $y = ceil(($height - $width) / 2); - $height = $width; + $y = ceil(($sourceHeight - $sourceWidth) / 2); + $sourceHeight = $sourceWidth; } } // resize image $image = imageCreateTrueColor($width, $height); imageAlphaBlending($image, false); - imageCopyResampled($image, $this->image, 0, 0, $x, $y, $width, $height, $this->width, $this->height); + imageCopyResampled($image, $this->image, 0, 0, $x, $y, $width, $height, $sourceWidth, $sourceHeight); imageSaveAlpha($image, true); return $image; diff --git a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php index 536268406e..6f949bd06f 100644 --- a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php +++ b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php @@ -71,7 +71,7 @@ class UploadFile { * @return string */ public function getFilename() { - return $this->name; + return $this->filename; } /** @@ -129,4 +129,18 @@ class UploadFile { public function getValidationErrorType() { return $this->validationErrorType; } + + public function getImageData() { + if (strpos($this->getMimeType(), 'image/') == 0) { + if (($imageData = @getImageSize($this->getLocation())) !== false) { + return array( + 'width' => $imageData[0], + 'height' => $imageData[1], + 'mimeType' => $imageData['mime'], + ); + } + } + + return null; + } }