function site_disclaimer_init in Site Disclaimer 7
Same name and namespace in other branches
- 6 site_disclaimer.module \site_disclaimer_init()
Implements hook_init().
File
- ./
site_disclaimer.module, line 190 - This module adds Site Disclaimer to the registration page.
Code
function site_disclaimer_init() {
global $user;
if (user_is_logged_in() && !user_access('bypass site disclaimer') && !user_access('administer site disclaimer')) {
$site_disclaimer_enabled = _site_disclaimer_enabled();
$site_disclaimer_version = variable_get('site_disclaimer_version', 1);
if ($site_disclaimer_enabled && (!isset($user->data['site_disclaimer']) || $user->data['site_disclaimer'] < $site_disclaimer_version)) {
$allow_nodes = variable_get('site_disclaimer_allow_nodes', array());
// Allowed paths, array path components mean logical or (any of)
$allow_paths = array(
explode('/', SITE_DISCLAIMER_ACCEPT_PATH),
array(
'user',
'logout',
),
array(
'js',
),
);
// Any links in the Site Disclaimer node or in the checkbox should also be allowed.
if (!empty($allow_nodes)) {
$allow_paths[] = array(
'node',
$allow_nodes,
);
// Special case for print.module - allow the user to also print the allowed nodes.
$allow_paths[] = array(
'print',
'node',
$allow_nodes,
);
$allow_paths[] = array(
'printpdf',
'node',
$allow_nodes,
);
}
// @todo: implement hook_site_disclaimer_allowed_paths_alter() here, so paths like print, printpdf can belong to print module
// Check if the path is in the allowed list
foreach ($allow_paths as $allow_path) {
// This while loop ends in "return" if the path matches.
// If the path does not match, break 2 will loop to the next allowed path
while (1) {
$i = 0;
// Array path components mean logical or (any of)
foreach ($allow_path as $part) {
if (is_array($part) && !in_array(arg($i), $part)) {
break 2;
}
if (!is_array($part) && arg($i) != $part) {
break 2;
}
$i++;
}
// The arg() path matches the one in the $allow_path
return;
}
}
drupal_goto(SITE_DISCLAIMER_ACCEPT_PATH, array(
'query' => drupal_get_destination(),
));
}
}
}