Skip to content
Snippets Groups Projects
Commit 8a9ba772 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#183690 by Wim Leers: (developer improvement) abstract path matching to...

#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
parent 8a10f3ea
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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);
}
......@@ -410,11 +410,10 @@ function block_list($region) {
if ($block->pages) {
if ($block->visibility < 2) {
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
// Compare with the internal and path alias (if any).
$page_match = preg_match($regexp, $path);
$page_match = drupal_match_path($path, $block->pages);
if ($path != $_GET['q']) {
$page_match = $page_match || preg_match($regexp, $_GET['q']);
$page_match = $page_match || drupal_match_path($_GET['q'], $block->pages);
}
// When $block->visibility has a value of 0, the block is displayed on
// all pages except those listed in $block->pages. When set to 1, it
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment