cambios adicionales

This commit is contained in:
2025-09-25 12:27:01 -04:00
parent 5ddc52658d
commit 104051ede0
2451 changed files with 447790 additions and 2 deletions

View File

@@ -0,0 +1,322 @@
jQuery Fancy File Uploader
==========================
A jQuery plugin to convert the HTML file input type into a mobile-friendly fancy file uploader. Choose from a MIT or LGPL license.
Also available in [FlexForms Modules](https://github.com/cubiclesoft/php-flexforms-modules).
![Screenshot](https://user-images.githubusercontent.com/1432111/28810269-b1571d10-763d-11e7-9ac5-6190b94d0f2d.png)
[Live demo via Admin Pack](https://barebonescms.com/demos/admin_pack/admin.php?action=addeditexample&sec_t=7a110e04a283159db5a4e282c76e29b02e70e52c) (This plugin is located near the bottom of that page.)
Also used by [Cool File Transfer](https://github.com/cubiclesoft/php-cool-file-transfer).
[![Donate](https://cubiclesoft.com/res/donate-shield.png)](https://cubiclesoft.com/donate/) [![Discord](https://img.shields.io/discord/777282089980526602?label=chat&logo=discord)](https://cubiclesoft.com/product-support/github/)
Features
--------
* Beautiful, compact, and fully responsive layout.
* Drag-and-drop dropzone with paste support.
* Full keyboard navigation.
* Client-side file naming.
* Preview support for images, audio, and video.
* Supports recording video and audio directly from a webcam, microphone, and other media sources.
* Chunked file upload support.
* Lots of useful callbacks.
* Automatic retries with exponential fallback.
* Multilingual support.
* Has a liberal open source license. MIT or LGPL, your choice.
* Designed for relatively painless integration into your project.
* Sits on GitHub for all of that pull request and issue tracker goodness to easily submit changes and ideas respectively.
Alternate Options
-----------------
jQuery Fancy File Uploader just handles uploading of files in an environment where you plan to apply strict storage controls. However, if you need something even fancier, here are a couple of options:
If you need a general-purpose hierarchical file management and tabbed file editor solution that can be readily embedded into existing software products, check out the open source CubicleSoft [PHP File Manager and Editor](https://github.com/cubiclesoft/php-filemanager) application.
If you need something even more powerful, flexible, and highly customizable with hierarchical directory and file structures, check out the open source CubicleSoft [Folder and File Explorer](https://github.com/cubiclesoft/js-fileexplorer) zero-dependencies Javascript widget.
Getting Started
---------------
jQuery is required to use this software so hopefully that doesn't come as a surprise to anyone. Parts of this plugin require the jQuery UI widget factory. If you are already including jQuery UI on your webpage, then you already have the widget factory and don't need to do anything else. Otherwise, add this line after including jQuery:
```html
<script type="text/javascript" src="fancy-file-uploader/jquery.ui.widget.js"></script>
```
Now you can include Fancy File Uploader:
```html
<link rel="stylesheet" href="fancy-file-uploader/fancy_fileupload.css" type="text/css" media="all" />
<script type="text/javascript" src="fancy-file-uploader/jquery.fileupload.js"></script>
<script type="text/javascript" src="fancy-file-uploader/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="fancy-file-uploader/jquery.fancy-fileupload.js"></script>
```
Let's say you have a file input element somewhere on the same page that looks like:
```html
<input id="thefiles" type="file" name="files" accept=".jpg, .png, image/jpeg, image/png" multiple>
```
To transform that file input into something fancy, pass in some options to the plugin and let the magic happen:
```html
<script type="text/javascript">
$(function() {
$('#thefiles').FancyFileUpload({
params : {
action : 'fileuploader'
},
maxfilesize : 1000000
});
});
</script>
```
Other than handling the files on the server side of things and leveraging the various callbacks, that's pretty much it for basic usage.
Server-Side Processing
----------------------
The server should reply with the following JSON object format for successful uploads:
```json
{
"success" : true
}
```
The server should reply with the following JSON object format for error conditions:
```json
{
"success" : false,
"error" : "Human-readable, possibly translated error.",
"errorcode" : "relevant_error_code"
}
```
See [FlexForms Modules](https://github.com/cubiclesoft/php-flexforms-modules), [Admin Pack](https://github.com/cubiclesoft/admin-pack), and [FlexForms](https://github.com/cubiclesoft/php-flexforms) for example usage with open source CubicleSoft products that handle Fancy File Uploader submissions.
Fancy File Uploader works with most server-side languages. For basic server-side PHP integration with Fancy File Uploader, you can use the included server-side helper class:
```php
<?php
require_once "fancy_file_uploader_helper.php";
function ModifyUploadResult(&$result, $filename, $name, $ext, $fileinfo)
{
// Add more information to the result here as necessary (e.g. a URL to the file that a callback uses to link to or show the file).
}
$options = array(
"allowed_exts" => array("jpg", "png"),
"filename" => __DIR__ . "/images/" . $id . ".{ext}",
// "result_callback" => "ModifyUploadResult"
);
FancyFileUploaderHelper::HandleUpload("files", $options);
?>
```
The class also contains `FancyFileUploaderHelper::GetMaxUploadFileSize()`, which determines the maximum allowed file/chunk upload size that PHP allows.
When using `FancyFileUploaderHelper::HandleUpload()`, be sure to pass `fileuploader` as a parameter to the server so the FancyFileUploaderHelper class will handle the request instead of ignoring it. For example:
```html
<script type="text/javascript">
$(function() {
$('#thefiles').FancyFileUpload({
params : {
fileuploader : '1'
},
// ...
});
});
</script>
```
Additional Examples
-------------------
To automatically start every upload as soon as it is added, do something similar to this:
```html
<script type="text/javascript">
$(function() {
$('#thefiles').FancyFileUpload({
params : {
action : 'fileuploader'
},
edit : false,
maxfilesize : 1000000,
added : function(e, data) {
// It is okay to simulate clicking the start upload button.
this.find('.ff_fileupload_actions button.ff_fileupload_start_upload').click();
}
});
});
</script>
```
It is possible to add a button to the screen to start all of the uploads at once that are able to be started:
```html
<button type="button" onclick="$('#thefiles').next().find('.ff_fileupload_actions button.ff_fileupload_start_upload').click(); return false;">Upload all files</button>
```
The specialized function `data.ff_info.RemoveFile()` can be used at any time to remove a file from the list which will immediately abort any upload in progress, remove the associated UI elements, and clean up internal structures:
```html
<script type="text/javascript">
$(function() {
var token;
$('#thefiles').FancyFileUpload({
params : {
action : 'fileuploader'
},
maxfilesize : 1000000,
startupload : function(SubmitUpload, e, data) {
$.ajax({
'url' : 'gettoken.php',
'dataType' : 'json',
'success' : function(tokendata) {
token = tokendata;
SubmitUpload();
}
});
},
continueupload : function(e, data) {
var ts = Math.round(new Date().getTime() / 1000);
// Alternatively, just call data.abort() or return false here to terminate the upload but leave the UI elements alone.
if (token.expires < ts) data.ff_info.RemoveFile();
},
uploadcompleted : function(e, data) {
data.ff_info.RemoveFile();
}
});
});
</script>
```
To use chunked uploads for handling large file transfers, read up on [jQuery File Upload chunked file uploads](https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads) and do something like:
```html
<script type="text/javascript">
$(function() {
$('#thefiles').FancyFileUpload({
params : {
action : 'fileuploader'
},
fileupload : {
maxChunkSize : 1000000
}
});
});
</script>
```
Enable the microphone and webcam/camera recording buttons:
```html
<script type="text/javascript">
$(function() {
$('#thefiles').FancyFileUpload({
params : {
action : 'fileuploader'
},
recordaudio : true,
recordvideo : true
});
});
</script>
```
To remove the widget altogether and restore the original file input, call: `$('#thefiles').FancyFileUpload('destroy');`
In order to be able to remove the widget later, `data('fancy-fileupload')` is used to store information alongside the object. Modifying various options after initial creation is possible but tricky. Accessing these internal options is at your own, probably minimal, risk:
* fileuploadwrap - A jQuery object pointing at the root of the DOM node of the main user interface.
* form - A jQuery object pointing at the hidden form that is created during the initialization process. When the user clicks the button to select files, the click transfers to the hidden file input field in the form.
* settings - A reference to the settings object.
Example usage to access the hidden file input element after creating it (e.g. to change its `accept` attribute):
```html
<script type="text/javascript">
$('#thefiles').each(function() {
var $this = $(this);
// Find the associated file input.
var fileinput = $this.data('fancy-fileupload').form.find('input[type=file]');
// Do something with the file input.
fileinput.attr('accept', '.png; image/png');
$this.data('fancy-fileupload').settings.accept = ['png'];
// Can even alter the underlying jQuery File Uploader (e.g. inject a canvas PNG blob).
fileinput.fileupload('add', { files: [ new Blob(...) ] });
});
</script>
```
Options
-------
This plugin accepts the following options:
* url - A string containing the destination URL to use to send the data. The default behavior is to locate the `action` of the nearest `form` element to the matching input file element and use that (Default is '').
* params - An object containing key-value pairs to send to the server when submitting file data (Default is an empty object).
* edit - A boolean indicating whether or not to allow the user to enter a filename minus the file extension after selecting a file but before the upload process has started (Default is true).
* maxfilesize - An integer containing the maximum size, in bytes, to allow for file upload (Default is -1, which means no limit).
* accept - An array containing a list of allowed file extensions (Default is null, which allows all file extensions). Note that the server is still responsible for validating uploads.
* displayunits - A string containing one of 'iec_windows', 'iec_formal', or 'si' to specify what units to use when displaying file sizes to the user (Default is 'iec_windows').
* adjustprecision - A boolean indicating whether or not to adjust the final precision when displaying file sizes to the user (Default is true).
* retries - An integer containing the number of retries to perform before giving up (Default is 5).
* retrydelay - An integer containing the base delay, in milliseconds, to apply between retries (Default is 500). Note that the delay is multiplied by 2 for exponential fallback.
* recordaudio - A boolean indicating whether or not to display a toolbar button with a microphone icon for recording audio directly via the web browser (Default is false).
* audiosettings - An object containing valid MediaRecorder options (Default is an empty object).
* recordvideo - A boolean indicating whether or not to display a toolbar button with a webcam icon for recording video directly via the web browser (Default is false).
* videosettings - An object containing valid MediaRecorder options (Default is an empty object).
* preinit - A valid callback function that is called during initialization to allow for last second changes to the settings. Useful for altering `fileupload` options on the fly. The callback function must accept one parameter - callback(settings).
* postinit - A valid callback function that is called at the end of initialization of each instance. The `this` is a jQuery object to the instance. The callback function must accept zero parameters - callback().
* added - A valid callback function that is called for each item after its UI has been added to the DOM. The callback function must accept two parameters - callback(e, data).
* showpreview - A valid callback function that is called after the preview dialog appears. Useful for temporarily preventing unwanted UI interactions elsewhere. The callback function must accept three parameters - callback(data, preview, previewclone).
* hidepreview - A valid callback function that is called after the preview dialog disappears. The callback function must accept three parameters - callback(data, preview, previewclone).
* startupload - A valid callback function that is called when the button is clicked to start the upload. The callback function must accept three parameters - callback(SubmitUpload, e, data). The callback is expected to call the `SubmitUpload()` function when it is ready to start the file upload.
* continueupload - A valid callback function that is called whenever progress is updated (default is every 100 milliseconds). The callback function must accept three parameters - callback(e, data). The callback may return false or call `data.abort()` to cancel the upload.
* uploadcancelled - A valid callback function that is called whenever an upload has been cancelled. The callback function must accept two parameters - callback(e, data).
* uploadcompleted - A valid callback function that is called whenever an upload has successfully completed. The callback function must accept two parameters - callback(e, data).
* fileupload - An object containing [jQuery File Upload options](https://github.com/blueimp/jQuery-File-Upload/wiki/Options) (Default is an empty object). The following options are immutable and cannot be changed (doing so will break this plugin): `singleFileUploads` (always true), `dropZone`, `add`, `progress`, `fail`, `done`, `chunksend`, and `chunkdone`. The `dataType` option must be 'json' (the default) or 'jsonp' as the plugin depends on a valid JSON response for correct operation.
* langmap - An object containing translation strings. Support exists for most of the user interface (Default is an empty object).
All callbacks have a `this` containing the jQuery object for the current UI table row. Use the jQuery `this.find(selector)` syntax to locate relevant UI elements.
The default settings can be adjusted before creating any instances via `$.FancyFileUpload.defaults`. The most common use-case is to apply a set of translation strings to `langmap`.
Translations
------------
To translate this plugin to another language, open `jquery.fancy-fileupload.js` in a text editor and locate strings passed to the `Translate()` function. In a new .js file, create a mapping between English and the target language:
```js
$.FancyFileUpload.defaults.langmap = {
'File is too large. Maximum file size is {0}.': 'Translation goes here...'
};
```
Some strings contain `{0}`, `{1}`, etc. which are placeholders for `FormatStr()` to fill in. Load your .js file after loading `jquery.fancy-fileupload.js`.
Under the Hood
--------------
jQuery Fancy File Uploader uses the core plugin from blueimp [jQuery File Upload](https://github.com/blueimp/jQuery-File-Upload) and then wraps the core plugin up in the custom user interface that users interact with.

View File

@@ -0,0 +1,126 @@
/*
* jQuery postMessage Transport Plugin
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* global define, require, window, document */
;(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(require('jquery'));
} else {
// Browser globals:
factory(window.jQuery);
}
}(function ($) {
'use strict';
var counter = 0,
names = [
'accepts',
'cache',
'contents',
'contentType',
'crossDomain',
'data',
'dataType',
'headers',
'ifModified',
'mimeType',
'password',
'processData',
'timeout',
'traditional',
'type',
'url',
'username'
],
convert = function (p) {
return p;
};
$.ajaxSetup({
converters: {
'postmessage text': convert,
'postmessage json': convert,
'postmessage html': convert
}
});
$.ajaxTransport('postmessage', function (options) {
if (options.postMessage && window.postMessage) {
var iframe,
loc = $('<a>').prop('href', options.postMessage)[0],
target = loc.protocol + '//' + loc.host,
xhrUpload = options.xhr().upload;
// IE always includes the port for the host property of a link
// element, but not in the location.host or origin property for the
// default http port 80 and https port 443, so we strip it:
if (/^(http:\/\/.+:80)|(https:\/\/.+:443)$/.test(target)) {
target = target.replace(/:(80|443)$/, '');
}
return {
send: function (_, completeCallback) {
counter += 1;
var message = {
id: 'postmessage-transport-' + counter
},
eventName = 'message.' + message.id;
iframe = $(
'<iframe style="display:none;" src="' +
options.postMessage + '" name="' +
message.id + '"></iframe>'
).bind('load', function () {
$.each(names, function (i, name) {
message[name] = options[name];
});
message.dataType = message.dataType.replace('postmessage ', '');
$(window).bind(eventName, function (e) {
e = e.originalEvent;
var data = e.data,
ev;
if (e.origin === target && data.id === message.id) {
if (data.type === 'progress') {
ev = document.createEvent('Event');
ev.initEvent(data.type, false, true);
$.extend(ev, data);
xhrUpload.dispatchEvent(ev);
} else {
completeCallback(
data.status,
data.statusText,
{postmessage: data.result},
data.headers
);
iframe.remove();
$(window).unbind(eventName);
}
}
});
iframe[0].contentWindow.postMessage(
message,
target
);
}).appendTo(document.body);
},
abort: function () {
if (iframe) {
iframe.remove();
}
}
};
}
});
}));

View File

@@ -0,0 +1,89 @@
/*
* jQuery XDomainRequest Transport Plugin
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*
* Based on Julian Aubourg's ajaxHooks xdr.js:
* https://github.com/jaubourg/ajaxHooks/
*/
/* global define, require, window, XDomainRequest */
;(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(require('jquery'));
} else {
// Browser globals:
factory(window.jQuery);
}
}(function ($) {
'use strict';
if (window.XDomainRequest && !$.support.cors) {
$.ajaxTransport(function (s) {
if (s.crossDomain && s.async) {
if (s.timeout) {
s.xdrTimeout = s.timeout;
delete s.timeout;
}
var xdr;
return {
send: function (headers, completeCallback) {
var addParamChar = /\?/.test(s.url) ? '&' : '?';
function callback(status, statusText, responses, responseHeaders) {
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
xdr = null;
completeCallback(status, statusText, responses, responseHeaders);
}
xdr = new XDomainRequest();
// XDomainRequest only supports GET and POST:
if (s.type === 'DELETE') {
s.url = s.url + addParamChar + '_method=DELETE';
s.type = 'POST';
} else if (s.type === 'PUT') {
s.url = s.url + addParamChar + '_method=PUT';
s.type = 'POST';
} else if (s.type === 'PATCH') {
s.url = s.url + addParamChar + '_method=PATCH';
s.type = 'POST';
}
xdr.open(s.type, s.url);
xdr.onload = function () {
callback(
200,
'OK',
{text: xdr.responseText},
'Content-Type: ' + xdr.contentType
);
};
xdr.onerror = function () {
callback(404, 'Not Found');
};
if (s.xdrTimeout) {
xdr.ontimeout = function () {
callback(0, 'timeout');
};
xdr.timeout = s.xdrTimeout;
}
xdr.send((s.hasContent && s.data) || null);
},
abort: function () {
if (xdr) {
xdr.onerror = $.noop();
xdr.abort();
}
}
};
}
});
}
}));

View File

@@ -0,0 +1,119 @@
.ff_fileupload_hidden { display: none; }
.ff_fileupload_wrap .ff_fileupload_dropzone_wrap { position: relative; }
.ff_fileupload_wrap .ff_fileupload_dropzone { display: block; width: 100%; height: 200px; box-sizing: border-box; border: 2px dashed #A2B4CA; border-radius: 3px; padding: 0; background-color: #FCFCFC; background-image: url('fancy_upload.png'); background-repeat: no-repeat; background-position: center center; opacity: 0.85; cursor: pointer; outline: none; }
.ff_fileupload_wrap .ff_fileupload_dropzone::-moz-focus-inner { border: 0; }
.ff_fileupload_wrap .ff_fileupload_dropzone:hover, .ff_fileupload_wrap .ff_fileupload_dropzone:focus, .ff_fileupload_wrap .ff_fileupload_dropzone:active { opacity: 1; background-color: #FDFDFD; border-color: #157EFB; }
.ff_fileupload_wrap .ff_fileupload_dropzone_tools { position: absolute; right: 10px; top: 0; }
.ff_fileupload_wrap .ff_fileupload_dropzone_tool { display: block; margin-top: 10px; width: 40px; height: 40px; box-sizing: border-box; border: 1px solid #A2B4CA; border-radius: 3px; padding: 0; background-color: #FDFDFD; background-repeat: no-repeat; background-position: center center; opacity: 0.85; cursor: pointer; outline: none; }
.ff_fileupload_wrap .ff_fileupload_dropzone_tool::-moz-focus-inner { border: 0; }
.ff_fileupload_wrap .ff_fileupload_dropzone_tool:hover, .ff_fileupload_wrap .ff_fileupload_dropzone_tool:focus, .ff_fileupload_wrap .ff_fileupload_dropzone_tool:active { opacity: 1; background-color: #FFFFFF; border-color: #157EFB; }
.ff_fileupload_wrap .ff_fileupload_recordaudio { background-image: url('fancy_microphone.png'); }
.ff_fileupload_wrap .ff_fileupload_recordvideo { background-image: url('fancy_webcam.png'); }
.ff_fileupload_wrap .ff_fileupload_recordvideo_preview { position: absolute; display: block; right: 60px; top: 10px; width: 320px; max-width: calc(100% - 70px); height: calc(100% - 20px); background-color: #222222; }
.ff_fileupload_wrap .ff_fileupload_recordvideo_preview.ff_fileupload_hidden { display: none; }
@keyframes ff_fileupload_recording_animate {
from { border-color: #EF1F1F; }
to { border-color: #C9A1A1; }
}
.ff_fileupload_wrap .ff_fileupload_recording { animation: ff_fileupload_recording_animate 1.2s infinite alternate; }
.ff_fileupload_wrap table.ff_fileupload_uploads { width: 100%; border-collapse: collapse !important; border: 0 none; }
.ff_fileupload_wrap table.ff_fileupload_uploads tr, .ff_fileupload_wrap table.ff_fileupload_uploads td { margin: 0; border: 0 none; padding: 0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td { vertical-align: top; padding: 1em 0; white-space: nowrap; line-height: normal; }
@keyframes ff_fileupload_bounce_animate {
10%, 90% { transform: translateY(-1px); }
20%, 80% { transform: translateY(2px); }
30%, 50%, 70% { transform: translateY(-3px); }
40%, 60% { transform: translateY(3px); }
}
.ff_fileupload_wrap table.ff_fileupload_uploads tr.ff_fileupload_bounce { animation: ff_fileupload_bounce_animate 0.82s cubic-bezier(.36,.07,.19,.97) both; transform: translateY(0); }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview { width: 1px; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image { display: block; box-sizing: border-box; border: 0 none; padding: 0; background-color: #DDDDDD; background-size: cover; background-repeat: no-repeat; background-position: center center; width: 50px; height: 50px; border-radius: 5px; opacity: 0.75; text-align: center; font-size: 12px; font-weight: bold; color: #222222; overflow: hidden; outline: none; cursor: default; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image::-moz-focus-inner { border: 0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image_has_preview { cursor: pointer; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image:hover, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image:focus, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image:active { opacity: 1; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text { display: block; margin: 0 auto; width: 70%; overflow: hidden; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button { display: inline-block; vertical-align: top; width: 26px; height: 26px; box-sizing: border-box; border: 1px solid #A2B4CA; border-radius: 3px; padding: 0; background-color: #FCFCFC; background-repeat: no-repeat; background-position: center center; opacity: 0.85; cursor: pointer; outline: none; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button::-moz-focus-inner { border: 0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button:hover, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button:focus, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button:active { opacity: 1; background-color: #FDFDFD; border-color: #157EFB; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions button.ff_fileupload_start_upload { margin-right: 0.5em; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile { display: none; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile button { display: block; margin-top: 0.3em; width: 100%; height: 28px; box-sizing: border-box; border: 1px solid #A2B4CA; border-radius: 3px; padding: 0; background-color: #FCFCFC; background-repeat: no-repeat; background-position: center center; opacity: 0.85; cursor: pointer; outline: none; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile button::-moz-focus-inner { border: 0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile button:hover, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile button:focus, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile button:active { opacity: 1; background-color: #FDFDFD; border-color: #157EFB; }
.ff_fileupload_wrap table.ff_fileupload_uploads button.ff_fileupload_start_upload { background-image: url('fancy_okay.png'); }
.ff_fileupload_wrap table.ff_fileupload_uploads button.ff_fileupload_remove_file { background-image: url('fancy_remove.png'); }
/* Colored buttons based on file extension for non-images. */
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_with_color { color: #FFFFFF; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_a { background-color: #F03C3C; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_b { background-color: #F05A3C; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_c { background-color: #F0783C; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_d { background-color: #F0963C; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_e { background-color: #E0862B; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_f { background-color: #DCA12B; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_g { background-color: #C7AB1E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_h { background-color: #C7C71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_i { background-color: #ABC71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_j { background-color: #8FC71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_k { background-color: #72C71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_l { background-color: #56C71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_m { background-color: #3AC71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_n { background-color: #1EC71E; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_o { background-color: #1EC73A; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_p { background-color: #1EC756; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_q { background-color: #1EC78F; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_r { background-color: #1EC7AB; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_s { background-color: #1EC7C7; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_t { background-color: #1EABC7; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_u { background-color: #1E8FC7; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_v { background-color: #1E72C7; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_w { background-color: #3C78F0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_x { background-color: #3C5AF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_y { background-color: #3C3CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_z { background-color: #5A3CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_0 { background-color: #783CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_1 { background-color: #963CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_2 { background-color: #B43CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_3 { background-color: #D23CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_4 { background-color: #F03CF0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_5 { background-color: #F03CD2; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_6 { background-color: #F03CB4; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_7 { background-color: #F03C96; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_8 { background-color: #F03C78; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_text_9 { background-color: #F03C5A; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary { padding: 1em; font-size: 0.9em; white-space: normal; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_filename { width: 100%; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_filename input { box-sizing: border-box; width: 100%; padding: 0.3em; margin-bottom: 0.1em; font-size: 1.0em; font-weight: normal; line-height: normal; border: 1px solid #BBBBBB; border-radius: 0; box-shadow: none; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_filename input:focus, .ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_filename input:hover { border: 1px solid #888888; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_errors { color: #A94442; font-weight: bold; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_progress_background { margin-top: 0.5em; background-color: #CCCCCC; height: 2px; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary .ff_fileupload_progress_bar { background-color: #157EFB; width: 0; height: 2px; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions { width: 1px; text-align: right; }
@media (max-width: 420px) {
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_preview_image { width: 36px; height: 36px; font-size: 11px; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_summary { padding-right: 0; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_actions { display: none; }
.ff_fileupload_wrap table.ff_fileupload_uploads td.ff_fileupload_preview .ff_fileupload_actions_mobile { display: block; }
}
.ff_fileupload_dialog_background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.85); z-index: 10000; }
.ff_fileupload_dialog_main { position: absolute; top: 10%; left: 10%; width: 80%; height: 80%; text-align: center; }
.ff_fileupload_dialog_main img { position: relative; top: 50%; transform: perspective(1px) translateY(-50%); max-width: 100%; max-height: 100%; }
.ff_fileupload_dialog_main audio { position: relative; top: 50%; transform: perspective(1px) translateY(-50%); width: 100%; }
.ff_fileupload_dialog_main video { position: relative; top: 50%; transform: perspective(1px) translateY(-50%); max-width: 100%; max-height: 100%; }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,785 @@
// jQuery plugin to display a custom jQuery File Uploader interface.
// (C) 2020 CubicleSoft. All Rights Reserved.
(function($) {
var EscapeHTML = function(text) {
var map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
var FormatStr = function(format) {
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/{(\d+)}/g, function(match, number) {
return (typeof args[number] != 'undefined' ? args[number] : match);
});
};
var GetDisplayFilesize = function(numbytes, adjustprecision, units) {
if (numbytes == 0) return '0 Bytes';
if (numbytes == 1) return '1 Byte';
numbytes = Math.abs(numbytes);
var magnitude, abbreviations;
if (units && units.toLowerCase() === 'iec_formal')
{
magnitude = Math.pow(2, 10);
abbreviations = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
}
else if (units && units.toLowerCase() === 'si')
{
magnitude = Math.pow(10, 3);
abbreviations = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
}
else
{
magnitude = Math.pow(2, 10);
abbreviations = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
}
var pos = Math.floor(Math.log(numbytes) / Math.log(magnitude));
var result = (numbytes / Math.pow(magnitude, pos));
return (pos == 0 || (adjustprecision && result >= 99.995) ? result.toFixed(0) : result.toFixed(2)) + ' ' + abbreviations[pos];
};
var DisplayPreviewDialog = function(preview, endelem, inforow, data, settings) {
var previewbackground = $('<div>').addClass('ff_fileupload_dialog_background');
var previewclone = preview.clone(true, true).click(function(e) {
e.stopPropagation();
});
var previewdialog = $('<div>').addClass('ff_fileupload_dialog_main').append(previewclone);
var HidePreviewDialog = function() {
$(document).off('keyup.fancy_fileupload');
previewbackground.remove();
endelem.focus();
if (settings.hidepreview) settings.hidepreview.call(inforow, data, preview, previewclone);
};
$(document).on('keyup.fancy_fileupload', function(e) {
if (e.keyCode == 27) {
HidePreviewDialog();
}
});
previewbackground.append(previewdialog).click(function() {
HidePreviewDialog();
});
$('body').append(previewbackground);
previewclone.focus();
if (settings.showpreview) settings.showpreview.call(inforow, data, preview, previewclone);
};
var InitShowAriaLabelInfo = function(inforow) {
inforow.find('button').hover(function() {
var val = $(this).attr('aria-label');
if (val)
{
inforow.find('.ff_fileupload_buttoninfo').text(val).removeClass('ff_fileupload_hidden');
inforow.find('.ff_fileupload_fileinfo').addClass('ff_fileupload_hidden');
}
}, function() {
inforow.find('.ff_fileupload_fileinfo').removeClass('ff_fileupload_hidden');
inforow.find('.ff_fileupload_buttoninfo').addClass('ff_fileupload_hidden');
});
};
$.fn.FancyFileUpload = function(options) {
this.each(function() {
var $this = $(this);
// Remove the previous file uploader.
if ($this.data('fancy-fileupload') && typeof($this.data('fancy-fileupload')) === 'object')
{
$this.removeClass('ff_fileupload_hidden');
var data = $this.data('fancy-fileupload');
data.form.find('input[type=file]').fileupload('destroy');
data.form.remove();
data.fileuploadwrap.remove();
$this.removeData('fancy-fileupload');
}
});
if (!$('.ff_fileupload_hidden').length)
{
$(document).off('drop.fancy_fileupload dragover.fancy_fileupload');
$(window).off('beforeunload.fancy_fileupload');
}
if (typeof(options) === 'string' && options === 'destroy') return this;
var settings = $.extend({}, $.fn.FancyFileUpload.defaults, options);
// Let custom callbacks make last second changes to the finalized settings.
if (settings.preinit) settings.preinit(settings);
// Prevent default file drag-and-drop operations.
$(document).off('drop.fancy_fileupload dragover.fancy_fileupload');
$(document).on('drop.fancy_fileupload dragover.fancy_fileupload', function (e) {
e.preventDefault();
});
// Some useful functions.
var Translate = function(str) {
return (settings.langmap[str] ? settings.langmap[str] : str);
};
// Prevent the user from leaving the page if there is an active upload.
// Most browsers won't show the custom message. So make the relevant UI elements bounce using CSS.
$(window).on('beforeunload.fancy_fileupload', function(e) {
var active = $('.ff_fileupload_uploading, .ff_fileupload_starting');
var queued = $('.ff_fileupload_queued');
if (active.length || queued.length)
{
active.removeClass('ff_fileupload_bounce');
setTimeout(function() { active.addClass('ff_fileupload_bounce') }, 250);
queued.removeClass('ff_fileupload_bounce');
setTimeout(function() { queued.addClass('ff_fileupload_bounce') }, 250);
if (active.length) return Translate('There is a file upload still in progress. Leaving the page will cancel the upload.\n\nAre you sure you want to leave this page?');
if (queued.length) return Translate('There is a file that was added to the queue but the upload has not been started. Leaving the page will clear the queue and not upload the file.\n\nAre you sure you want to leave this page?');
}
});
// Create some extra DOM nodes for preview checking.
var audioelem = document.createElement('audio');
var videoelem = document.createElement('video');
var AddFile = function(uploads, e, data) {
var inforow = $('<tr><td class="ff_fileupload_preview"><button class="ff_fileupload_preview_image" type="button"><span class="ff_fileupload_preview_text"></span></button><div class="ff_fileupload_actions_mobile"></div></td><td class="ff_fileupload_summary"><div class="ff_fileupload_filename"></div><div class="ff_fileupload_fileinfo"></div><div class="ff_fileupload_buttoninfo ff_fileupload_hidden"></div><div class="ff_fileupload_errors ff_fileupload_hidden"></div><div class="ff_fileupload_progress_background ff_fileupload_hidden"><div class="ff_fileupload_progress_bar"></div></div></td><td class="ff_fileupload_actions"></td></tr>');
var pos = data.files[0].name.lastIndexOf('.');
var filename = (pos > -1 ? data.files[0].name.substring(0, pos) : data.files[0].name);
var fileext = (pos > -1 ? data.files[0].name.substring(pos + 1).toLowerCase() : '');
var alphanum = 'abcdefghijklmnopqrstuvwxyz0123456789';
pos = (fileext == '' ? -1 : alphanum.indexOf(fileext.charAt(0)));
var fileextclass = alphanum.charAt((pos > -1 ? pos : Math.floor(Math.random() * alphanum.length)));
// Initialize necessary callback options.
data.ff_info = {};
data.ff_info.errors = [];
data.ff_info.retries = 0;
data.ff_info.retrydelay = settings.retrydelay;
data.ff_info.removewidget = false;
data.ff_info.inforow = inforow;
data.ff_info.displayfilesize = GetDisplayFilesize(data.files[0].size, settings.adjustprecision, settings.displayunits);
data.context = inforow;
// A couple of functions for handling actions.
var StartUpload = function(e) {
e.preventDefault();
// Set filename.
if (settings.edit && !data.ff_info.errors.length)
{
var fileinput = inforow.find('.ff_fileupload_filename input');
if (fileinput.length)
{
var newfilename = fileinput.val();
if (fileext != '') newfilename += '.' + fileext;
inforow.find('.ff_fileupload_filename').text(newfilename);
data.files[0].uploadName = newfilename;
}
}
// Remove start upload buttons.
inforow.find('button.ff_fileupload_start_upload').remove();
// Reset hover status.
inforow.find('.ff_fileupload_fileinfo').removeClass('ff_fileupload_hidden');
inforow.find('.ff_fileupload_buttoninfo').addClass('ff_fileupload_hidden');
// Set the status.
inforow.find('.ff_fileupload_fileinfo').text(data.ff_info.displayfilesize + ' | ' + Translate('Starting upload...'));
// Display progress bar.
inforow.find('.ff_fileupload_progress_background').removeClass('ff_fileupload_hidden');
// Alter remove buttons.
inforow.find('button.ff_fileupload_remove_file').attr('aria-label', Translate('Cancel upload and remove from list'));
// Begin the actual upload.
inforow.removeClass('ff_fileupload_queued');
inforow.addClass('ff_fileupload_starting');
var SubmitUpload = function() {
inforow.removeClass('ff_fileupload_starting');
inforow.addClass('ff_fileupload_uploading');
data.submit();
};
if (settings.startupload) settings.startupload.call(inforow, SubmitUpload, e, data);
else SubmitUpload();
};
var RemoveFile = function(e) {
e.preventDefault();
if (inforow.hasClass('ff_fileupload_uploading'))
{
if (!confirm(Translate('This file is currently being uploaded.\n\nStop the upload and remove the file from the list?'))) return;
data.ff_info.removewidget = true;
data.abort();
}
else
{
if (inforow.hasClass('ff_fileupload_starting'))
{
if (!confirm(Translate('This file is waiting to start.\n\nCancel the operation and remove the file from the list?'))) return;
if (settings.uploadcancelled) settings.uploadcancelled.call(data.ff_info.inforow, e, data);
}
inforow.remove();
delete data.ff_info;
}
};
data.ff_info.RemoveFile = function() {
if (inforow.hasClass('ff_fileupload_uploading'))
{
data.ff_info.removewidget = true;
data.abort();
}
else
{
if (inforow.hasClass('ff_fileupload_starting'))
{
if (settings.uploadcancelled) settings.uploadcancelled.call(data.ff_info.inforow, e, data);
}
inforow.remove();
delete data.ff_info;
}
};
// Thumbnail preview.
var haspreview = false;
var preview;
var hasimage = false;
if (URL && URL.createObjectURL)
{
var url = URL.createObjectURL(data.files[0]);
if (url)
{
if (data.files[0].type === 'image/gif' || data.files[0].type === 'image/jpeg' || data.files[0].type === 'image/png')
{
inforow.find('.ff_fileupload_preview_image').css('background-image', 'url("' + url + '")');
haspreview = true;
preview = $('<img>').attr('src', url);
hasimage = true;
}
else if (data.files[0].type.lastIndexOf('audio/', 0) > -1 && audioelem.canPlayType && audioelem.canPlayType(data.files[0].type))
{
haspreview = true;
preview = $('<audio>').attr('src', url).prop('controls', true);
}
else if (data.files[0].type.lastIndexOf('video/', 0) > -1 && videoelem.canPlayType && videoelem.canPlayType(data.files[0].type))
{
haspreview = true;
preview = $('<video>').attr('src', url).prop('controls', true);
}
}
}
if (haspreview)
{
inforow.find('.ff_fileupload_preview_image').addClass('ff_fileupload_preview_image_has_preview').attr('aria-label', Translate('Preview')).click(function(e) {
e.preventDefault();
this.blur();
DisplayPreviewDialog(preview, this, inforow, data, settings);
});
}
else
{
inforow.find('.ff_fileupload_preview_image').prop('disabled', true).attr('aria-label', Translate('No preview available')).click(function(e) {
e.preventDefault();
});
}
if (!hasimage) inforow.find('.ff_fileupload_preview_image').addClass('ff_fileupload_preview_text_with_color').addClass('ff_fileupload_preview_text_' + fileextclass).text(fileext);
// Validate inputs.
if (settings.accept)
{
var found = false;
for (var x = 0; x < settings.accept.length && !found; x++)
{
if (settings.accept[x] === fileext || settings.accept[x] === data.files[0].type) found = true;
}
if (!found) data.ff_info.errors.push(Translate('Invalid file extension.'));
}
if (settings.maxfilesize > -1 && data.files[0].size > settings.maxfilesize) data.ff_info.errors.push(FormatStr(Translate('File is too large. Maximum file size is {0}.'), GetDisplayFilesize(settings.maxfilesize, settings.adjustprecision, settings.displayunits)));
// Filename text field/display.
if (settings.edit && !data.ff_info.errors.length)
{
inforow.find('.ff_fileupload_filename').append($('<input>').attr('type', 'text').val(filename).keydown(function(e) {
// Start uploading if someone presses enter.
if (e.keyCode == 13) StartUpload(e);
}));
}
else
{
inforow.find('.ff_fileupload_filename').text(data.files[0].name);
}
// File/Upload information.
inforow.find('.ff_fileupload_fileinfo').text(data.ff_info.displayfilesize + (hasimage && settings.edit && !data.ff_info.errors.length ? ' | .' + fileext : ''));
// Errors.
if (data.ff_info.errors.length) inforow.find('.ff_fileupload_errors').html(data.ff_info.errors.join('<br>')).removeClass('ff_fileupload_hidden');
// Action buttons.
if (!data.ff_info.errors.length)
{
inforow.find('.ff_fileupload_actions').append($('<button>').addClass('ff_fileupload_start_upload').attr('type', 'button').attr('aria-label', Translate('Start uploading')).click(StartUpload));
inforow.find('.ff_fileupload_actions_mobile').append($('<button>').addClass('ff_fileupload_start_upload').attr('type', 'button').attr('aria-label', Translate('Start uploading')).click(StartUpload));
inforow.addClass('ff_fileupload_queued');
}
inforow.find('.ff_fileupload_actions').append($('<button>').addClass('ff_fileupload_remove_file').attr('type', 'button').attr('aria-label', Translate('Remove from list')).click(RemoveFile));
inforow.find('.ff_fileupload_actions_mobile').append($('<button>').addClass('ff_fileupload_remove_file').attr('type', 'button').attr('aria-label', Translate('Remove from list')).click(RemoveFile));
// Handle button hover.
InitShowAriaLabelInfo(inforow);
// Improve progress bar performance during upload.
data.ff_info.fileinfo = inforow.find('.ff_fileupload_fileinfo');
data.ff_info.progressbar = inforow.find('.ff_fileupload_progress_bar');
uploads.append(inforow);
if (settings.added) settings.added.call(inforow, e, data);
};
var UploadProgress = function(e, data) {
var progress = (data.total < 1 ? 0 : data.loaded / data.total * 100);
data.ff_info.fileinfo.text(FormatStr(Translate('{0} of {1} | {2}%'), GetDisplayFilesize(data.loaded, settings.adjustprecision, settings.displayunits), data.ff_info.displayfilesize, progress.toFixed(0)));
data.ff_info.progressbar.css('width', progress + '%');
if (settings.continueupload && settings.continueupload.call(data.ff_info.inforow, e, data) === false) data.abort();
};
var UploadFailed = function(e, data) {
// For handling chunked upload termination.
if (data.ff_info.lastresult && !data.ff_info.lastresult.success)
{
data.result = data.ff_info.lastresult;
data.errorThrown = 'failed_with_msg';
}
if (data.errorThrown !== 'abort' && data.errorThrown !== 'failed_with_msg' && data.uploadedBytes < data.files[0].size && data.ff_info.retries < settings.retries)
{
data.ff_info.fileinfo.text(FormatStr(Translate('{0} | Network error, retrying in a moment... ({1})'), data.ff_info.displayfilesize, data.errorThrown));
data.ff_info.inforow.removeClass('ff_fileupload_uploading');
data.ff_info.inforow.addClass('ff_fileupload_starting');
setTimeout(function() {
data.ff_info.inforow.removeClass('ff_fileupload_starting');
data.ff_info.inforow.addClass('ff_fileupload_uploading');
data.data = null;
data.submit();
}, data.ff_info.retrydelay);
data.ff_info.retries++;
data.ff_info.retrydelay *= 2;
return;
}
data.ff_info.inforow.removeClass('ff_fileupload_uploading');
if (settings.uploadcancelled) settings.uploadcancelled.call(data.ff_info.inforow, e, data);
if (data.ff_info.removewidget)
{
data.ff_info.inforow.remove();
delete data.ff_info;
}
else
{
// Set the error info.
if (data.errorThrown === 'abort') data.ff_info.errors.push(Translate('The upload was cancelled.'));
else if (data.errorThrown === 'failed_with_msg') data.ff_info.errors.push(FormatStr(Translate('The upload failed. {0} ({1})'), EscapeHTML(data.result.error), EscapeHTML(data.result.errorcode)));
else data.ff_info.errors.push(Translate('The upload failed.'));
data.ff_info.inforow.find('.ff_fileupload_errors').html(data.ff_info.errors.join('<br>')).removeClass('ff_fileupload_hidden');
// Hide the progress bar.
data.ff_info.inforow.find('.ff_fileupload_progress_background').addClass('ff_fileupload_hidden');
// Alter remove buttons.
data.ff_info.inforow.find('button.ff_fileupload_remove_file').attr('aria-label', Translate('Remove from list'));
}
};
var UploadDone = function(e, data) {
if (!data.result.success)
{
if (typeof(data.result.error) !== 'string') data.result.error = Translate('The server indicated that the upload was not successful. No additional information available.');
if (typeof(data.result.errorcode) !== 'string') data.result.errorcode = 'server_response';
data.errorThrown = 'failed_with_msg';
data.ff_info.removewidget = false;
UploadFailed(e, data);
return;
}
data.ff_info.inforow.removeClass('ff_fileupload_uploading');
if (settings.uploadcompleted) settings.uploadcompleted.call(data.ff_info.inforow, e, data);
if (data.ff_info.removewidget)
{
data.ff_info.inforow.remove();
delete data.ff_info;
}
else
{
// Set the status.
data.ff_info.inforow.find('.ff_fileupload_fileinfo').text(data.ff_info.displayfilesize + ' | ' + Translate('Upload completed'));
// Hide the progress bar.
data.ff_info.inforow.find('.ff_fileupload_progress_background').addClass('ff_fileupload_hidden');
// Alter remove buttons.
data.ff_info.inforow.find('button.ff_fileupload_remove_file').attr('aria-label', Translate('Remove from list'));
}
};
var UploadChunkSend = function(e, data) {
if (data.ff_info)
{
if (settings.continueupload && settings.continueupload.call(data.ff_info.inforow, e, data) === false)
{
if (!data.ff_info.lastresult || data.ff_info.lastresult.success)
{
data.ff_info.lastresult = {
'success' : false
};
}
}
if (data.ff_info.lastresult && !data.ff_info.lastresult.success)
{
data.result = data.ff_info.lastresult;
if (typeof(data.ff_info.lastresult.error) !== 'string') data.ff_info.lastresult.error = Translate('The server indicated that the upload was not successful. No additional information available.');
if (typeof(data.ff_info.lastresult.errorcode) !== 'string') data.ff_info.lastresult.errorcode = 'server_response';
data.ff_info.removewidget = false;
return false;
}
}
};
var UploadChunkDone = function(e, data) {
// Reset retries for successful chunked uploads.
data.ff_info.retries = 0;
data.ff_info.retrydelay = settings.retrydelay;
// Save for the next UploadChunkSend() call.
data.ff_info.lastresult = data.result;
};
return this.each(function() {
var $this = $(this);
// Calculate the action URL.
if (settings.url === '')
{
var url = $this.closest('form').attr('action');
if (url) settings.url = url;
}
// Create a separate, hidden form on the page for handling file uploads.
var form = $('<form>').addClass('ff_fileupload_hidden').attr({
'action' : settings.url,
'method' : 'post',
'enctype' : 'multipart/form-data'
});
$('body').append(form);
// Append hidden input elements.
for (var x in settings.params)
{
if (settings.params.hasOwnProperty(x))
{
var input = $('<input>').attr({
'type' : 'hidden',
'name' : x,
'value' : settings.params[x]
});
form.append(input);
}
}
// Append a file input element.
var fileinputname = $this.attr('name');
var fileinput = $('<input>').attr({
'type' : 'file',
'name' : (fileinputname ? fileinputname : 'file')
});
if ($this.prop('multiple')) fileinput.prop('multiple', true);
// Process the accepted file extensions.
if ($this.attr('accept'))
{
fileinput.attr('accept', $this.attr('accept'));
if (!settings.accept)
{
var accept = $this.attr('accept').split(',');
settings.accept = [];
for (var x = 0; x < accept.length; x++)
{
var opt = $.trim(accept[x]).toLowerCase();
settings.accept.push(opt.indexOf('/') < 0 && opt.lastIndexOf('.') > -1 ? opt.substring(opt.lastIndexOf('.') + 1) : opt);
}
}
}
form.append(fileinput);
// Insert the widget wrapper.
var fileuploadwrap = $('<div>').addClass('ff_fileupload_wrap');
$this.after(fileuploadwrap);
// Insert a new dropzone. Using a button allows for standard keyboard and mouse navigation to the element. The wrapper is for paste support.
var dropzonewrap = $('<div>').addClass('ff_fileupload_dropzone_wrap');
var dropzone = $('<button>').addClass('ff_fileupload_dropzone').attr('type', 'button').attr('aria-label', Translate('Browse, drag-and-drop, or paste files to upload'));
dropzonewrap.append(dropzone);
fileuploadwrap.append(dropzonewrap);
dropzone.on('click.fancy_fileupload', function(e) {
e.preventDefault();
form.find('input[type=file]').click();
});
// Add special recording buttons (if enabled).
var dropzonetools = $('<div>').addClass('ff_fileupload_dropzone_tools');
dropzonewrap.append(dropzonetools);
// Record audio.
if (settings.recordaudio && navigator.mediaDevices && window.MediaRecorder)
{
var audiobutton = $('<button>').addClass('ff_fileupload_dropzone_tool').addClass('ff_fileupload_recordaudio').attr('type', 'button').attr('aria-label', Translate('Record audio using a microphone'));
dropzonetools.append(audiobutton);
var audiorec = null;
var audiochunks = [];
audiobutton.click(function(e) {
e.preventDefault();
if (!audiorec)
{
navigator.mediaDevices.getUserMedia({ audio: true }).then(function(stream) {
audiorec = new MediaRecorder(stream, settings.audiosettings);
audiorec.addEventListener('dataavailable', function(e) {
if (e.data.size > 0) audiochunks.push(e.data);
if (audiorec.state === 'inactive')
{
var blob = new Blob(audiochunks, { type: 'audio/mp3' });
blob.lastModifiedDate = new Date();
blob.lastModified = Math.floor(blob.lastModifiedDate.getTime() / 1000);
blob.name = FormatStr(Translate('Audio recording - {0}.mp3'), blob.lastModifiedDate.toLocaleString());
fileinput.fileupload('add', { files: [blob] });
stream.getTracks().forEach(function(track) {
track.stop();
});
audiobutton.removeClass('ff_fileupload_recording');
audiochunks = [];
audiorec = null;
}
});
audiorec.start();
audiobutton.addClass('ff_fileupload_recording');
}).catch(function(e) {
alert(Translate('Unable to record audio. Either a microphone was not found or access was denied.'));
});
}
else
{
audiorec.stop();
}
});
}
// Record video.
if (settings.recordvideo && navigator.mediaDevices && window.MediaRecorder)
{
var videobutton = $('<button>').addClass('ff_fileupload_dropzone_tool').addClass('ff_fileupload_recordvideo').attr('type', 'button').attr('aria-label', Translate('Record video using a camera'));
dropzonetools.append(videobutton);
var videorecpreview = $('<video>').prop('muted', true).prop('autoplay', true).addClass('ff_fileupload_recordvideo_preview').addClass('ff_fileupload_hidden');
dropzonewrap.append(videorecpreview);
var videorec = null;
var videochunks = [];
videobutton.click(function(e) {
e.preventDefault();
if (!videorec)
{
var streamhandler = function(stream) {
videorec = new MediaRecorder(stream, settings.videosettings);
videorec.addEventListener('dataavailable', function(e) {
if (e.data.size > 0) videochunks.push(e.data);
if (videorec.state === 'inactive')
{
var blob = new Blob(videochunks, { type: 'video/mp4' });
blob.lastModifiedDate = new Date();
blob.lastModified = Math.floor(blob.lastModifiedDate.getTime() / 1000);
blob.name = FormatStr(Translate('Video recording - {0}.mp4'), blob.lastModifiedDate.toLocaleString());
fileinput.fileupload('add', { files: [blob] });
stream.getTracks().forEach(function(track) {
track.stop();
});
videobutton.removeClass('ff_fileupload_recording');
videorecpreview.addClass('ff_fileupload_hidden');
if (videorecpreview[0].src !== '') videorecpreview[0].src = '';
videorecpreview[0].srcObject = null;
videochunks = [];
videorec = null;
}
});
videorec.start();
videobutton.addClass('ff_fileupload_recording');
// Display a preview box with just the video stream.
try { videorecpreview[0].src = URL.createObjectURL(stream); } catch(e) { videorecpreview[0].srcObject = stream; }
videorecpreview.removeClass('ff_fileupload_hidden');
};
// Video with audio (e.g. webcam) with fallback to video only (e.g. some screen recording codecs).
navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then(streamhandler).catch(function(e) {
navigator.mediaDevices.getUserMedia({ video: true }).then(streamhandler).catch(function(e) {
alert(Translate('Unable to record video. Either a camera was not found or access was denied.'));
});
});
}
else
{
videorec.stop();
}
});
}
// Add a table to track unprocessed and in-progress uploads.
var uploads = $('<table>').addClass('ff_fileupload_uploads');
fileuploadwrap.append(uploads);
// Hide the starting element.
$this.addClass('ff_fileupload_hidden');
// Initialize jQuery File Upload using the hidden form and visible dropzone.
var baseoptions = {
url: settings.url,
dataType: 'json',
pasteZone: dropzonewrap,
limitConcurrentUploads: 2
};
// Immutable options.
var immutableoptions = {
singleFileUploads: true,
dropZone: dropzone,
add: function(e, data) { AddFile(uploads, e, data) },
progress: UploadProgress,
fail: UploadFailed,
done: UploadDone,
chunksend: UploadChunkSend,
chunkdone: UploadChunkDone
};
// The user interface requires certain options to be set correctly.
fileinput.fileupload($.extend(baseoptions, settings.fileupload, immutableoptions));
// Save necessary information in case the uploader is destroyed later.
$this.data('fancy-fileupload', {
'fileuploadwrap' : fileuploadwrap,
'form' : form,
'settings': settings
});
// Post-initialization callback.
if (settings.postinit) settings.postinit.call($this);
});
}
$.fn.FancyFileUpload.defaults = {
'url' : '',
'params' : {},
'edit' : true,
'maxfilesize' : -1,
'accept' : null,
'displayunits' : 'iec_windows',
'adjustprecision' : true,
'retries' : 5,
'retrydelay' : 500,
'recordaudio' : false,
'audiosettings' : {},
'recordvideo' : false,
'videosettings' : {},
'preinit' : null,
'postinit' : null,
'added' : null,
'showpreview' : null,
'hidepreview' : null,
'startupload' : null,
'continueupload' : null,
'uploadcancelled' : null,
'uploadcompleted' : null,
'fileupload' : {},
'langmap' : {}
};
}(jQuery));

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,221 @@
/*
* jQuery Iframe Transport Plugin
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*/
/* global define, require */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(require('jquery'));
} else {
// Browser globals:
factory(window.jQuery);
}
})(function ($) {
'use strict';
// Helper variable to create unique names for the transport iframes:
var counter = 0,
jsonAPI = $,
jsonParse = 'parseJSON';
if ('JSON' in window && 'parse' in JSON) {
jsonAPI = JSON;
jsonParse = 'parse';
}
// The iframe transport accepts four additional options:
// options.fileInput: a jQuery collection of file input fields
// options.paramName: the parameter name for the file form data,
// overrides the name property of the file input field(s),
// can be a string or an array of strings.
// options.formData: an array of objects with name and value properties,
// equivalent to the return data of .serializeArray(), e.g.:
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
// options.initialIframeSrc: the URL of the initial iframe src,
// by default set to "javascript:false;"
$.ajaxTransport('iframe', function (options) {
if (options.async) {
// javascript:false as initial iframe src
// prevents warning popups on HTTPS in IE6:
// eslint-disable-next-line no-script-url
var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
form,
iframe,
addParamChar;
return {
send: function (_, completeCallback) {
form = $('<form style="display:none;"></form>');
form.attr('accept-charset', options.formAcceptCharset);
addParamChar = /\?/.test(options.url) ? '&' : '?';
// XDomainRequest only supports GET and POST:
if (options.type === 'DELETE') {
options.url = options.url + addParamChar + '_method=DELETE';
options.type = 'POST';
} else if (options.type === 'PUT') {
options.url = options.url + addParamChar + '_method=PUT';
options.type = 'POST';
} else if (options.type === 'PATCH') {
options.url = options.url + addParamChar + '_method=PATCH';
options.type = 'POST';
}
// IE versions below IE8 cannot set the name property of
// elements that have already been added to the DOM,
// so we set the name along with the iframe HTML markup:
counter += 1;
iframe = $(
'<iframe src="' +
initialIframeSrc +
'" name="iframe-transport-' +
counter +
'"></iframe>'
).on('load', function () {
var fileInputClones,
paramNames = $.isArray(options.paramName)
? options.paramName
: [options.paramName];
iframe.off('load').on('load', function () {
var response;
// Wrap in a try/catch block to catch exceptions thrown
// when trying to access cross-domain iframe contents:
try {
response = iframe.contents();
// Google Chrome and Firefox do not throw an
// exception when calling iframe.contents() on
// cross-domain requests, so we unify the response:
if (!response.length || !response[0].firstChild) {
throw new Error();
}
} catch (e) {
response = undefined;
}
// The complete callback returns the
// iframe content document as response object:
completeCallback(200, 'success', { iframe: response });
// Fix for IE endless progress bar activity bug
// (happens on form submits to iframe targets):
$('<iframe src="' + initialIframeSrc + '"></iframe>').appendTo(
form
);
window.setTimeout(function () {
// Removing the form in a setTimeout call
// allows Chrome's developer tools to display
// the response result
form.remove();
}, 0);
});
form
.prop('target', iframe.prop('name'))
.prop('action', options.url)
.prop('method', options.type);
if (options.formData) {
$.each(options.formData, function (index, field) {
$('<input type="hidden"/>')
.prop('name', field.name)
.val(field.value)
.appendTo(form);
});
}
if (
options.fileInput &&
options.fileInput.length &&
options.type === 'POST'
) {
fileInputClones = options.fileInput.clone();
// Insert a clone for each file input field:
options.fileInput.after(function (index) {
return fileInputClones[index];
});
if (options.paramName) {
options.fileInput.each(function (index) {
$(this).prop('name', paramNames[index] || options.paramName);
});
}
// Appending the file input fields to the hidden form
// removes them from their original location:
form
.append(options.fileInput)
.prop('enctype', 'multipart/form-data')
// enctype must be set as encoding for IE:
.prop('encoding', 'multipart/form-data');
// Remove the HTML5 form attribute from the input(s):
options.fileInput.removeAttr('form');
}
form.submit();
// Insert the file input fields at their original location
// by replacing the clones with the originals:
if (fileInputClones && fileInputClones.length) {
options.fileInput.each(function (index, input) {
var clone = $(fileInputClones[index]);
// Restore the original name and form properties:
$(input)
.prop('name', clone.prop('name'))
.attr('form', clone.attr('form'));
clone.replaceWith(input);
});
}
});
form.append(iframe).appendTo(document.body);
},
abort: function () {
if (iframe) {
// javascript:false as iframe src aborts the request
// and prevents warning popups on HTTPS in IE6.
iframe.off('load').prop('src', initialIframeSrc);
}
if (form) {
form.remove();
}
}
};
}
});
// The iframe transport returns the iframe content document as response.
// The following adds converters from iframe to text, json, html, xml
// and script.
// Please note that the Content-Type for JSON responses has to be text/plain
// or text/html, if the browser doesn't include application/json in the
// Accept header, else IE will show a download dialog.
// The Content-Type for XML responses on the other hand has to be always
// application/xml or text/xml, so IE properly parses the XML response.
// See also
// https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
$.ajaxSetup({
converters: {
'iframe text': function (iframe) {
return iframe && $(iframe[0].body).text();
},
'iframe json': function (iframe) {
return iframe && jsonAPI[jsonParse]($(iframe[0].body).text());
},
'iframe html': function (iframe) {
return iframe && $(iframe[0].body).html();
},
'iframe xml': function (iframe) {
var xmlDoc = iframe && iframe[0];
return xmlDoc && $.isXMLDoc(xmlDoc)
? xmlDoc
: $.parseXML(
(xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
$(xmlDoc.body).html()
);
},
'iframe script': function (iframe) {
return iframe && $.globalEval($(iframe[0].body).text());
}
}
});
});

View File

@@ -0,0 +1,808 @@
/*! jQuery UI - v1.12.1+0b7246b6eeadfa9e2696e22f3230f6452f8129dc - 2020-02-20
* http://jqueryui.com
* Includes: widget.js
* Copyright jQuery Foundation and other contributors; Licensed MIT */
/* global define, require */
/* eslint-disable no-param-reassign, new-cap, jsdoc/require-jsdoc */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(window.jQuery);
}
})(function ($) {
('use strict');
$.ui = $.ui || {};
$.ui.version = '1.12.1';
/*!
* jQuery UI Widget 1.12.1
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
//>>label: Widget
//>>group: Core
//>>description: Provides a factory for creating stateful widgets with a common API.
//>>docs: http://api.jqueryui.com/jQuery.widget/
//>>demos: http://jqueryui.com/widget/
// Support: jQuery 1.9.x or older
// $.expr[ ":" ] is deprecated.
if (!$.expr.pseudos) {
$.expr.pseudos = $.expr[':'];
}
// Support: jQuery 1.11.x or older
// $.unique has been renamed to $.uniqueSort
if (!$.uniqueSort) {
$.uniqueSort = $.unique;
}
var widgetUuid = 0;
var widgetHasOwnProperty = Array.prototype.hasOwnProperty;
var widgetSlice = Array.prototype.slice;
$.cleanData = (function (orig) {
return function (elems) {
var events, elem, i;
// eslint-disable-next-line eqeqeq
for (i = 0; (elem = elems[i]) != null; i++) {
// Only trigger remove when necessary to save time
events = $._data(elem, 'events');
if (events && events.remove) {
$(elem).triggerHandler('remove');
}
}
orig(elems);
};
})($.cleanData);
$.widget = function (name, base, prototype) {
var existingConstructor, constructor, basePrototype;
// ProxiedPrototype allows the provided prototype to remain unmodified
// so that it can be used as a mixin for multiple widgets (#8876)
var proxiedPrototype = {};
var namespace = name.split('.')[0];
name = name.split('.')[1];
var fullName = namespace + '-' + name;
if (!prototype) {
prototype = base;
base = $.Widget;
}
if ($.isArray(prototype)) {
prototype = $.extend.apply(null, [{}].concat(prototype));
}
// Create selector for plugin
$.expr.pseudos[fullName.toLowerCase()] = function (elem) {
return !!$.data(elem, fullName);
};
$[namespace] = $[namespace] || {};
existingConstructor = $[namespace][name];
constructor = $[namespace][name] = function (options, element) {
// Allow instantiation without "new" keyword
if (!this._createWidget) {
return new constructor(options, element);
}
// Allow instantiation without initializing for simple inheritance
// must use "new" keyword (the code above always passes args)
if (arguments.length) {
this._createWidget(options, element);
}
};
// Extend with the existing constructor to carry over any static properties
$.extend(constructor, existingConstructor, {
version: prototype.version,
// Copy the object used to create the prototype in case we need to
// redefine the widget later
_proto: $.extend({}, prototype),
// Track widgets that inherit from this widget in case this widget is
// redefined after a widget inherits from it
_childConstructors: []
});
basePrototype = new base();
// We need to make the options hash a property directly on the new instance
// otherwise we'll modify the options hash on the prototype that we're
// inheriting from
basePrototype.options = $.widget.extend({}, basePrototype.options);
$.each(prototype, function (prop, value) {
if (!$.isFunction(value)) {
proxiedPrototype[prop] = value;
return;
}
proxiedPrototype[prop] = (function () {
function _super() {
return base.prototype[prop].apply(this, arguments);
}
function _superApply(args) {
return base.prototype[prop].apply(this, args);
}
return function () {
var __super = this._super;
var __superApply = this._superApply;
var returnValue;
this._super = _super;
this._superApply = _superApply;
returnValue = value.apply(this, arguments);
this._super = __super;
this._superApply = __superApply;
return returnValue;
};
})();
});
constructor.prototype = $.widget.extend(
basePrototype,
{
// TODO: remove support for widgetEventPrefix
// always use the name + a colon as the prefix, e.g., draggable:start
// don't prefix for widgets that aren't DOM-based
widgetEventPrefix: existingConstructor
? basePrototype.widgetEventPrefix || name
: name
},
proxiedPrototype,
{
constructor: constructor,
namespace: namespace,
widgetName: name,
widgetFullName: fullName
}
);
// If this widget is being redefined then we need to find all widgets that
// are inheriting from it and redefine all of them so that they inherit from
// the new version of this widget. We're essentially trying to replace one
// level in the prototype chain.
if (existingConstructor) {
$.each(existingConstructor._childConstructors, function (i, child) {
var childPrototype = child.prototype;
// Redefine the child widget using the same prototype that was
// originally used, but inherit from the new version of the base
$.widget(
childPrototype.namespace + '.' + childPrototype.widgetName,
constructor,
child._proto
);
});
// Remove the list of existing child constructors from the old constructor
// so the old child constructors can be garbage collected
delete existingConstructor._childConstructors;
} else {
base._childConstructors.push(constructor);
}
$.widget.bridge(name, constructor);
return constructor;
};
$.widget.extend = function (target) {
var input = widgetSlice.call(arguments, 1);
var inputIndex = 0;
var inputLength = input.length;
var key;
var value;
for (; inputIndex < inputLength; inputIndex++) {
for (key in input[inputIndex]) {
value = input[inputIndex][key];
if (
widgetHasOwnProperty.call(input[inputIndex], key) &&
value !== undefined
) {
// Clone objects
if ($.isPlainObject(value)) {
target[key] = $.isPlainObject(target[key])
? $.widget.extend({}, target[key], value)
: // Don't extend strings, arrays, etc. with objects
$.widget.extend({}, value);
// Copy everything else by reference
} else {
target[key] = value;
}
}
}
}
return target;
};
$.widget.bridge = function (name, object) {
var fullName = object.prototype.widgetFullName || name;
$.fn[name] = function (options) {
var isMethodCall = typeof options === 'string';
var args = widgetSlice.call(arguments, 1);
var returnValue = this;
if (isMethodCall) {
// If this is an empty collection, we need to have the instance method
// return undefined instead of the jQuery instance
if (!this.length && options === 'instance') {
returnValue = undefined;
} else {
this.each(function () {
var methodValue;
var instance = $.data(this, fullName);
if (options === 'instance') {
returnValue = instance;
return false;
}
if (!instance) {
return $.error(
'cannot call methods on ' +
name +
' prior to initialization; ' +
"attempted to call method '" +
options +
"'"
);
}
if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
return $.error(
"no such method '" +
options +
"' for " +
name +
' widget instance'
);
}
methodValue = instance[options].apply(instance, args);
if (methodValue !== instance && methodValue !== undefined) {
returnValue =
methodValue && methodValue.jquery
? returnValue.pushStack(methodValue.get())
: methodValue;
return false;
}
});
}
} else {
// Allow multiple hashes to be passed on init
if (args.length) {
options = $.widget.extend.apply(null, [options].concat(args));
}
this.each(function () {
var instance = $.data(this, fullName);
if (instance) {
instance.option(options || {});
if (instance._init) {
instance._init();
}
} else {
$.data(this, fullName, new object(options, this));
}
});
}
return returnValue;
};
};
$.Widget = function (/* options, element */) {};
$.Widget._childConstructors = [];
$.Widget.prototype = {
widgetName: 'widget',
widgetEventPrefix: '',
defaultElement: '<div>',
options: {
classes: {},
disabled: false,
// Callbacks
create: null
},
_createWidget: function (options, element) {
element = $(element || this.defaultElement || this)[0];
this.element = $(element);
this.uuid = widgetUuid++;
this.eventNamespace = '.' + this.widgetName + this.uuid;
this.bindings = $();
this.hoverable = $();
this.focusable = $();
this.classesElementLookup = {};
if (element !== this) {
$.data(element, this.widgetFullName, this);
this._on(true, this.element, {
remove: function (event) {
if (event.target === element) {
this.destroy();
}
}
});
this.document = $(
element.style
? // Element within the document
element.ownerDocument
: // Element is window or document
element.document || element
);
this.window = $(
this.document[0].defaultView || this.document[0].parentWindow
);
}
this.options = $.widget.extend(
{},
this.options,
this._getCreateOptions(),
options
);
this._create();
if (this.options.disabled) {
this._setOptionDisabled(this.options.disabled);
}
this._trigger('create', null, this._getCreateEventData());
this._init();
},
_getCreateOptions: function () {
return {};
},
_getCreateEventData: $.noop,
_create: $.noop,
_init: $.noop,
destroy: function () {
var that = this;
this._destroy();
$.each(this.classesElementLookup, function (key, value) {
that._removeClass(value, key);
});
// We can probably remove the unbind calls in 2.0
// all event bindings should go through this._on()
this.element.off(this.eventNamespace).removeData(this.widgetFullName);
this.widget().off(this.eventNamespace).removeAttr('aria-disabled');
// Clean up events and states
this.bindings.off(this.eventNamespace);
},
_destroy: $.noop,
widget: function () {
return this.element;
},
option: function (key, value) {
var options = key;
var parts;
var curOption;
var i;
if (arguments.length === 0) {
// Don't return a reference to the internal hash
return $.widget.extend({}, this.options);
}
if (typeof key === 'string') {
// Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
options = {};
parts = key.split('.');
key = parts.shift();
if (parts.length) {
curOption = options[key] = $.widget.extend({}, this.options[key]);
for (i = 0; i < parts.length - 1; i++) {
curOption[parts[i]] = curOption[parts[i]] || {};
curOption = curOption[parts[i]];
}
key = parts.pop();
if (arguments.length === 1) {
return curOption[key] === undefined ? null : curOption[key];
}
curOption[key] = value;
} else {
if (arguments.length === 1) {
return this.options[key] === undefined ? null : this.options[key];
}
options[key] = value;
}
}
this._setOptions(options);
return this;
},
_setOptions: function (options) {
var key;
for (key in options) {
this._setOption(key, options[key]);
}
return this;
},
_setOption: function (key, value) {
if (key === 'classes') {
this._setOptionClasses(value);
}
this.options[key] = value;
if (key === 'disabled') {
this._setOptionDisabled(value);
}
return this;
},
_setOptionClasses: function (value) {
var classKey, elements, currentElements;
for (classKey in value) {
currentElements = this.classesElementLookup[classKey];
if (
value[classKey] === this.options.classes[classKey] ||
!currentElements ||
!currentElements.length
) {
continue;
}
// We are doing this to create a new jQuery object because the _removeClass() call
// on the next line is going to destroy the reference to the current elements being
// tracked. We need to save a copy of this collection so that we can add the new classes
// below.
elements = $(currentElements.get());
this._removeClass(currentElements, classKey);
// We don't use _addClass() here, because that uses this.options.classes
// for generating the string of classes. We want to use the value passed in from
// _setOption(), this is the new value of the classes option which was passed to
// _setOption(). We pass this value directly to _classes().
elements.addClass(
this._classes({
element: elements,
keys: classKey,
classes: value,
add: true
})
);
}
},
_setOptionDisabled: function (value) {
this._toggleClass(
this.widget(),
this.widgetFullName + '-disabled',
null,
!!value
);
// If the widget is becoming disabled, then nothing is interactive
if (value) {
this._removeClass(this.hoverable, null, 'ui-state-hover');
this._removeClass(this.focusable, null, 'ui-state-focus');
}
},
enable: function () {
return this._setOptions({ disabled: false });
},
disable: function () {
return this._setOptions({ disabled: true });
},
_classes: function (options) {
var full = [];
var that = this;
options = $.extend(
{
element: this.element,
classes: this.options.classes || {}
},
options
);
function bindRemoveEvent() {
options.element.each(function (_, element) {
var isTracked = $.map(that.classesElementLookup, function (elements) {
return elements;
}).some(function (elements) {
return elements.is(element);
});
if (!isTracked) {
that._on($(element), {
remove: '_untrackClassesElement'
});
}
});
}
function processClassString(classes, checkOption) {
var current, i;
for (i = 0; i < classes.length; i++) {
current = that.classesElementLookup[classes[i]] || $();
if (options.add) {
bindRemoveEvent();
current = $(
$.uniqueSort(current.get().concat(options.element.get()))
);
} else {
current = $(current.not(options.element).get());
}
that.classesElementLookup[classes[i]] = current;
full.push(classes[i]);
if (checkOption && options.classes[classes[i]]) {
full.push(options.classes[classes[i]]);
}
}
}
if (options.keys) {
processClassString(options.keys.match(/\S+/g) || [], true);
}
if (options.extra) {
processClassString(options.extra.match(/\S+/g) || []);
}
return full.join(' ');
},
_untrackClassesElement: function (event) {
var that = this;
$.each(that.classesElementLookup, function (key, value) {
if ($.inArray(event.target, value) !== -1) {
that.classesElementLookup[key] = $(value.not(event.target).get());
}
});
this._off($(event.target));
},
_removeClass: function (element, keys, extra) {
return this._toggleClass(element, keys, extra, false);
},
_addClass: function (element, keys, extra) {
return this._toggleClass(element, keys, extra, true);
},
_toggleClass: function (element, keys, extra, add) {
add = typeof add === 'boolean' ? add : extra;
var shift = typeof element === 'string' || element === null,
options = {
extra: shift ? keys : extra,
keys: shift ? element : keys,
element: shift ? this.element : element,
add: add
};
options.element.toggleClass(this._classes(options), add);
return this;
},
_on: function (suppressDisabledCheck, element, handlers) {
var delegateElement;
var instance = this;
// No suppressDisabledCheck flag, shuffle arguments
if (typeof suppressDisabledCheck !== 'boolean') {
handlers = element;
element = suppressDisabledCheck;
suppressDisabledCheck = false;
}
// No element argument, shuffle and use this.element
if (!handlers) {
handlers = element;
element = this.element;
delegateElement = this.widget();
} else {
element = delegateElement = $(element);
this.bindings = this.bindings.add(element);
}
$.each(handlers, function (event, handler) {
function handlerProxy() {
// Allow widgets to customize the disabled handling
// - disabled as an array instead of boolean
// - disabled class as method for disabling individual parts
if (
!suppressDisabledCheck &&
(instance.options.disabled === true ||
$(this).hasClass('ui-state-disabled'))
) {
return;
}
return (typeof handler === 'string'
? instance[handler]
: handler
).apply(instance, arguments);
}
// Copy the guid so direct unbinding works
if (typeof handler !== 'string') {
handlerProxy.guid = handler.guid =
handler.guid || handlerProxy.guid || $.guid++;
}
var match = event.match(/^([\w:-]*)\s*(.*)$/);
var eventName = match[1] + instance.eventNamespace;
var selector = match[2];
if (selector) {
delegateElement.on(eventName, selector, handlerProxy);
} else {
element.on(eventName, handlerProxy);
}
});
},
_off: function (element, eventName) {
eventName =
(eventName || '').split(' ').join(this.eventNamespace + ' ') +
this.eventNamespace;
element.off(eventName);
// Clear the stack to avoid memory leaks (#10056)
this.bindings = $(this.bindings.not(element).get());
this.focusable = $(this.focusable.not(element).get());
this.hoverable = $(this.hoverable.not(element).get());
},
_delay: function (handler, delay) {
var instance = this;
function handlerProxy() {
return (typeof handler === 'string'
? instance[handler]
: handler
).apply(instance, arguments);
}
return setTimeout(handlerProxy, delay || 0);
},
_hoverable: function (element) {
this.hoverable = this.hoverable.add(element);
this._on(element, {
mouseenter: function (event) {
this._addClass($(event.currentTarget), null, 'ui-state-hover');
},
mouseleave: function (event) {
this._removeClass($(event.currentTarget), null, 'ui-state-hover');
}
});
},
_focusable: function (element) {
this.focusable = this.focusable.add(element);
this._on(element, {
focusin: function (event) {
this._addClass($(event.currentTarget), null, 'ui-state-focus');
},
focusout: function (event) {
this._removeClass($(event.currentTarget), null, 'ui-state-focus');
}
});
},
_trigger: function (type, event, data) {
var prop, orig;
var callback = this.options[type];
data = data || {};
event = $.Event(event);
event.type = (type === this.widgetEventPrefix
? type
: this.widgetEventPrefix + type
).toLowerCase();
// The original event may come from any element
// so we need to reset the target on the new event
event.target = this.element[0];
// Copy original event properties over to the new event
orig = event.originalEvent;
if (orig) {
for (prop in orig) {
if (!(prop in event)) {
event[prop] = orig[prop];
}
}
}
this.element.trigger(event, data);
return !(
($.isFunction(callback) &&
callback.apply(this.element[0], [event].concat(data)) === false) ||
event.isDefaultPrevented()
);
}
};
$.each({ show: 'fadeIn', hide: 'fadeOut' }, function (method, defaultEffect) {
$.Widget.prototype['_' + method] = function (element, options, callback) {
if (typeof options === 'string') {
options = { effect: options };
}
var hasOptions;
var effectName = !options
? method
: options === true || typeof options === 'number'
? defaultEffect
: options.effect || defaultEffect;
options = options || {};
if (typeof options === 'number') {
options = { duration: options };
}
hasOptions = !$.isEmptyObject(options);
options.complete = callback;
if (options.delay) {
element.delay(options.delay);
}
if (hasOptions && $.effects && $.effects.effect[effectName]) {
element[method](options);
} else if (effectName !== method && element[effectName]) {
element[effectName](options.duration, options.easing, callback);
} else {
element.queue(function (next) {
$(this)[method]();
if (callback) {
callback.call(element[0]);
}
next();
});
}
};
});
});

View File

@@ -0,0 +1,86 @@
// German translation provided courtesy of GitHub user Woersty.
// (C) 2021 CubicleSoft. All Rights Reserved.
if (!$.fn.FancyFileUpload.langs) $.fn.FancyFileUpload.langs = {};
$.fn.FancyFileUpload.langs['de'] = {
'Start uploading':
'Starte Hochladen',
'Starting upload...':
'Hochladen gestartet...',
'Upload completed':
'Hochladen erfolgreich',
'There is a file upload still in progress. Leaving the page will cancel the upload.\n\nAre you sure you want to leave this page?':
'Es wird gerade eine Datei hochgeladen. Das Verlassen der Seite bricht das Hochladen ab.\n\nBist du sicher, dass du gehen willst?',
'There is a file that was added to the queue but the upload has not been started. Leaving the page will clear the queue and not upload the file.\n\nAre you sure you want to leave this page?':
'Es wurde eine Datei zur Warteschlange hinzugefügt aber noch nicht hochgeladen. Das Verlassen der Seite leert die Warteschlange und die Datei wird nicht hochgeladen.\n\nBist du sicher, dass du gehen willst?',
'Cancel upload and remove from list':
'Breche Hochladen ab und entferne Datei aus der Liste.',
'This file is currently being uploaded.\n\nStop the upload and remove the file from the list?':
'Die Datei wird gerade hochgeladen.\n\nHochladen stoppen und Datei aus der Liste entfernen?',
'This file is waiting to start.\n\nCancel the operation and remove the file from the list?':
'Die Datei wartet auf ihren Start.\n\nOperation abbrechen und Datei aus der Liste entfernen?',
'Preview':
'Vorschau',
'No preview available':
'Keine Vorschau verfügbar',
'Invalid file extension.':
'Ungültige Dateiendung.',
'File is too large. Maximum file size is {0}.':
'Datei zu groß. Die maximal erlaubte Größe ist {0}.',
'Remove from list':
'Aus der Liste entfernen',
'{0} of {1} | {2}%':
'{0} von {1} | {2}%',
'{0} | Network error, retrying in a moment... ({1})':
'{0} | Netzwerkfehler, ich versuche es gleich nochmal... ({1})',
'The upload was cancelled.':
'Das Hochladen wurde abgebrochen.',
'The upload failed. {0} ({1})':
'Das Hochladen ist fehlgeschlagen. {0} ({1})',
'The upload failed.':
'Das Hochladen ist fehlgeschlagen.',
'The server indicated that the upload was not successful. No additional information available.':
'Der Server meldet, dass das Hochladen fehlgeschlagen ist. Keine weiteren Details bekannt.',
'Browse, drag-and-drop, or paste files to upload':
'Durchsuchen, Drag & Drop oder Einfügen zum Hochladen',
'Record audio using a microphone':
'Ton aufnehmen (Mikro)',
'Audio recording - {0}.mp3':
'Tonaufnahme - {0}.mp3',
'Unable to record audio. Either a microphone was not found or access was denied.':
'Kann keine Tonaufnahme machen. Kein Mikrofon oder keinen Zugriff darauf.',
'Record video using a camera':
'Video aufnehmen (Kamera)',
'Video recording - {0}.mp4':
'Videoaufnahme - {0}.mp4',
'Unable to record video. Either a camera was not found or access was denied.':
'Kann keine Videoaufnahme machen. Keine Kamera oder keinen Zugriff darauf.'
};
$.fn.FancyFileUpload.defaults.langmap = $.fn.FancyFileUpload.langs['de'];

View File

@@ -0,0 +1,86 @@
// French translation provided courtesy of GitHub user tuxfamily.
// (C) 2022 CubicleSoft. All Rights Reserved.
if (!$.fn.FancyFileUpload.langs) $.fn.FancyFileUpload.langs = {};
$.fn.FancyFileUpload.langs['fr'] = {
'Start uploading':
'Démarrer le transfert',
'Starting upload...':
'Démarrage du transfert...',
'Upload completed':
'Transfert terminé',
'There is a file upload still in progress. Leaving the page will cancel the upload.\n\nAre you sure you want to leave this page?':
'Un transfert de fichier est toujours en cours. Si vous quittez la page, il sera annulé.\n\nVoulez-vous vraiment quitter cette page ?',
'There is a file that was added to the queue but the upload has not been started. Leaving the page will clear the queue and not upload the file.\n\nAre you sure you want to leave this page?':
'Un fichier a été ajouté à la file d\'attente, mais le transfert n\'a pas démarré. Quitter la page effacera la file d\'attente et ne téléversera pas le fichier.\n\nVoulez- vous vraiment quitter cette page ?',
'Cancel upload and remove from list':
'Annuler le transfert et le supprimer de la liste',
'This file is currently being uploaded.\n\nStop the upload and remove the file from the list?':
'Ce fichier est en cours de transfert.\n\nArrêter le transfert et supprimer le fichier de la liste ?',
'This file is waiting to start.\n\nCancel the operation and remove the file from the list?':
'Ce fichier est en attente de transfert.\n\nAnnuler l\'opération et supprimer le fichier de la liste ?',
'Preview':
'Aperçu',
'No preview available':
'Aucun aperçu disponible',
'Invalid file extension.':
'Extension de fichier invalide.',
'File is too large. Maximum file size is {0}.':
'Fichier trop volumineux. Le poids maximum acceptée est de {0}.',
'Remove from list':
'Retirer de la liste',
'{0} of {1} | {2}%':
'{0} sur {1} | {2}%',
'{0} | Network error, retrying in a moment... ({1})':
'{0} | Erreur réseau, nouvelle tentative dans un instant... ({1})',
'The upload was cancelled.':
'Le transfert a été annulé.',
'The upload failed. {0} ({1})':
'Le transfert a échoué. {0} ({1})',
'The upload failed.':
'Le transfert a échoué.',
'The server indicated that the upload was not successful. No additional information available.':
'Le serveur a indiqué que le transfert a échoué sans donner d\'informations supplémentaires.',
'Browse, drag-and-drop, or paste files to upload':
'Parcourir, glisser-déposer ou coller des fichiers à transférer',
'Record audio using a microphone':
'Enregistrer de l\'audio à l\'aide d\'un microphone',
'Audio recording - {0}.mp3':
'Enregistrement audio - {0}.mp3',
'Unable to record audio. Either a microphone was not found or access was denied.':
'Impossible d\'enregistrer le son. Soit le microphone n\'a pas été trouvé, soit son accès a été refusé.',
'Record video using a camera':
'Enregistrer une vidéo à l\'aide d\'une caméra',
'Video recording - {0}.mp4':
'Enregistrement vidéo - {0}.mp4',
'Unable to record video. Either a camera was not found or access was denied.':
'Impossible d\'enregistrer la vidéo. Soit la caméra n\'a pas été trouvée, soit son accès a été refusé.'
};
$.fn.FancyFileUpload.defaults.langmap = $.fn.FancyFileUpload.langs['fr'];

View File

@@ -0,0 +1,277 @@
<?php
// Fancy File Uploader helper class. Combines some useful functions from FlexForms and FlexForms Modules.
// (C) 2021 CubicleSoft. All Rights Reserved.
class FancyFileUploaderHelper
{
// Copy included for class self-containment.
// Makes an input filename safe for use.
// Allows a very limited number of characters through.
public static function FilenameSafe($filename)
{
return preg_replace('/\s+/', "-", trim(trim(preg_replace('/[^A-Za-z0-9_.\-]/', " ", $filename), ".")));
}
public static function NormalizeFiles($key)
{
$result = array();
if (isset($_FILES) && is_array($_FILES) && isset($_FILES[$key]) && is_array($_FILES[$key]))
{
$currfiles = $_FILES[$key];
if (isset($currfiles["name"]) && isset($currfiles["type"]) && isset($currfiles["tmp_name"]) && isset($currfiles["error"]) && isset($currfiles["size"]))
{
if (is_string($currfiles["name"]))
{
$currfiles["name"] = array($currfiles["name"]);
$currfiles["type"] = array($currfiles["type"]);
$currfiles["tmp_name"] = array($currfiles["tmp_name"]);
$currfiles["error"] = array($currfiles["error"]);
$currfiles["size"] = array($currfiles["size"]);
}
$y = count($currfiles["name"]);
for ($x = 0; $x < $y; $x++)
{
if ($currfiles["error"][$x] != 0)
{
switch ($currfiles["error"][$x])
{
case 1: $msg = "The uploaded file exceeds the 'upload_max_filesize' directive in 'php.ini'."; $code = "upload_err_ini_size"; break;
case 2: $msg = "The uploaded file exceeds the 'MAX_FILE_SIZE' directive that was specified in the submitted form."; $code = "upload_err_form_size"; break;
case 3: $msg = "The uploaded file was only partially uploaded."; $code = "upload_err_partial"; break;
case 4: $msg = "No file was uploaded."; $code = "upload_err_no_file"; break;
case 6: $msg = "The configured temporary folder on the server is missing."; $code = "upload_err_no_tmp_dir"; break;
case 7: $msg = "Unable to write the temporary file to disk. The server is out of disk space, incorrectly configured, or experiencing hardware issues."; $code = "upload_err_cant_write"; break;
case 8: $msg = "A PHP extension stopped the upload."; $code = "upload_err_extension"; break;
default: $msg = "An unknown error occurred."; $code = "upload_err_unknown"; break;
}
$entry = array(
"success" => false,
"error" => self::FFTranslate($msg),
"errorcode" => $code
);
}
else if (!is_uploaded_file($currfiles["tmp_name"][$x]))
{
$entry = array(
"success" => false,
"error" => self::FFTranslate("The specified input filename was not uploaded to this server."),
"errorcode" => "invalid_input_filename"
);
}
else
{
$currfiles["name"][$x] = self::FilenameSafe($currfiles["name"][$x]);
$pos = strrpos($currfiles["name"][$x], ".");
$fileext = ($pos !== false ? (string)substr($currfiles["name"][$x], $pos + 1) : "");
$entry = array(
"success" => true,
"file" => $currfiles["tmp_name"][$x],
"name" => $currfiles["name"][$x],
"ext" => $fileext,
"type" => $currfiles["type"][$x],
"size" => $currfiles["size"][$x]
);
}
$result[] = $entry;
}
}
}
return $result;
}
public static function GetMaxUploadFileSize()
{
$maxpostsize = floor(self::ConvertUserStrToBytes(ini_get("post_max_size")) * 3 / 4);
if ($maxpostsize > 4096) $maxpostsize -= 4096;
$maxuploadsize = self::ConvertUserStrToBytes(ini_get("upload_max_filesize"));
if ($maxuploadsize < 1) $maxuploadsize = ($maxpostsize < 1 ? -1 : $maxpostsize);
return ($maxpostsize < 1 ? $maxuploadsize : min($maxpostsize, $maxuploadsize));
}
// Copy included for class self-containment.
public static function ConvertUserStrToBytes($str)
{
$str = trim($str);
$num = (double)$str;
if (strtoupper(substr($str, -1)) == "B") $str = substr($str, 0, -1);
switch (strtoupper(substr($str, -1)))
{
case "P": $num *= 1024;
case "T": $num *= 1024;
case "G": $num *= 1024;
case "M": $num *= 1024;
case "K": $num *= 1024;
}
return $num;
}
public static function GetChunkFilename()
{
if (isset($_SERVER["HTTP_CONTENT_DISPOSITION"]))
{
// Content-Disposition: attachment; filename="urlencodedstr"
$str = $_SERVER["HTTP_CONTENT_DISPOSITION"];
if (strtolower(substr($str, 0, 11)) === "attachment;")
{
$pos = strpos($str, "\"", 11);
$pos2 = strrpos($str, "\"");
if ($pos !== false && $pos2 !== false && $pos < $pos2)
{
$str = self::FilenameSafe(rawurldecode(substr($str, $pos + 1, $pos2 - $pos - 1)));
if ($str !== "") return $str;
}
}
}
return false;
}
public static function GetFileStartPosition()
{
if (isset($_SERVER["HTTP_CONTENT_RANGE"]) || isset($_SERVER["HTTP_RANGE"]))
{
// Content-Range: bytes (*|integer-integer)/(*|integer-integer)
$vals = explode(" ", preg_replace('/\s+/', " ", str_replace(",", "", (isset($_SERVER["HTTP_CONTENT_RANGE"]) ? $_SERVER["HTTP_CONTENT_RANGE"] : $_SERVER["HTTP_RANGE"]))));
if (count($vals) === 2 && strtolower($vals[0]) === "bytes")
{
$vals = explode("/", trim($vals[1]));
if (count($vals) === 2)
{
$vals = explode("-", trim($vals[0]));
if (count($vals) === 2) return (double)$vals[0];
}
}
}
return 0;
}
public static function HandleUpload($filekey, $options = array())
{
if (!isset($_REQUEST["fileuploader"]) && !isset($_POST["fileuploader"])) return array("success" => false, "error" => "No upload or missing 'fileuploader'.", "errorcode" => "no_upload");
if (isset($options["allowed_exts"]))
{
$allowedexts = array();
if (is_string($options["allowed_exts"])) $options["allowed_exts"] = explode(",", $options["allowed_exts"]);
foreach ($options["allowed_exts"] as $ext)
{
$ext = strtolower(trim(trim($ext), "."));
if ($ext !== "") $allowedexts[$ext] = true;
}
}
$files = self::NormalizeFiles($filekey);
if (!isset($files[0])) $result = array("success" => false, "error" => self::FFTranslate("File data was submitted but is missing."), "errorcode" => "bad_input");
else if (!$files[0]["success"]) $result = $files[0];
else if (isset($options["allowed_exts"]) && !isset($allowedexts[strtolower($files[0]["ext"])]))
{
$result = array(
"success" => false,
"error" => self::FFTranslate("Invalid file extension. Must be one of %s.", "'." . implode("', '.", array_keys($allowedexts)) . "'"),
"errorcode" => "invalid_file_ext"
);
}
else
{
// For chunked file uploads, get the current filename and starting position from the incoming headers.
$name = self::GetChunkFilename();
if ($name !== false)
{
$startpos = self::GetFileStartPosition();
$name = substr($name, 0, -(strlen($files[0]["ext"]) + 1));
if (isset($options["filename_callback"]) && is_callable($options["filename_callback"])) $filename = call_user_func_array($options["filename_callback"], array($name, strtolower($files[0]["ext"]), $files[0]));
else if (isset($options["filename"])) $filename = (isset($options["fixed_filename"]) && $options["fixed_filename"] ? $options["filename"] : str_replace(array("{name}", "{ext}"), array($name, strtolower($files[0]["ext"])), $options["filename"]));
else $filename = false;
if (!is_string($filename)) $result = array("success" => false, "error" => self::FFTranslate("The server did not set a valid filename."), "errorcode" => "invalid_filename");
else if (isset($options["limit"]) && $options["limit"] > -1 && $startpos + filesize($files[0]["file"]) > $options["limit"]) $result = array("success" => false, "error" => self::FFTranslate("The server file size limit was exceeded."), "errorcode" => "file_too_large");
else
{
if (file_exists($filename) && $startpos === filesize($filename)) $fp = @fopen($filename, "ab");
else
{
$fp = @fopen($filename, ($startpos > 0 && file_exists($filename) ? "r+b" : "wb"));
if ($fp !== false) @fseek($fp, $startpos, SEEK_SET);
}
$fp2 = @fopen($files[0]["file"], "rb");
if ($fp === false) $result = array("success" => false, "error" => self::FFTranslate("Unable to open a required file for writing."), "errorcode" => "open_failed", "info" => $filename);
else if ($fp2 === false) $result = array("success" => false, "error" => self::FFTranslate("Unable to open a required file for reading."), "errorcode" => "open_failed", "info" => $files[0]["file"]);
else
{
do
{
$data2 = @fread($fp2, 1048576);
if ($data2 == "") break;
@fwrite($fp, $data2);
} while (1);
fclose($fp2);
fclose($fp);
$result = array(
"success" => true
);
}
}
}
else
{
$name = substr($files[0]["name"], 0, -(strlen($files[0]["ext"]) + 1));
if (isset($options["filename_callback"]) && is_callable($options["filename_callback"])) $filename = call_user_func_array($options["filename_callback"], array($name, strtolower($files[0]["ext"]), $files[0]));
else if (isset($options["filename"])) $filename = (isset($options["fixed_filename"]) && $options["fixed_filename"] ? $options["filename"] : str_replace(array("{name}", "{ext}"), array($name, strtolower($files[0]["ext"])), $options["filename"]));
else $filename = false;
if (!is_string($filename)) $result = array("success" => false, "error" => self::FFTranslate("The server did not set a valid filename."), "errorcode" => "invalid_filename");
else if (isset($options["limit"]) && $options["limit"] > -1 && filesize($files[0]["file"]) > $options["limit"]) $result = array("success" => false, "error" => self::FFTranslate("The server file size limit was exceeded."), "errorcode" => "file_too_large");
else
{
@copy($files[0]["file"], $filename);
$result = array(
"success" => true
);
}
}
}
if ($result["success"] && isset($options["result_callback"]) && is_callable($options["result_callback"])) call_user_func_array($options["result_callback"], array(&$result, $filename, $name, strtolower($files[0]["ext"]), $files[0], (isset($options["result_callback_opts"]) ? $options["result_callback_opts"] : false)));
if (isset($options["return_result"]) && $options["return_result"]) return $result;
header("Content-Type: application/json");
echo json_encode($result, JSON_UNESCAPED_SLASHES);
exit();
}
public static function FFTranslate()
{
$args = func_get_args();
if (!count($args)) return "";
return call_user_func_array((defined("CS_TRANSLATE_FUNC") && function_exists(CS_TRANSLATE_FUNC) ? CS_TRANSLATE_FUNC : "sprintf"), $args);
}
}
?>

View File

@@ -0,0 +1,53 @@
<?php
// German translation provided courtesy of GitHub user Woersty.
// (C) 2021 CubicleSoft. All Rights Reserved.
if (!isset($langmap)) $langmap = array();
$langmap["de"] = array(
"The uploaded file exceeds the 'upload_max_filesize' directive in 'php.ini'." =>
"Die hochgeladene Datei ist größer als 'upload_max_filesize' in der 'php.ini'.",
"The uploaded file exceeds the 'MAX_FILE_SIZE' directive that was specified in the submitted form." =>
"Die hochgeladene Datei ist größer als 'MAX_FILE_SIZE' im Formular.",
"The uploaded file was only partially uploaded." =>
"Die Datei wurde nur teilweise hochgeladen.",
"No file was uploaded." =>
"Es wurde keine Datei hochgeladen.",
"The configured temporary folder on the server is missing." =>
"Der temporäre Ordner auf dem LoxBerry ist nicht vorhanden.",
"Unable to write the temporary file to disk. The server is out of disk space, incorrectly configured, or experiencing hardware issues." =>
"Kann die temporäre Datei nicht schreiben. Entweder ist Speicherplatz voll oder das Speichermedium defekt.",
"A PHP extension stopped the upload." =>
"Keine PHP Erweiterung stoppte das Hochladen.",
"An unknown error occurred." =>
"Ein unbekannter Fehler ist aufgetreten.",
"The specified input filename was not uploaded to this server." =>
"Der angegebene Dateiname wurde nicht auf diesen Server hochgeladen.",
"File data was submitted but is missing." =>
"Dateiinformationen wurden gesendet aber es fehlen Angaben.",
"Invalid file extension. Must be one of %s." =>
"Ungültige Dateiendung. Es muss eine von diesen sein %s.",
"The server did not set a valid filename." =>
"Der Server hat keinen gültigen Dateinamen gesendet.",
"The server file size limit was exceeded." =>
"Die Server Dateigrößenbeschränkung wurde überschritten.",
"Unable to open a required file for writing." =>
"Kann eine benötigte Datei nicht für den Schreibzugriff öffnen.",
"Unable to open a required file for reading." =>
"Kann eine benötigte Datei nicht für den Lesezugriff öffnen."
);
?>

View File

@@ -0,0 +1,53 @@
<?php
// French translation provided courtesy of GitHub user tuxfamily.
// (C) 2022 CubicleSoft. All Rights Reserved.
if (!isset($langmap)) $langmap = array();
$langmap["fr"] = array(
"The uploaded file exceeds the 'upload_max_filesize' directive in 'php.ini'." =>
"Le poids du fichier dépasse la directive 'upload_max_filesize' dans 'php.ini'.",
"The uploaded file exceeds the 'MAX_FILE_SIZE' directive that was specified in the submitted form." =>
"Le poids du fichier dépasse la directive 'MAX_FILE_SIZE' spécifiée dans le formulaire.",
"The uploaded file was only partially uploaded." =>
"Le fichier n'a été que partiellement transféré.",
"No file was uploaded." =>
"Aucun fichier n'a été transféré.",
"The configured temporary folder on the server is missing." =>
"Le dossier temporaire configuré sur le serveur n'existe pas.",
"Unable to write the temporary file to disk. The server is out of disk space, incorrectly configured, or experiencing hardware issues." =>
"Impossible d'écrire le fichier temporaire sur le disque. Le serveur manque d'espace disque ou rencontre des problèmes techniques.",
"A PHP extension stopped the upload." =>
"Une extension PHP a arrêté le transfert.",
"An unknown error occurred." =>
"Une erreur inconnue est survenue.",
"The specified input filename was not uploaded to this server." =>
"Le nom de fichier spécifié n'a pu être transmis au serveur.",
"File data was submitted but is missing." =>
"Les données du fichier ont été transférées mais le fichier est manquant.",
"Invalid file extension. Must be one of %s." =>
"Extension de fichier invalide. Les extensions acceptées sont : %s.",
"The server did not set a valid filename." =>
"Le serveur n'a pas retourné un nom de fichier valide.",
"The server file size limit was exceeded." =>
"La limite de poids de fichier définie sur le serveur a été dépassée.",
"Unable to open a required file for writing." =>
"Impossible d'ouvrir un fichier requis pour l'écriture.",
"Unable to open a required file for reading." =>
"Impossible d'ouvrir un fichier requis pour la lecture."
);
?>