mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Introduce ignorePatterns to Media Library, ignoring dot files by default
Roll back some changes from #2692
This commit is contained in:
parent
31ba5e29bd
commit
c7eb965af8
@ -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
|
||||
],
|
||||
|
||||
],
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user