function highcharttable_match_path in HighchartTable 7
Match a path against one or more regex patterns.
A drop-in replacement for drupal_match_path(), this also handles pattern negation through the use of the twiddle/squiggle (~) character.
Adapted from function context_condition_path::match() in the Context module.
Parameters
string $path: The path string to be matched.
string $patterns: String containing a sequence of patterns separated by \n, \r or \r\n. Each pattern will be trimmed of leading spaces. Any pattern that begins with ~ is interpreted as an exclusion and overrides any match amongst patterns. Example: With $patterns = "admin/*\n~admin/reports/visitors", this function will return TRUE for all "admin/*" paths, except "admin/reports/visitors".
2 calls to highcharttable_match_path()
- highcharttable_preprocess_page in ./
highcharttable.module - Implements hook_preprocess_page().
- _highcharttable_path_matches_decoration in ./
highcharttable.module - Returns whether path matches any of the wildcards in decoration.
File
- ./
highcharttable.module, line 287 - highcharttable.module
Code
function highcharttable_match_path($path, $patterns) {
$regexps =& drupal_static(__FUNCTION__, array());
$patterns = preg_split('/[\\r\\n]+/', $patterns);
$match = FALSE;
$positives = $negatives = 0;
foreach ($patterns as $pat) {
$pattern = trim($pat);
if (!empty($pattern)) {
if ($negate = drupal_substr($pattern, 0, 1) === '~') {
// Remove the tilde before executing a standard preg_match().
$pattern = drupal_substr($pattern, 1);
$negatives++;
}
else {
$positives++;
}
if (!isset($regexps[$pattern])) {
$regexps[$pattern] = '/^(' . preg_replace(array(
'/(\\r\\n?|\\n)/',
'/\\\\\\*/',
'/(^|\\|)\\\\<front\\\\>($|\\|)/',
), array(
'|',
'.*',
'\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
), preg_quote($pattern, '/')) . ')$/';
}
if (preg_match($regexps[$pattern], $path)) {
if ($negate) {
return FALSE;
}
$match = TRUE;
}
}
}
// If there are *only* negative conditions and we got this far, we actually
// have a match.
if ($positives === 0 && $negatives > 0) {
return TRUE;
}
return $match;
}