You are here

function popup_message_init in Popup message 7

Same name and namespace in other branches
  1. 6 popup_message.module \popup_message_init()

Implements hook_init().

File

./popup_message.module, line 67
Main module file.

Code

function popup_message_init() {

  // Check permissions to display message.
  $permission = user_access('display popup message');

  // Get status: enabled/disabled.
  $status = variable_get('popup_message_enable', 1);

  // Allow other modules to modiffy permissions.
  drupal_alter('popup_message_permission', $permission);

  // Get popup message visibility settings.
  $visibility = variable_get('popup_message_visibility', POPUP_MESSAGE_VISIBILITY_NOTLISTED);

  // Get popup message visibility pages settings.
  $visibility_pages = variable_get('popup_message_visibility_pages', '');

  // Predefine value.
  $page_match = TRUE;

  // Limited visibility popup message must list at least one page.
  if ($visibility == POPUP_MESSAGE_VISIBILITY_LISTED && empty($visibility_pages)) {
    $status = FALSE;
  }

  // Match path if necessary.
  if ($visibility_pages && $status) {

    // Convert path to lowercase. This allows comparison of the same path
    // with different case. Ex: /Page, /page, /PAGE.
    $pages = drupal_strtolower($visibility_pages);
    if ($visibility < POPUP_MESSAGE_VISIBILITY_PHP) {

      // Convert the Drupal path to lowercase.
      $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

      // Compare the lowercase internal and lowercase path alias (if any).
      $page_match = drupal_match_path($path, $pages);
      if ($path != $_GET['q']) {
        $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
      }

      // When $visibility has a value of 0 (POPUP_MESSAGE_VISIBILITY_NOTLISTED),
      // the popup message is displayed on all pages except those listed in
      // $visibility_pages.
      // When set to 1 (POPUP_MESSAGE_VISIBILITY_LISTED), it is displayed only
      // on those
      // pages listed in $visibility_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),
    );

    // Allow other modules to modiffy message parameters.
    drupal_alter('popup_message_perameters', $popup_message_parameters);
    if ($message_title && $message_body) {
      popup_message_show_message($popup_message_parameters);
    }
  }
}