View source
<?php
define('POPUP_MESSAGE_CSS_NAME', 'popup.css');
define('POPUP_MESSAGE_THEME_STYLE_DIR', 'popup_message_styles');
define('POPUP_MESSAGE_VISIBILITY_NOTLISTED', 0);
define('POPUP_MESSAGE_VISIBILITY_LISTED', 1);
define('POPUP_MESSAGE_VISIBILITY_PHP', 2);
function popup_message_help($path, $arg) {
switch ($path) {
case 'admin/help#popup_message':
$output = '<p>' . t('Display popup message for users once per browser session.') . '</p>';
$output .= '<p>' . t('Configuration') . ':</p>';
$output .= '<ul>';
$output .= '<li>' . t('Go to admin/settings/popup_message and set message title and body.') . '</li>';
$output .= '<li>' . t('Go to admin/user/permissions and set permissions.') . '</li>';
$output .= '</ul>';
return $output;
}
}
function popup_message_permission() {
return array(
'popup message administration' => array(
'title' => t('Administer Popup message module'),
'description' => t('Perform administration tasks for Popup message module.'),
),
'display popup message' => array(
'title' => t('Display popup message'),
'description' => t('Allow users to see popup message.'),
),
);
}
function popup_message_menu() {
$items = array();
$items['admin/config/user-interface/popup_message'] = array(
'title' => 'Popup message',
'description' => 'Popup message configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'popup_message_settings',
),
'file' => 'popup_message.admin.inc',
'access arguments' => array(
'popup message administration',
),
);
return $items;
}
function popup_message_init() {
$permission = user_access('display popup message');
$status = variable_get('popup_message_enable', 1);
drupal_alter('popup_message_permission', $permission);
$visibility = variable_get('popup_message_visibility', POPUP_MESSAGE_VISIBILITY_NOTLISTED);
$visibility_pages = variable_get('popup_message_visibility_pages', '');
$page_match = TRUE;
if ($visibility == POPUP_MESSAGE_VISIBILITY_LISTED && empty($visibility_pages)) {
$status = FALSE;
}
if ($visibility_pages && $status) {
$pages = drupal_strtolower($visibility_pages);
if ($visibility < POPUP_MESSAGE_VISIBILITY_PHP) {
$path = drupal_strtolower(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);
}
elseif (module_exists('php')) {
$page_match = php_eval($visibility_pages);
}
else {
$page_match = FALSE;
}
}
if ($permission && $status && $page_match) {
$message_title = filter_xss(variable_get('popup_message_title', ''));
$message_body_variable = variable_get('popup_message_body');
$message_body = check_markup($message_body_variable['value'], $message_body_variable['format'] ? $message_body_variable['format'] : variable_get('filter_default_format', NULL), FALSE);
$popup_message_parameters = array(
'title' => $message_title,
'body' => $message_body,
'check_cookie' => variable_get('popup_message_check_cookie', 1),
'width' => variable_get('popup_message_width', 300),
'height' => variable_get('popup_message_height', 300),
'delay' => variable_get('popup_message_delay', 0),
);
drupal_alter('popup_message_perameters', $popup_message_parameters);
if ($message_title && $message_body) {
popup_message_show_message($popup_message_parameters);
}
}
}
function popup_message_show_message($popup_message_parameters) {
drupal_add_js(array(
'popup_message' => $popup_message_parameters,
), 'setting');
drupal_add_js('misc/jquery.cookie.js');
drupal_add_js(drupal_get_path('module', 'popup_message') . '/js/popup.js');
$default_style = drupal_get_path('module', 'popup_message') . '/styles/default/' . POPUP_MESSAGE_CSS_NAME;
$style = variable_get('popup_message_style', $default_style);
if (!file_exists($style)) {
$style = $default_style;
}
drupal_add_css($style);
}