View source
<?php
define('POPUP_MESSAGE_JQUERYCOOKIE_PATH', 'sites/all/libraries/jquery.cookie');
define('POPUP_MESSAGE_CSS_NAME', 'popup.css');
define('POPUP_MESSAGE_THEME_STYLE_DIR', 'popup_message_styles');
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_perm() {
return array(
'popup message administration',
'display popup message',
);
}
function popup_message_menu() {
$items = array();
$items['admin/settings/popup_message'] = array(
'title' => 'Popup message',
'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);
if ($permission && $status) {
$message_title = filter_xss(variable_get('popup_message_title', ''));
$message_body = check_markup(variable_get('popup_message_body_text', ''), variable_get('popup_message_body_format', variable_get('filter_default_format', 1)), 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),
);
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(popup_message_get_jquerycookie_path() . '/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);
}
function popup_message_get_jquerycookie_path() {
static $library_path = NULL;
if ($library_path == NULL) {
$path = variable_get('popup_message_jquerycookie_path', POPUP_MESSAGE_JQUERYCOOKIE_PATH);
if (is_dir($path . '/jquery.cookie')) {
$library_path = $path;
}
elseif ($library_path == NULL && module_exists('libraries')) {
if ($path = libraries_get_path('jquery.cookie')) {
$library_path = $path;
variable_set('popup_message_jquerycookie_path', $library_path);
}
}
elseif ($library_path == NULL) {
$library_path = POPUP_MESSAGE_JQUERYCOOKIE_PATH;
}
}
return $library_path;
}