Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions component/admin/controllers/redform.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @package Redform.Front
* @copyright Copyright (c) 2008 - 2021 redweb.dk redCOMPONENT.com
* @license GNU General Public License version 2 or later, see LICENSE.
*/

use Redform\Controller\RedformJsonController;

defined('_JEXEC') or die('Restricted access');

/**
* Redform Controller
* @since __DEPLOY_VERSION__
* @package Redform.Front
*/
class RedformControllerRedform extends RedformJsonController
{
}
8 changes: 8 additions & 0 deletions component/admin/language/en-GB/en-GB.com_redform.ini
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ COM_REDFORM_FIELD_TYPE_FULLNAME="Full name"
COM_REDFORM_FIELD_TYPE_SELECT="Select"
COM_REDFORM_FIELD_TYPE_MULTISELECT="Multi select"
COM_REDFORM_FIELD_TYPE_FILEUPLOAD="File upload"
COM_REDFORM_FIELD_TYPE_FILESUPLOAD="Files upload"
COM_REDFORM_FIELD_TYPE_WYSIWYG="Wysiwyg"
COM_REDFORM_FIELD_TYPE_INFO="Info"
COM_REDFORM_FIELD_TYPE_RECIPIENTS="Recipients"
Expand Down Expand Up @@ -719,6 +720,13 @@ COM_REDFORM_FIELD_WYSIWYG_PARAMS_FILTERING_RAW="Raw"
COM_REDFORM_FIELD_FILEUPLOAD_PARAMS_MAXSIZE="Max size"
COM_REDFORM_FIELD_FILEUPLOAD_PARAMS_MAXSIZE_DESC="Specify a maximum size in bytes for the upload"

COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_MAXSIZE="Max size"
COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_MAXSIZE_DESC="Specify a maximum size in bytes for the upload"
COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_MAXFILES="Max files"
COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_MAXFILES_DESC="Specify a maximum files for the upload"
COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_ACCEPTED_FILES="Accepted Files"
COM_REDFORM_FIELD_FILESUPLOAD_PARAMS_ACCEPTED_FILES_DESC="The default implementation of `accept` checks the file's mime type or extension against this list. This is a comma separated list of mime types or file extensions. Eg.: `image/*,application/pdf,.psd`"

COM_REDFORM_ERROR_FILEUPLOAD_SIZE_S_BIGGER_THAN_MAXSIZE_S="The uploaded file size (%s) is bigger than max allowed size (%s)"

COM_REDFORM_SUBMISSION_SAVE_FAILED="Submission saving failed"
Expand Down
96 changes: 96 additions & 0 deletions component/libraries/redform/cron/clear_tmp_filesupload_folder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* @package Redform.Library
* @subpackage CLI
*
* @copyright Copyright (C) 2008 - 2022 redCOMPONENT.com. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

use Joomla\CMS\Application\CliApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;

