1 path.inc backdrop_match_path($path, $patterns)

Check if a path matches any pattern in a set of patterns.

Parameters

$path: The path to match.

$patterns: String containing a set of patterns separated by \n, \r or \r\n.

Return value

Boolean value: TRUE if the path matches a pattern, FALSE otherwise.

File

core/includes/path.inc, line 296
Functions to handle paths in Backdrop, including path aliasing.

Code

function backdrop_match_path($path, $patterns) {
  $regexps = &backdrop_static(__FUNCTION__);

  if (!isset($regexps[$patterns])) {
    // Convert path settings to a regular expression.
    // Therefore replace newlines with a logical or, /* with asterisks and the <front> with the frontpage.
    $to_replace = array(
      '/(\r\n?|\n)/', // newlines
      '/\\\\\*/', // asterisks
      '/(^|\|)\\\\<front\\\\>($|\|)/' // <front>
    );
    $replacements = array(
      '|',
      '.*',
      '\1' . preg_quote(config_get('system.core', 'site_frontpage'), '/') . '\2'
    );
    $patterns_quoted = preg_quote($patterns, '/');
    $regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
  }
  return (bool) preg_match($regexps[$patterns], $path);
}