function _disclaimer_visibility in Disclaimer 7
Same name and namespace in other branches
- 6.2 disclaimer.module \_disclaimer_visibility()
- 6 disclaimer.module \_disclaimer_visibility()
Calculate visibility of disclaimer if set.
This is a copy from block.module (~807), thanks for the original code.
Return value
bool Page match or not.
1 call to _disclaimer_visibility()
- disclaimer_show in ./
disclaimer.module - Function to control disclaimer display depending user and accesses.
File
- ./
disclaimer.module, line 293 - Create and show disclaimer for your site.
Code
function _disclaimer_visibility() {
$separator = "\n";
$negator = '!';
$visibility = variable_get('disclaimer_visibility', 0);
$pages = variable_get('disclaimer_pages', implode($separator, array(
'admin',
'user',
)));
$pages = array_map('trim', explode($separator, $pages));
$not_pages = implode($separator, array_map(static function ($pattern) {
return substr($pattern, 1);
}, array_filter($pages, static function ($pattern) use ($negator) {
return $pattern[0] === $negator;
})));
$pages = implode($separator, array_filter($pages, static function ($pattern) use ($negator) {
return $pattern[0] !== $negator;
}));
// Convert path to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
$pages = drupal_strtolower($pages);
$not_pages = drupal_strtolower($not_pages);
if ($visibility < 2) {
$q = $_GET['q'];
// Convert the Drupal path to lowercase.
$path = drupal_strtolower(drupal_get_path_alias($q));
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages) && !drupal_match_path($path, $not_pages);
if ($path !== $q) {
$page_match = $page_match || drupal_match_path($q, $pages) && !drupal_match_path($q, $not_pages);
}
// When $visibility has a value of 0,
// the disclaimer is displayed on all pages except those listed in $pages.
// When set to 1, it is displayed only on those
// pages listed in $pages.
$page_match = !($visibility xor $page_match);
}
elseif (module_exists('php')) {
$page_match = php_eval($pages);
}
else {
$page_match = FALSE;
}
return $page_match;
}