disclaimer.module in Disclaimer 6.2
Same filename and directory in other branches
Create and show disclaimer for your site. Visotors need js enabled and accept cookie
This module is for Drupal 6.x only.
Module by: Mog Mailto: tech@arthura.fr
File
disclaimer.moduleView source
<?php
/**
* @file
* Create and show disclaimer for your site.
* Visotors need js enabled and accept cookie
*
* This module is for Drupal 6.x only.
*
* Module by: Mog
* Mailto: tech@arthura.fr
*
*/
/**
* Implementation of hook_menu().
*/
function disclaimer_menu() {
$items = array();
// Disclaimer page
$items['disclaimer'] = array(
'title' => 'Disclaimer',
'page callback' => '_disclaimer_get_content',
'access arguments' => array(
'access content',
),
'type' => MENU_SUGGESTED_ITEM,
);
// configuration page of the Disclaimer module
$items['admin/settings/disclaimer'] = array(
'title' => 'Disclaimer',
'description' => 'Administer Disclaimer settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disclaimer_admin_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer disclaimer settings',
),
'file' => 'disclaimer.admin.inc',
);
return $items;
}
/**
* Implementation of hook_init().
*/
function disclaimer_init() {
global $user;
if ((!user_access('bypass disclaimer') || variable_get('disclaimer_logged', 1) == 1 && $user->uid) && _disclaimer_visibility() == 1) {
// settings
$settings = array(
// common
'url' => base_path() . 'disclaimer',
'content' => _disclaimer_get_content(),
'modal' => variable_get('disclaimer_modal', 'thickbox'),
'cookie_path' => variable_get('disclaimer_cookie_path', '/'),
'cookie_domain' => variable_get('disclaimer_cookie_domain', NULL),
'width' => variable_get('disclaimer_width', '400px'),
'height' => variable_get('disclaimer_height', '300px'),
// colorbox
'opacity' => variable_get('disclaimer_overlay', 0.85),
'speed' => variable_get('disclaimer_speed', 350),
'transition' => variable_get('disclaimer_transition', 'elastic'),
);
//dsm($settings);
drupal_add_js(array(
'disclaimer' => $settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'disclaimer') . '/disclaimer.js', 'module', variable_get('disclaimer_location_js', 'header'));
}
}
/**
* Implementation of hook_perm().
*/
function disclaimer_perm() {
return array(
'administer disclaimer settings',
'bypass disclaimer',
);
}
/**
* Generate disclaimer content
*/
function _disclaimer_get_content() {
$action_type = variable_get('disclaimer_action_type', 'text');
$exit_url = variable_get('disclaimer_exit_url', 'http://www.google.com');
$enter_url = variable_get('disclaimer_enter_url', '');
$nid = variable_get('disclaimer_node', '');
$nid_footer = variable_get('disclaimer_node_footer', '');
$age = variable_get('disclaimer_age_form', 0);
$age_limit = variable_get('disclaimer_age_limit', 18);
$modal = variable_get('disclaimer_modal', 'thickbox');
$js = '';
switch ($action_type) {
case "image":
$enter_alt = variable_get('disclaimer_enter_img_alt', t('ENTER'));
$exit_alt = variable_get('disclaimer_exit_img_alt', t('EXIT'));
$enter = theme('image', variable_get('disclaimer_enter_img_path', FALSE), $enter_alt, $enter_alt);
$exit = theme('image', variable_get('disclaimer_exit_img_path', FALSE), $exit_alt, $exit_alt);
break;
default:
$enter = variable_get('disclaimer_enter_txt', t('ENTER'));
$exit = variable_get('disclaimer_exit_txt', t('EXIT'));
}
if ($age == 1) {
$age_form = drupal_get_form('disclaimer_age_form');
$rows[] = array(
array(
'data' => $age_form,
'align' => 'center',
'colspan' => '2',
),
);
$js = "CheckAge('" . variable_get('disclaimer_cookie_name', 'disclaimerShow') . "', " . $age_limit . ", '" . $exit_url . "', '" . $modal . "');";
}
else {
$js = 'WriteCookie(\'' . variable_get('disclaimer_cookie_name', 'disclaimerShow') . '\', \'1\');';
switch ($modal) {
case 'thickbox':
$js .= 'tb_remove();';
break;
case 'colorbox':
$js .= '$.colorbox.remove();';
break;
}
}
if ($enter_url) {
$enter = l($enter, $enter_url, array(
'attributes' => array(
'onclick' => $js,
),
'html' => TRUE,
));
}
else {
$enter = '<a href="javascript:void(0);" onclick="' . $js . '">' . $enter . '</a>';
}
$exit = l($exit, $exit_url, array(
'html' => TRUE,
));
$rows[] = array(
array(
'data' => $enter,
'align' => 'center',
),
array(
'data' => $exit,
'align' => 'center',
),
);
if ($nid == 0) {
$output = check_markup(variable_get('disclaimer_content', ''), variable_get('disclaimer_content_format', 1), FALSE);
}
else {
$output = node_view(node_load($nid), FALSE, TRUE);
}
$output .= theme('table', array(), $rows);
if ($nid_footer == 0) {
$output .= check_markup(variable_get('disclaimer_content_footer', ''), variable_get('disclaimer_content_footer_format', 1), FALSE);
}
else {
$output .= node_view(node_load($nid_footer), FALSE, TRUE);
}
return $output;
}
/**
* Calculate visibility of disclaimer if set
* function copy from block.module, thanks for the original code.
* @return bolean
*/
function _disclaimer_visibility() {
$visibility = variable_get('disclaimer_visibility', 0);
$pages = variable_get('disclaimer_pages', "admin/*\nuser");
if ($pages) {
if ($visibility < 2) {
$path = drupal_get_path_alias($_GET['q']);
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
$page_match = !($visibility xor $page_match);
}
else {
$page_match = drupal_eval($pages);
}
}
else {
$page_match = TRUE;
}
return $page_match;
}
/**
* function to set age form on disclaimer
* @return array an array of forms
*/
function disclaimer_age_form() {
$form['disclaimer_age'] = array(
'#type' => 'date',
'#title' => t('Date of Birth'),
'#description' => t('You must be at least @age years old to visit @site.', array(
'@age' => variable_get('disclaimer_age_limit', 18),
'@site' => variable_get('site_name', ''),
)),
);
return $form;
}
Functions
Name | Description |
---|---|
disclaimer_age_form | function to set age form on disclaimer |
disclaimer_init | Implementation of hook_init(). |
disclaimer_menu | Implementation of hook_menu(). |
disclaimer_perm | Implementation of hook_perm(). |
_disclaimer_get_content | Generate disclaimer content |
_disclaimer_visibility | Calculate visibility of disclaimer if set function copy from block.module, thanks for the original code. |