Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call back function or method on sanitizeFileName #2432

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions php/plugins/Sanitizer/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* 'Sanitizer' => array(
* 'enable' => true,
* 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
* 'replace' => '_' // replace to this
* 'replace' => '_', // replace to this
* 'callBack' => null // Or @callable sanitize function
* )
* ),
* // each volume configure (optional)
Expand All @@ -35,7 +36,8 @@
* 'Sanitizer' => array(
* 'enable' => true,
* 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
* 'replace' => '_' // replace to this
* 'replace' => '_', // replace to this
* 'callBack' => null // Or @callable sanitize function
* )
* )
* )
Expand All @@ -59,6 +61,7 @@ public function __construct($opts) {
'enable' => true, // For control by volume driver
'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
'replace' => '_', // replace to this
'callBack' => null, // Or callable sanitize function
'pathAllows' => array('/') // Characters allowed in path name of characters in `targets` array
);

Expand Down Expand Up @@ -114,6 +117,9 @@ public function onUpLoadPreSave(&$thash, &$name, $src, $elfinder, $volume) {
}

protected function sanitizeFileName($filename, $opts, $allows = array()) {
if(!empty($opts['callBack']) && is_callable($opts['callBack'])) {
return call_user_func_array($opts['callBack'], array($filename, $opts));
}
$targets = $allows? array_diff($opts['targets'], $allows) : $opts['targets'];
return str_replace($targets, $opts['replace'], $filename);
}
Expand Down