Improved attachment support (still work in progress)
authorMarcel Werk <burntime@woltlab.com>
Thu, 8 Mar 2012 21:24:55 +0000 (22:24 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 8 Mar 2012 21:24:55 +0000 (22:24 +0100)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php
wcfsetup/install/files/lib/system/upload/UploadFile.class.php

index 6635565da47cc97117755aa17217880c54eb5e2b..5dd96f4ea7b86430cc4b47b72d3a58c7318d9269 100644 (file)
@@ -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 = $('<li>'+file.name+' ('+file.size+')<progress max="100"></progress></li>');
index c5de8ae30f7d6d705a45145b2569b5e4a69061ce..9b727763edbf6e4c386c6baafe6f0cc8beb01fcd 100644 (file)
@@ -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;
index 536268406e1af598c577d78104e7ad1e1be4f70d..6f949bd06fedac9d121e97d2f88ad4b7cd8d9c4d 100644 (file)
@@ -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;
+       }
 }