You are here

function ServiceAuditFilesNotInDatabase::_auditfiles_get_exclusions in Audit Files 8

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 excluions.

1 call to ServiceAuditFilesNotInDatabase::_auditfiles_get_exclusions()
ServiceAuditFilesNotInDatabase::_auditfiles_not_in_database_get_files in src/ServiceAuditFilesNotInDatabase.php
Retrieves a list of files in the given path.

File

src/ServiceAuditFilesNotInDatabase.php, line 206
providing the service that used in not in database functionality.

Class

ServiceAuditFilesNotInDatabase

Namespace

Drupal\auditfiles

Code

function _auditfiles_get_exclusions() {
  $config = \Drupal::config('auditfiles_config.settings');
  $exclusions_array = [];
  $files = trim($config
    ->get('auditfiles_exclude_files') ? $config
    ->get('auditfiles_exclude_files') : '.htaccess');
  if ($files) {
    $exclude_files = explode(';', $files);
    array_walk($exclude_files, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_make_preg', FALSE);
    $exclusions_array = array_merge($exclusions_array, $exclude_files);
  }
  $paths = trim($config
    ->get('auditfiles_exclude_paths') ? $config
    ->get('auditfiles_exclude_paths') : 'color;css;ctools;js');
  if ($paths) {
    $exclude_paths = explode(';', $paths);
    array_walk($exclude_paths, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_make_preg', TRUE);
    $exclusions_array = array_merge($exclusions_array, $exclude_paths);
  }

  // Exclude other file streams that may be deinfed and in use.
  $exclude_streams = [];
  $auditfiles_file_system_path = $config
    ->get('auditfiles_file_system_path') ? $config
    ->get('auditfiles_file_system_path') : 'public';
  $file_system_paths = \Drupal::service("stream_wrapper_manager")
    ->getWrappers(\Drupal\Core\StreamWrapper\StreamWrapperInterface::LOCAL);
  foreach ($file_system_paths as $file_system_path_id => $file_system_path) {
    if ($file_system_path_id != $auditfiles_file_system_path) {
      $uri = $file_system_path_id . '://';
      if ($wrapper = \Drupal::service('stream_wrapper_manager')
        ->getViaUri($uri)) {
        $exclude_streams[] = $wrapper
          ->realpath();
      }
    }
  }
  array_walk($exclude_streams, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_make_preg', FALSE);
  $exclusions_array = array_merge($exclusions_array, $exclude_streams);

  // Create the list of requested extension exclusions. (This is a little more
  // complicated.)
  $extensions = trim($config
    ->get('auditfiles_exclude_extensions') ? $config
    ->get('auditfiles_exclude_extensions') : '');
  if ($extensions) {
    $exclude_extensions = explode(';', $extensions);
    array_walk($exclude_extensions, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::_auditfiles_make_preg', 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;
}