diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-16 14:10:33 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-16 14:10:33 +0000 |
commit | 8a9ba77275935bf0e5ab90ed4370f9416d787a08 (patch) | |
tree | 9b5576b9b8478b331e4b322b3373e36b860a49cc /includes | |
parent | 8a10f3ea220b4ad8e1d8244594031d918fb22b04 (diff) | |
download | brdo-8a9ba77275935bf0e5ab90ed4370f9416d787a08.tar.gz brdo-8a9ba77275935bf0e5ab90ed4370f9416d787a08.tar.bz2 |
#183690 by Wim Leers: (developer improvement) abstract path matching to drupal_match_path() from block listing, so this gets reusable when path based matching is required
Diffstat (limited to 'includes')
-rw-r--r-- | includes/path.inc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/includes/path.inc b/includes/path.inc index 898b39048..d9774f93e 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -220,3 +220,23 @@ function drupal_is_front_page() { // we can check it against the 'site_frontpage' variable. return $_GET['q'] == drupal_get_normal_path(variable_get('site_frontpage', 'node')); } + +/** + * Check if a path matches any pattern in a set of patterns. + * + * @param $path + * The path to match. + * @param $patterns + * String containing a set of patterns separated by \n, \r or \r\n. + * + * @return + * Boolean value: TRUE if the path matches a pattern, FALSE otherwise. + */ +function drupal_match_path($path, $patterns) { + static $regexps; + + if (!isset($regexps[$patterns])) { + $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($patterns, '/')) .')$/'; + } + return preg_match($regexps[$patterns], $path); +} |