class FilebrowserValidator in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/Services/FilebrowserValidator.php \Drupal\filebrowser\Services\FilebrowserValidator
Hierarchy
- class \Drupal\filebrowser\Services\FilebrowserValidator
Expanded class hierarchy of FilebrowserValidator
2 files declare their use of FilebrowserValidator
- DefaultController.php in src/
Controller/ DefaultController.php - FilebrowserManager.php in src/
FilebrowserManager.php
1 string reference to 'FilebrowserValidator'
1 service uses FilebrowserValidator
File
- src/
Services/ FilebrowserValidator.php, line 8
Namespace
Drupal\filebrowser\ServicesView source
class FilebrowserValidator {
/**
* FilebrowserValidator constructor.
*/
public function __construct() {
}
/**
* Helper function to match a pattern on the path
* @param string $path to process
* @param array $patterns to search (separated by cr)
* @return TRUE if at least one pattern is found
*/
public function matchPath($path, $patterns) {
static $regexps = NULL;
//var_dump($path);
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;
}
/**
* @param string $folder_path
* @return string tokenized folder path
*/
public function getNodeRoot($folder_path) {
// fixme: token support broken
// token_replace is in D7 core *** if (module_exists("token")) {
// $folder_path = \Drupal::token()->replace($path, ['type' => 'global', 'object' => NULL, 'leading' => '[',
// $trailing = ']']);
return $folder_path;
}
public function encodingToFs($encoding, $string) {
return strcasecmp($encoding, 'UTF-8') == 0 ? $string : mb_convert_encoding($string, $encoding, "UTF-8");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | Helper function to match a pattern on the path | |
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | ||
FilebrowserValidator:: |
public | function | FilebrowserValidator constructor. |