Skip to content
Permalink
Browse files

Add total to fileInputOrder

fileInputOrder = order/total
  • Loading branch information...
bloatware committed Oct 8, 2019
1 parent 73a2eca commit 8ca39025019b56780eb2ca9992f17e02ae4ccab3
Showing with 34 additions and 41 deletions.
  1. +5 −3 textpattern/include/txp_file.php
  2. +0 −13 textpattern/lib/txplib_html.php
  3. +29 −25 textpattern/textpattern.js
@@ -923,15 +923,17 @@ function file_insert()
$newname = sanitizeForFile($name);
$newpath = build_file_path($file_base_path, $newname);
if (!$size || $file_max_upload_size < $size) {
$messages[] = array(gTxt('file_upload_failed')." $newname - ".upload_get_errormsg($chunked && !$size ? UPLOAD_ERR_PARTIAL : UPLOAD_ERR_FORM_SIZE), E_ERROR);
if ($error || !$size && $chunked) {
$messages[] = array(gTxt('file_upload_failed', array('{list}' => $newname))." - ".upload_get_errormsg($error ? $error : UPLOAD_ERR_PARTIAL), E_ERROR);
} elseif ($file_max_upload_size < $size) {
$messages[] = array(gTxt('file_upload_failed', array('{list}' => $newname))." - ".upload_get_errormsg(UPLOAD_ERR_FORM_SIZE), E_ERROR);
} elseif (!is_file($newpath) && !safe_count('txp_file', "filename = '".doSlash($newname)."'")) {
$hash = isset($titles[$i]) ? $i : md5($name);
$title = isset($titles[$hash]) ? $titles[$hash] : '';
$id = file_db_add($newname, $category, $permissions, $description, $size, $title);
if (!$id) {
$messages[] = array(gTxt('file_upload_failed').' (db_add)', E_ERROR);
$messages[] = array(gTxt('file_upload_failed', array('{list}' => $newname)).' (db_add)', E_ERROR);
} else {
$id = assert_int($id);
@@ -1384,18 +1384,6 @@ function pageby_form($event, $val, $step = null)
function upload_form($label, $pophelp = '', $step, $event, $id = '', $max_file_size = 1000000, $label_id = '', $class = '', $wraptag_val = array('div', 'div'), $extra = null, $accept = '')
{
extract(gpsa(array(
'page',
'sort',
'dir',
'crit',
'search_method',
)));
if (is_array($search_method)) {
$search_method = join(',', $search_method);
}
if (!$label_id) {
$label_id = $event.'-upload';
}
@@ -1421,7 +1409,6 @@ function upload_form($label, $pophelp = '', $step, $event, $id = '', $max_file_s
eInput($event).
sInput($step).
hInput('id', $id).
// hInput(compact('id', 'sort', 'dir', 'page', 'search_method','crit')).
tInput().
inputLabel(
$label_id,
@@ -1894,23 +1894,11 @@ jQuery.fn.txpFileupload = function (options) {
formData: null,
fileInput: null,
dropZone: null,
replaceFileInput: false,
replaceFileInput: false,/*
add: function (e, data) {
var file = data.files[0], uploadErrors = [];

if(file['size'] && file['size'] > maxFileSize) {
uploadErrors.push('Filesize is too big');
textpattern.Console.addMessage(['<strong>'+textpattern.encodeHTML(file['name'])+'</strong> - '+textpattern.gTxt('upload_err_form_size'), 1], 'uploadEnd');
}

if(!uploadErrors.length) {
form.uploadCount++;
data.submit();
}
},
/* done: function (e, data) {
console.log(data);
}, */
form.uploadCount++;
data.submit();
},*/
progressall: function (e, data) {
textpattern.Relay.callback('uploadProgress', data);
},
@@ -1923,16 +1911,30 @@ jQuery.fn.txpFileupload = function (options) {
}, options)).off('submit').submit(function (e) {
e.preventDefault();
form.uploadCount = 0;
form.fileupload('add', {
files: fileInput.prop('files')
});
fileInput.val('');
var files = [];

if (!form.uploadCount) {
for (let file of fileInput.prop('files')) {
if (file.size <= maxFileSize) {
form.uploadCount++;
file["order"] = form.uploadCount;
files.push(file);
} else {
textpattern.Console.addMessage(['<strong>'+textpattern.encodeHTML(file['name'])+'</strong> - '+textpattern.gTxt('upload_err_form_size'), 1], 'uploadEnd');
}
};

if (!files.length) {
textpattern.Console.announce('uploadEnd');
} else {
form.fileupload('add', {
files: files
});
}
fileInput.val('');
}).bind('fileuploadsubmit', function (e, data) {
data.formData = $.merge([{"name" : "fileInputOrder", "value" : form.uploadCount}], options.formData);
data.formData = $.merge([{
"name" : "fileInputOrder", "value" : data.files[0].order+"/"+form.uploadCount
}], options.formData);
$.merge(data.formData, form.serializeArray());

// Reduce maxChunkSize by extra data size (?)
@@ -1942,9 +1944,11 @@ jQuery.fn.txpFileupload = function (options) {
}).reduce(function(a, b) {return a + b + 2;}, 0)
: 256;

form.fileupload('option', 'maxChunkSize', maxChunkSize - 8*(res + 255));
var chunkSize = form.fileupload('option', 'maxChunkSize');
form.fileupload('option', 'maxChunkSize', Math.min(maxChunkSize - 8*(res + 255), chunkSize));
});
/* fileInput.on('change', function(e) {
/*
fileInput.on('change', function(e) {
var singleFileUploads = false;
$(this.files).each(function () {
@@ -1954,7 +1958,7 @@ jQuery.fn.txpFileupload = function (options) {
});
form.fileupload('option', 'singleFileUploads', singleFileUploads);
}) */
})*/
return this;
};

0 comments on commit 8ca3902

Please sign in to comment.
You can’t perform that action at this time.