src/Charcoal/Admin/Action/ElfinderConnectorAction.php
public function sanitizeOnUploadPreSave(&$path, &$name, $src, $elfinder, $volume)
    {
        // To please PHPCS
        unset($path, $src, $elfinder, $volume);

        if (isset($this->elfinderOptions['plugin']['Sanitizer'])) {
            $opts = $this->elfinderOptions['plugin']['Sanitizer'];

            if (isset($opts['enable']) && $opts['enable']) {
                $mask = (is_array($opts['replace']) ? implode($opts['replace']) : $opts['replace']);
                $ext = '.'.pathinfo($name, PATHINFO_EXTENSION);

                // Strip leading and trailing dashes or underscores
                $name = trim(str_replace($ext, '', $name), $mask);

                // Squeeze multiple delimiters and whitespace with a single separator
                $name = preg_replace('!['.preg_quote($mask, '!').'\.\s]{2,}!', $opts['replace'], $name);

                // Reassemble the file name
                $name .= $ext;
            }
        }

        return true;
    }
public function sanitizeOnUploadPreSave(&$path, &$name, $src, $elfinder, $volume)
    {
        // To please PHPCS
        unset($path, $src, $elfinder, $volume);

        if (isset($this->elfinderOptions['plugin']['Sanitizer'])) {
            $opts = $this->elfinderOptions['plugin']['Sanitizer'];

            if (isset($opts['enable']) && $opts['enable']) {
                $mask = (is_array($opts['replace']) ? implode($opts['replace']) : $opts['replace']);
                $ext = '.'.pathinfo($name, PATHINFO_EXTENSION);

                // Strip leading and trailing dashes or underscores
                $name = trim(str_replace($ext, '', $name), $mask);

                // Squeeze multiple delimiters and whitespace with a single separator
                $name = preg_replace('!['.preg_quote($mask, '!').'\.\s]{2,}!', $opts['replace'], $name);

                // Reassemble the file name
                $name .= $ext;
            }
        }

        return true;
    }
public function sanitizeOnUploadPreSave ( & $ path , & $ name , $ src , $ elfinder , $ volume ) { // To please PHPCS unset ( $ path , $ src , $ elfinder , $ volume ) ; if ( isset ( $ this -> elfinderOptions [ 'plugin' ] [ 'Sanitizer' ] ) ) { $ opts = $ this -> elfinderOptions [ 'plugin' ] [ 'Sanitizer' ] ; if ( isset ( $ opts [ 'enable' ] ) && $ opts [ 'enable' ] ) { $ mask = ( is_array ( $ opts [ 'replace' ] ) ? implode ( $ opts [ 'replace' ] ) : $ opts [ 'replace' ] ) ; $ ext = '.' . pathinfo ( $ name , PATHINFO_EXTENSION ) ; // Strip leading and trailing dashes or underscores $ name = trim ( str_replace ( $ ext , '' , $ name ) , $ mask ) ; // Squeeze multiple delimiters and whitespace with a single separator $ name = preg_replace ( '![' . preg_quote ( $ mask , '!' ) . '\.\s]{2,}!' , $ opts [ 'replace' ] , $ name ) ; // Reassemble the file name $ name .= $ ext ; } } return true ; }
Trim a file name.

@param  string $path     The target path.
@param  string $name     The target name.
@param  string $src      The temporary file name.
@param  object $elfinder The elFinder instance.
@param  object $volume   The current volume instance.
@return true
Trim a file name .