Introduce ignorePatterns to Media Library, ignoring dot files by default

Roll back some changes from #2692
This commit is contained in:
Samuel Georges 2017-03-20 17:42:17 +11:00
parent 31ba5e29bd
commit c7eb965af8
2 changed files with 20 additions and 7 deletions

View File

@ -248,8 +248,6 @@ return [
'disk' => 'local',
'folder' => 'media',
'path' => '/storage/app/media',
'ignore' => ['^\..*'], // use "php artisan cache:clear" after changing
'ttl' => 10, // how much in minutes to cache the media items before refetching
],
],

View File

@ -47,6 +47,12 @@ class MediaLibrary
*/
protected $ignoreNames;
/**
* @var array Contains a list of regex patterns to ignore in files and directories.
* The list can be customized with cms.storage.media.ignorePatterns configuration option.
*/
protected $ignorePatterns;
/**
* @var int Cache for the storage folder name length.
*/
@ -66,6 +72,8 @@ class MediaLibrary
$this->ignoreNames = Config::get('cms.storage.media.ignore', FileDefinitions::get('ignoreFiles'));
$this->ignorePatterns = Config::get('cms.storage.media.ignorePatterns', ['^\..*']);
$this->storageFolderNameLength = strlen($this->storageFolder);
}
@ -502,12 +510,19 @@ class MediaLibrary
*/
protected function isVisible($path)
{
$clean = [];
foreach ($this->ignoreNames as $one) {
$pattern = "/$one/";
$clean[] = !preg_grep($pattern, [basename($path)]);
$baseName = basename($path);
if (in_array($baseName, $this->ignoreNames)) {
return false;
}
return in_array(basename($path), $clean);
foreach ($this->ignorePatterns as $pattern) {
if (preg_match('/'.$pattern.'/', $baseName)) {
return false;
}
}
return true;
}
/**