const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/../../defines.php'))
{
require_once dirname(__DIR__) . '/../../defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__) . '/../..');
require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';

define('JDEBUG', 0);

$_SERVER['REQUEST_METHOD'] = 'GET';

define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_redform');

/**
* @package Aesir.E-Commerce
* @subpackage Create_Pdf_Productsheet
*
* @since 1.13.0
*/
class ClearTmpFileUploadsFolderApplicationCli extends CliApplication
{
/**
* A method to start the cli script
* Optional parameters: [1]: SKU of the product to print (only this product) - no Redis used in this case
*
* @return void
* @since 1.13.0
* @throws Exception
*/
public function doExecute()
{
Factory::getApplication('site');

$tmp = Factory::getConfig()->get('tmp_path') . '/redform/filesupload/';

if (!Folder::exists($tmp))
{
return;
}

$list = Folder::files($tmp);

if (empty($list))
{
return;
}

$nowMinusDay = (new DateTime)
->modify('-1 day');

foreach ($list as $item)
{
$filename = $tmp . $item;

$dateTime = new DateTime('@' . filemtime($filename));

if ($nowMinusDay >= $dateTime)
{
File::delete($filename);
}
}
}
}

CliApplication::getInstance('ClearTmpFileUploadsFolderApplicationCli')
->execute();
14 changes: 13 additions & 1 deletion component/libraries/redform/language/en-GB/en-GB.lib_redform.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ COM_REDFORM_FIELD_PARAMS_EXPORT_DESC="Include this field in exports"
COM_REDFORM_FIELD_PARAMS_SHOW_IN_LIST="Show in lists"
COM_REDFORM_FIELD_PARAMS_SHOW_IN_LIST_DESC="Show this field in submitters lists"

LIB_REDFORM_VALIDATE_FIELD_ERROR_TOO_LONG="%s field limit is %d characters"
LIB_REDFORM_VALIDATE_FIELD_ERROR_TOO_LONG="%s field limit is %d characters"

LIB_REDFORM_FILES_UPLOAD_DICTDEFAULTMESSAGE="Drop files here to upload"
LIB_REDFORM_FILES_UPLOAD_DICTFALLBACKMESSAGE="Your browser does not support drag'n'drop file uploads."
LIB_REDFORM_FILES_UPLOAD_DICTFALLBACKTEXT="Please use the fallback form below to upload your files like in the olden days."
LIB_REDFORM_FILES_UPLOAD_DICTFILETOOBIG="File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB."
LIB_REDFORM_FILES_UPLOAD_DICTINVALIDFILETYPE="You can't upload files of this type."
LIB_REDFORM_FILES_UPLOAD_DICTRESPONSEERROR="Server responded with {{statusCode}} code."
LIB_REDFORM_FILES_UPLOAD_DICTCANCELUPLOAD="Cancel upload"
LIB_REDFORM_FILES_UPLOAD_DICTUPLOADCANCELED="Upload canceled."
LIB_REDFORM_FILES_UPLOAD_DICTCANCELUPLOADCONFIRMATION="Are you sure you want to cancel this upload?"
LIB_REDFORM_FILES_UPLOAD_DICTREMOVEFILE="Remove file"
LIB_REDFORM_FILES_UPLOAD_DICTMAXFILESEXCEEDED="You can not upload any more files."
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$fieldsHtml = $data['fieldsHtml'];
$referer64 = $data['referer64'];
?>
<form action="<?php echo $action; ?>" method="post" name="redform" class="redform-validate form-horizontal <?php echo $form->classname; ?>" enctype="multipart/form-data">
<form action="<?php echo $action; ?>" method="post" id="redForm_<?php echo $form->id ?>" name="redform" class="redform-validate form-horizontal <?php echo $form->classname; ?>" enctype="multipart/form-data">

<?php echo $fieldsHtml; ?>

Expand Down
2 changes: 1 addition & 1 deletion component/libraries/redform/layouts/rform/form.legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$fieldsHtml = $data['fieldsHtml'];
$referer64 = $data['referer64'];
?>
<form action="<?php echo $action; ?>" method="post" name="redform" class="redform-validate <?php echo $form->classname; ?>" enctype="multipart/form-data">
<form action="<?php echo $action; ?>" method="post" name="redform" id="redForm_<?php echo $form->id ?>" class="redform-validate <?php echo $form->classname; ?>" enctype="multipart/form-data">

<?php echo $fieldsHtml; ?>

Expand Down
2 changes: 1 addition & 1 deletion component/libraries/redform/layouts/rform/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$fieldsHtml = $data['fieldsHtml'];
$referer64 = $data['referer64'];
?>
<form action="<?php echo $action; ?>" method="post" name="redform" class="redform-validate <?php echo $form->classname; ?>" enctype="multipart/form-data">
<form action="<?php echo $action; ?>" method="post" name="redform" id="redForm_<?php echo $form->id ?>" class="redform-validate <?php echo $form->classname; ?>" enctype="multipart/form-data">

<?php echo $fieldsHtml; ?>

Expand Down
200 changes: 200 additions & 0 deletions component/libraries/redform/layouts/rform/rfield/filesupload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php
/**
* @package Redform.Site
* @subpackage Layouts
* @copyright Copyright (c) 2008 - 2021 redweb.dk. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;

defined('_JEXEC') or die;

/** @var \RdfRfieldFilesupload $data */
$data = $displayData;

$properties = $data->getInputProperties();
$options = ['version' => 'auto', 'relative' => true];

HTMLHelper::_('script', 'com_redform/dropzone/dropzone.min.js', $options);
HTMLHelper::_('stylesheet', 'com_redform/dropzone/dropzone.min.css', $options);

if (!empty($data->getValue()))
{
foreach ($data->getValue() as $uuid => $val)
{
echo '<input type="hidden" name="'
. $data->getFormElementName() . '[' . $uuid . ']" value="'
. $val . '" />';
}
}
?>
<div class="dropzone" id="redFormDropZone<?php echo $data->form_id ?>"></div>
<script>
jQuery(document).ready(function () {
var form = jQuery("#redForm_<?php echo $data->form_id ?>");

// camelized version of the `id`
Dropzone.options.redFormDropZone<?php echo $data->form_id ?> = {
url: '<?php echo Uri::base() . 'index.php?option=com_redform&task=redform.upload&format=json' ?>',
uploadMultiple: true,
parallelUploads: <?php echo (int) $data->getParam('maxfiles', 10) ?>,
maxFiles: <?php echo (int) $data->getParam('maxfiles', 10) ?>,
paramName: "file",
addRemoveLinks: true,
maxFilesize: <?php echo (int) $data->getParam('maxsize', 1000) ?>,
acceptedFiles: '<?php echo $data->getParam('accepted_files', 'image/*') ?>',
params: {
'<?php echo Session::getFormToken() ?>': 1,
'form_id': '<?php echo $data->form_id ?>',
'field_id': '<?php echo $data->id ?>'
},

// The setting up of the dropzone
init: function () {
<?php
if (!empty($data->getValue()))
{
foreach ($data->getValue() as $uuid => $val)
{
$encoded = base64_decode($val);
$decoded = json_decode($encoded, true);
$decoded['status'] = 'added';
$decoded['uuid'] = $uuid;
$encoded = json_encode($decoded);

echo 'this.displayExistingFile('
. $encoded . ', \''
. Uri::root() . $decoded['path'] . '\');';
}
}
?>this.on('sendingmultiple', function (files, xhr, formData) {
for (var i = 0; i < files.length; i++) {
formData.append(
'uuid['+i+']',
files[i]['upload']['uuid']
);
}
})
.on('removedfile', function (file) {
var uuid, token, fileName;
if (file.uuid) {
uuid = file.uuid;
token = file.token;
fileName = file.stored_name;
} else {
uuid = file.upload.uuid;
token = file.additionalInfo.token;
fileName = file.additionalInfo.tmp_name;
}
var found = form.find('input[name=\"<?php echo $data->getFormElementName() ?>['+uuid+']\"]');
if (found) {
found.remove();
jQuery.ajax({
url: '<?php echo Uri::base() . 'index.php?option=com_redform&task=redform.remove&format=json' ?>',
type : "GET",
data : {
file_name: fileName,
token: token,
form_id: '<?php echo $data->form_id ?>'
}
});
}
})
.on("successmultiple", function (files, responseStr) {
// Gets triggered when the files have successfully been sent.
var responseObj = JSON.parse(responseStr);

if (!responseObj.success && responseObj.message)
{
for (var f = 0; f < files.length; f++) {
var file = files[f];
var message = responseObj.message;
file.previewElement.classList.add("dz-error");
file.status = Dropzone.ERROR;
var els = file.previewElement.querySelectorAll("[data-dz-errormessage]");
for (var i = 0; i < els.length; i++) {
els[i].textContent = message;
}
}
}

if (responseObj.success)
{
for (var f = 0; f < files.length; f++) {
var file = files[f];
file.additionalInfo = responseObj.data[file.upload.uuid];
form.append(
'<input type="hidden" name="<?php echo $data->getFormElementName() ?>['
+(file.upload.uuid)+']" value="'+(file.additionalInfo.base64)+'" />'
);
}
}
});
},

/**
* The text used before any files are dropped.
*/
dictDefaultMessage: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTDEFAULTMESSAGE', true) ?>",

/**
* The text that replaces the default message text it the browser is not supported.
*/
dictFallbackMessage: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTFALLBACKMESSAGE', true) ?>",

/**
* The text that will be added before the fallback form.
* If you provide a fallback element yourself, or if this option is `null` this will
* be ignored.
*/
dictFallbackText: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTFALLBACKTEXT', true) ?>",

/**
* If the filesize is too big.
* `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
*/
dictFileTooBig: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTFILETOOBIG', true) ?>",

/**
* If the file doesn't match the file type.
*/
dictInvalidFileType: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTINVALIDFILETYPE', true) ?>",

/**
* If the server response was invalid.
* `{{statusCode}}` will be replaced with the servers status code.
*/
dictResponseError: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTRESPONSEERROR', true) ?>",

/**
* If `addRemoveLinks` is true, the text to be used for the cancel upload link.
*/
dictCancelUpload: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTCANCELUPLOAD', true) ?>",

/**
* The text that is displayed if an upload was manually canceled
*/
dictUploadCanceled: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTUPLOADCANCELED', true) ?>",

/**
* If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
*/
dictCancelUploadConfirmation: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTCANCELUPLOADCONFIRMATION', true) ?>",

/**
* If `addRemoveLinks` is true, the text to be used to remove a file.
*/
dictRemoveFile: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTREMOVEFILE', true) ?>",

/**
* Displayed if `maxFiles` is st and exceeded.
* The string `{{maxFiles}}` will be replaced by the configuration value.
*/
dictMaxFilesExceeded: "<?php echo Text::_('LIB_REDFORM_FILES_UPLOAD_DICTMAXFILESEXCEEDED', true) ?>"
};
});
</script>
Loading