From 8a9ba77275935bf0e5ab90ed4370f9416d787a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Tue, 16 Oct 2007 14:10:33 +0000 Subject: #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 --- includes/path.inc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'includes') 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)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($patterns, '/')) .')$/'; + } + return preg_match($regexps[$patterns], $path); +} -- cgit v1.2.3