You are here

function block_exclude_pages_fnmatch in Block Exclude Pages 8

Doc function to reaplace native php fnmatch().

1 call to block_exclude_pages_fnmatch()
block_exclude_pages_check_excluded_path in ./block_exclude_pages.module
Doc function checks if path matches any restricted patterns.

File

./block_exclude_pages.module, line 49
Contains block_exclude_pages.module..

Code

function block_exclude_pages_fnmatch($pattern, $string, $flags = 0) {
  $modifiers = NULL;
  $transforms = [
    '\\*' => '.*',
    '\\?' => '.',
    '\\[\\!' => '[^',
    '\\[' => '[',
    '\\]' => ']',
    '\\.' => '\\.',
    '\\' => '\\\\',
    '\\-' => '\\-',
  ];

  // Forward slash in string must be in pattern:
  if ($flags & FNM_PATHNAME) {
    $transforms['\\*'] = '[^/]*';
  }

  // Back slash should not be escaped:
  if ($flags & FNM_NOESCAPE) {
    unset($transforms['\\']);
  }

  // Perform case insensitive match:
  if ($flags & FNM_CASEFOLD) {
    $modifiers .= 'i';
  }

  // Period at start must be the same as pattern:
  if ($flags & FNM_PERIOD) {
    if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) {
      return FALSE;
    }
  }
  $pattern = '#^' . strtr(preg_quote($pattern, '#'), $transforms) . '$#' . $modifiers;
  return (bool) preg_match($pattern, $string);
}