public function ServiceAuditFilesNotInDatabase::auditfilesGetExclusions in Audit Files 8.3
Same name and namespace in other branches
- 8.2 src/ServiceAuditFilesNotInDatabase.php \Drupal\auditfiles\ServiceAuditFilesNotInDatabase::auditfilesGetExclusions()
- 4.x src/ServiceAuditFilesNotInDatabase.php \Drupal\auditfiles\ServiceAuditFilesNotInDatabase::auditfilesGetExclusions()
Creates an exclusion string.
This function creates a list of file and/or directory exclusions to be used with a preg_* function.
Return value
string The exclusions.
File
- src/
ServiceAuditFilesNotInDatabase.php, line 301
Class
- ServiceAuditFilesNotInDatabase
- Define all methods that are used on Files not in database functionality.
Namespace
Drupal\auditfilesCode
public function auditfilesGetExclusions() {
$config = $this->configFactory
->get('auditfiles.settings');
$exclusions_array = [];
$files = $config
->get('auditfiles_exclude_files');
if ($files) {
$exclude_files = explode(';', $files);
foreach ($exclude_files as $key => $value) {
$exclude_files[$key] = $this
->auditFilesEscapePreg($value, FALSE);
}
$exclusions_array = array_merge($exclusions_array, $exclude_files);
}
$paths = $config
->get('auditfiles_exclude_paths');
if ($paths) {
$exclude_paths = explode(';', $paths);
foreach ($exclude_paths as $key => $value) {
$exclude_paths[$key] = $this
->auditFilesEscapePreg($value, TRUE);
}
$exclusions_array = array_merge($exclusions_array, $exclude_paths);
}
// Exclude other file streams that may be defined and in use.
$exclude_streams = [];
$auditfiles_file_system_path = $config
->get('auditfiles_file_system_path');
$file_system_paths = $this->streamWrapperManager
->getWrappers(StreamWrapperInterface::LOCAL);
foreach ($file_system_paths as $file_system_path_id => $file_system_path) {
if ($file_system_path_id != $auditfiles_file_system_path) {
$wrapper = $this->streamWrapperManager
->getViaUri($file_system_path_id . '://');
if ($wrapper && $wrapper
->realpath()) {
$exclude_streams[] = $wrapper
->realpath();
}
}
}
foreach ($exclude_streams as $key => $value) {
$exclude_streams[$key] = $this
->auditFilesEscapePreg($value, FALSE);
}
$exclusions_array = array_merge($exclusions_array, $exclude_streams);
// Create the list of requested extension exclusions. (This is a little more
// complicated.)
$extensions = $config
->get('auditfiles_exclude_extensions');
if ($extensions) {
$exclude_extensions = explode(';', $extensions);
foreach ($exclude_extensions as $key => $value) {
$exclude_extensions[$key] = $this
->auditFilesEscapePreg($value, FALSE);
}
$extensions = implode('|', $exclude_extensions);
$extensions = '(' . $extensions . ')$';
$exclusions_array[] = $extensions;
}
// Implode exclusions array to a string.
$exclusions = implode('|', $exclusions_array);
// Return prepared exclusion string.
return $exclusions;
}