FilebrowserValidator.php in Filebrowser 8.2
File
src/Services/FilebrowserValidator.php
View source
<?php
namespace Drupal\filebrowser\Services;
use Drupal\filebrowser\Filebrowser;
class FilebrowserValidator {
public function __construct() {
}
public function matchPath($path, $patterns) {
static $regexps = NULL;
if (!isset($regexps[$patterns])) {
$regexps[$patterns] = '/^(' . preg_replace([
'/(\\r\\n?|\\n)/',
'/\\\\\\*/',
], [
'|',
'.*',
], preg_quote($patterns, '/')) . ')$/i';
}
$result = preg_match($regexps[$patterns], $this
->safeBaseName($path)) == 1;
return $result;
}
public function whiteListed($file, $pattern) {
return trim($pattern) == '' || $this
->matchPath($file, $pattern);
}
public function blackListed($file, $pattern) {
return trim($pattern) != '' && $this
->matchPath($file, $pattern);
}
public function exploreSubdirs($path, $node) {
if (is_dir($path)) {
return $node->filebrowser->exploreSubdirs;
}
else {
return true;
}
}
public function safeBaseName($path) {
$path = rtrim($path, '/');
$path = explode('/', $path);
return end($path);
}
public function safeDirName($path) {
$path = rtrim($path, '/');
$path = explode('/', $path);
array_pop($path);
$result = implode("/", $path);
if ($result == '') {
return '/';
}
return $result;
}
public function getNodeRoot($folder_path) {
return $folder_path;
}
public function encodingToFs($encoding, $string) {
return strcasecmp($encoding, 'UTF-8') == 0 ? $string : mb_convert_encoding($string, $encoding, "UTF-8");
}
}