Skip to content

Commit

Permalink
Added 'clean filename' option, to disable default behavior of allowin…
Browse files Browse the repository at this point in the history
…g only alphanumeric (ie. using unicode).
  • Loading branch information
cheesegrits committed May 9, 2018
1 parent 7aa7da9 commit 8b699e7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
10 changes: 8 additions & 2 deletions plugins/fabrik_element/fileupload/adaptors/filesystemstorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ public function clean($path)

public function cleanName($filename, $repeatCounter)
{
// Replace any non-alphanumeric chars (except _ and - and .) with _
$filename = preg_replace('#[^a-zA-Z0-9_\-\.]#', '_', $filename);
$params = $this->getParams();

if ($params->get('fu_clean_filename', '1') === '1')
{
// Replace any non-alphanumeric chars (except _ and - and .) with _
$filename = preg_replace('#[^a-zA-Z0-9_\-\.]#', '_', $filename);
}

$this->randomizeName($filename);

return $filename;
Expand Down
2 changes: 1 addition & 1 deletion plugins/fabrik_element/fileupload/fileupload-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/fabrik_element/fileupload/fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(['jquery', 'fab/fileelement'], function (jQuery, FbFileElement) {
},
initialize: function (element, options) {
var self = this;
this.setPlugin('fileupload');
this.setPlugin('fileupl/oad');
this.parent(element, options);
this.container = jQuery(this.container);
this.toppath = this.options.dir;
Expand Down
2 changes: 2 additions & 0 deletions plugins/fabrik_element/fileupload/fileupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ protected function _renderListData($data, &$thisRow, $i = 0)
$displayData->title = $title;
$displayData->file = $data;
$displayData->noAccessImage = COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $params->get('fu_download_noaccess_image');
$displayData->noAccessURL = $params->get('fu_download_noaccess_url', '');
$displayData->downloadImg = ($downloadImg && JFile::exists('media/com_fabrik/images/' . $downloadImg)) ? COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $downloadImg : '';
$displayData->href = COM_FABRIK_LIVESITE
. 'index.php?option=com_' . $this->package . '&task=plugin.pluginAjax&plugin=fileupload&method=ajax_download&format=raw&element_id='
Expand Down Expand Up @@ -2582,6 +2583,7 @@ protected function downloadLink($value, $data, $repeatCounter = 0, $ajaxIndex)
$displayData->file = $fileName;
$displayData->ajaxIndex = $ajaxIndex;
$displayData->noAccessImage = COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $params->get('fu_download_noaccess_image');
$displayData->noAccessURL = $params->get('fu_download_noaccess_url', '');
$displayData->downloadImg = ($downloadImg && JFile::exists('media/com_fabrik/images/' . $downloadImg)) ? COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $downloadImg : '';
$displayData->href = COM_FABRIK_LIVESITE . 'index.php?option=com_' . $this->package
. '&task=plugin.pluginAjax&plugin=fileupload&method=ajax_download&format=raw&element_id='
Expand Down
10 changes: 10 additions & 0 deletions plugins/fabrik_element/fileupload/forms/fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
<option value="1">JYES</option>
</field>

<field name="fu_clean_filename"
type="radio"
class="btn-group"
default="1"
description="PLG_ELEMENT_FILEUPLOAD_CLEAN_FILENAME_DESC"
label="PLG_ELEMENT_FILEUPLOAD_CLEAN_FILENAME_LABEL">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field name="fu_rename_file_code"
type="fabrikeditor"
mode="php"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ PLG_ELEMENT_FILEUPLOAD_USE_WIP_DESC="Use works-in-progress, such as certain HTML
PLG_ELEMENT_FILEUPLOAD_USE_WIP_LABEL="Use WiP"
PLG_ELEMENT_FILEUPLOAD_WIN_WIDTH_LABEL="Crop window width"
PLG_ELEMENT_FILEUPLOAD_WIN_HEIGHT_LABEL="Crop window height"
PLG_ELEMENT_FILEUPLOAD_CLEAN_FILENAME_DESC="The default behavior for filenames is that Fabrik replaces all non alphanumeric characters (A-Z, a-z, 0-9) except - and _ with _. This prevents problems with OS's and filesystems which don't support multibyte character sets, or disallow certain characters. If you need to use Unicode names, set this to No, but be aware this may result in unusable filenames."
PLG_ELEMENT_FILEUPLOAD_CLEAN_FILENAME_LABEL="Clean Filename"

; Front end
PLG_ELEMENT_FILEUPLOAD_ADD_FILES="Add files"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@

?>

<?php if (!$d->canDownload) : ?>
<img src="<?php echo $d->noAccessImage;?>"
alt="<?php echo FText::_('PLG_ELEMENT_FILEUPLOAD_DOWNLOAD_NO_PERMISSION'); ?>" />
<?php else :?>
<?php if (!$d->canDownload) :
$noImg = ($d->noAccessImage === '' || !JFile::exists(JPATH_ROOT . '/media/com_fabrik/images/' . $d->noAccessImage));
$aClass = $noImg ? 'class="btn button"' : '';

if (!empty($d->noAccessURL)) :
?>
<a href="<?php echo $d->noAccessURL; ?>" <?php echo $aClass; ?>>
<?php
endif;

if ($noImg) :
?>
<i class="icon-play-circle"></i><?php echo FText::_('PLG_ELEMENT_FILEUPLOAD_DOWNLOAD_NO_PERMISSION'); ?>
<?php
else :
?>
<img src="<?php echo $d->noAccessImage;?>"
alt="<?php echo FText::_('PLG_ELEMENT_FILEUPLOAD_DOWNLOAD_NO_PERMISSION'); ?>" />
<?php
endif;

if (!empty($d->noAccessURL)) :
?>
</a>
<?php
endif;
else :?>
<a href="<?php echo $d->href;?>" <?php echo $class; ?>>
<?php if ($d->downloadImg !== '') : ?>
<img src="<?php echo $d->downloadImg;?>" alt="<?php echo $d->title;?>" />
Expand Down

0 comments on commit 8b699e7

Please sign in to comment.