From 03ff1862c181abf8a24c9596183c18bc4285ceaf Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 26 Jul 2018 14:58:44 +0900 Subject: [PATCH] Various QQ File uploaders updates --- www/admin/qq_file_upload_ajax.php | 11 +- www/admin/qq_file_upload_front.php | 229 +++++++++++------- www/admin/various_class_test.php | 5 + www/layout/admin/default/javascript/edit.js | 11 + .../javascript/file-uploader/fileuploader.js | 39 ++- www/lib/CoreLibs/Upload/qqFileUploader.inc | 4 +- 6 files changed, 207 insertions(+), 92 deletions(-) diff --git a/www/admin/qq_file_upload_ajax.php b/www/admin/qq_file_upload_ajax.php index 29d950d4..efdfad02 100755 --- a/www/admin/qq_file_upload_ajax.php +++ b/www/admin/qq_file_upload_ajax.php @@ -8,18 +8,20 @@ $PRINT_ALL = 1; require 'config.inc'; // class load $base = new CoreLibs\Basic(); +$base->debug('AJAX UPLOAD', 'START Backend'); // set max upload size $MAX_UPLOAD_SIZE = $base->StringByteFormat(ini_get('upload_max_filesize')); // test for qqFileUploader (AJAX side) -$allowedExtensions = array ('csv', 'zip', 'jpg', 'pdf'); +$allowedExtensions = array ('csv', 'zip', 'jpg', 'pdf', 'bz2'); $sizeLimit = $MAX_UPLOAD_SIZE; // as set in php ini $base->debug('AJAX UPLOAD', 'Size: '.$sizeLimit.', Memory Limit: '.ini_get('memory_limit')); $uploader = new CoreLibs\Upload\qqFileUploader($allowedExtensions, $sizeLimit); // either in post or get $_action= $_POST['action'] ? $_POST['action'] : $_GET['action']; $_task_uid = $_POST['task_uid'] ? $_POST['task_uid'] : $_GET['task_uid']; -$base->debug('AJAX UPLOAD', 'Action: '.$_action.', Task UID: '.$_task_uid); +$get_post['start'] = microtime(true); +$base->debug('AJAX UPLOAD', 'Action: '.$_action.', Task UID: '.$_task_uid.' => '.$base->dateStringFormat($get_post['start'])); $upload_path = ROOT.MEDIA.UPLOADS; $get_post['result'] = $uploader->handleUpload($upload_path, false); @@ -30,10 +32,13 @@ $get_post['filename'] = $uploader->uploadFileName; $get_post['type'] = $uploader->uploadFileExt; $get_post['filesize'] = filesize($uploader->uploadFileName); $get_post['filesize_formated'] = $base->ByteStringFormat($get_post['filesize']); +$get_post['end'] = microtime(true); +$get_post['time'] = $get_post['end'] - $get_post['start']; +$base->debug('AJAX RESULT', $base->printAr($get_post)); // return data $output = htmlspecialchars(json_encode($get_post), ENT_NOQUOTES); -$base->debug('AJAX USAGE', $output); +// $base->debug('AJAX JSON', $output); print $output; $base->printErrorMsg(); diff --git a/www/admin/qq_file_upload_front.php b/www/admin/qq_file_upload_front.php index 41a06547..6d7019a9 100755 --- a/www/admin/qq_file_upload_front.php +++ b/www/admin/qq_file_upload_front.php @@ -17,6 +17,7 @@ $base->debug('UPLOADED FRONT', 'With max size: '.$MAX_UPLOAD_SIZE); File upload AJAX +
-
File upload via AJAX
+
File upload via AJAX (MAX SIZE: byteStringFormat($MAX_UPLOAD_SIZE);?>)
-
Upload File
-
+
Upload File
+
+
X
+
+
+
+
+
0%
+
+
-
Upload File
-
+
Upload File
+
+
X
+
+
+
+
+
0%
+
+
diff --git a/www/admin/various_class_test.php b/www/admin/various_class_test.php index fd9cebba..078d4de1 100755 --- a/www/admin/various_class_test.php +++ b/www/admin/various_class_test.php @@ -10,6 +10,8 @@ require 'config.inc' ; DEFINE('SET_SESSION_NAME', EDIT_SESSION_NAME); $base = new CoreLibs\Basic(); +print "THIS HOST: ".HOST_NAME.", with PROTOCOL: ".HOST_PROTOCOL." is running SSL: ".HOST_SSL."
"; + // $test = array ( // 'A' => array ( // 'B' => array (), @@ -31,6 +33,9 @@ $base->debug('ARRAY', $base->printAr($test)); function rec($pre, $cur, $node = array ()) { + if (!is_array($node)) { + $node = array (); + } print "
#### PRE: ".$pre.", CUR: ".$cur.", N-c: ".count($node)." [".join('|', array_keys($node))."]
"; if (!$pre) { print "** NEW
"; diff --git a/www/layout/admin/default/javascript/edit.js b/www/layout/admin/default/javascript/edit.js index 2313caff..1a17c16e 100644 --- a/www/layout/admin/default/javascript/edit.js +++ b/www/layout/admin/default/javascript/edit.js @@ -301,6 +301,17 @@ function acssel(element, css) } } +// METHOD: scssel +// PARAMS: element, style to remove, style to add +// RETURN: "none", in place add because of reference +// DESC : removes one css and adds another +// is a wrapper around rcssel/acssel +function scssel(element, rcss, acss) +{ + rcssel(element, rcss); + acssel(element, acss); +} + // METHOD: phfo [produce html from object] // PARAMS: object tree with dom element declarations // RETURN: HTML string that can be used as innerHTML diff --git a/www/layout/admin/default/javascript/file-uploader/fileuploader.js b/www/layout/admin/default/javascript/file-uploader/fileuploader.js index 6cd1ea50..552b6eb6 100644 --- a/www/layout/admin/default/javascript/file-uploader/fileuploader.js +++ b/www/layout/admin/default/javascript/file-uploader/fileuploader.js @@ -275,6 +275,9 @@ qq.FileUploaderBasic = function(o){ emptyError: "{file} is empty, please select files again without it.", onLeave: "The files are being uploaded, if you leave now the upload will be cancelled." }, + classes: { + cancel: 'qq-upload-cancel' + }, showMessage: function(message){ alert(message); } @@ -290,6 +293,8 @@ qq.FileUploaderBasic = function(o){ } this._preventLeaveInProgress(); + this._classes = this._options.classes; + this._bindCancelEvent(); }; qq.FileUploaderBasic.prototype = { @@ -364,6 +369,8 @@ qq.FileUploaderBasic.prototype = { }, _onSubmit: function(id, fileName){ this._filesInProgress++; + // get current upload id for cancel + this.qqFileId = id; }, _onProgress: function(id, fileName, loaded, total){ }, @@ -374,6 +381,7 @@ qq.FileUploaderBasic.prototype = { } }, _onCancel: function(id, fileName){ + // console.log('CORE CANCEL: %s', id); this._filesInProgress--; }, _onInputChange: function(input){ @@ -401,6 +409,7 @@ qq.FileUploaderBasic.prototype = { var id = this._handler.add(fileContainer); var fileName = this._handler.getName(id); + // console.log('UPLOAD FILE: %s, FN: %s', id, fileName); if (this._options.button) { if (this._options.onSubmit(id, fileName, this._options.button.id) !== false){ @@ -485,6 +494,24 @@ qq.FileUploaderBasic.prototype = { } while (bytes > 99); return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i]; + }, + /** + * delegate click event for cancel link + **/ + _bindCancelEvent: function(){ + var self = this, + list = this._options.cancel; + qq.attach(list, 'click', function(e){ + e = e || window.event; + var target = e.target || e.srcElement; + + if (qq.hasClass(target, self._classes.cancel)){ + qq.preventDefault(e); + console.log('Item: %s', self.qqFileId); + self._handler.cancel(self.qqFileId); + console.log('## IN PROGRESS: %s', self.getInProgress()); + } + }); } }; @@ -895,7 +922,9 @@ qq.UploadHandlerAbstract.prototype = { * Adds file or file input to the queue * @returns id **/ - add: function(file){}, + add: function(file){ + console.log('FILE: %s', file); + }, /** * Sends the file identified by id and additional query params to the server */ @@ -915,6 +944,7 @@ qq.UploadHandlerAbstract.prototype = { * Cancels file upload by id */ cancel: function(id){ + // console.log('CANCEL: %s', id); this._cancel(id); this._dequeue(id); }, @@ -955,10 +985,11 @@ qq.UploadHandlerAbstract.prototype = { */ _dequeue: function(id){ var i = qq.indexOf(this._queue, id); + // console.log('==> Dequeue: %s with %s', id, i); this._queue.splice(i, 1); var max = this._options.maxConnections; - + // console.log('==> Dequeue next: %s, max: %s', this._queue.length, max); if (this._queue.length >= max && i < max){ var nextId = this._queue[max-1]; this._upload(nextId, this._params[nextId]); @@ -998,7 +1029,6 @@ qq.extend(qq.UploadHandlerForm.prototype, { }, _cancel: function(id){ this._options.onCancel(id, this.getName(id)); - delete this._inputs[id]; var iframe = document.getElementById(id); @@ -1013,7 +1043,7 @@ qq.extend(qq.UploadHandlerForm.prototype, { }, _upload: function(id, params){ var input = this._inputs[id]; -// console.log('IFRAME upload: %s', id); + // console.log('IFRAME upload: %s', id); if (!input){ throw new Error('file with passed id was not added, or already uploaded or cancelled'); @@ -1270,6 +1300,7 @@ qq.extend(qq.UploadHandlerXhr.prototype, { this._dequeue(id); }, _cancel: function(id){ + // console.log('CANCEL EXT: %s', id); this._options.onCancel(id, this.getName(id)); this._files[id] = null; diff --git a/www/lib/CoreLibs/Upload/qqFileUploader.inc b/www/lib/CoreLibs/Upload/qqFileUploader.inc index d926119e..627286da 100755 --- a/www/lib/CoreLibs/Upload/qqFileUploader.inc +++ b/www/lib/CoreLibs/Upload/qqFileUploader.inc @@ -101,9 +101,9 @@ class qqFileUploader $this->uploadFileExt = $ext; if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) { - return array('success'=>true); + return array('success' => true); } else { - return array('error'=> 'Could not save uploaded file.' . + return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered'); } }