You are here

function popups_init in Popups API (Ajax Dialogs) 6

Same name and namespace in other branches
  1. 5 popups.module \popups_init()
  2. 6.2 popups.module \popups_init()
  3. 7 popups.module \popups_init()

Implementation of hook_init().

Look at the page path and see if popup behavior has been requested for any links in this page.

File

./popups.module, line 49
This module provides a hook_popups for links to be openned in an Ajax Popup Dialog.

Code

function popups_init() {
  $popups = popups_get_popups();
  if (variable_get('popups_always_scan', 0)) {
    popups_add_popups();
  }
  foreach ($popups as $path => $popup_config) {
    if ($path == $_GET['q']) {
      popups_add_popups($popups[$path]);
    }
    elseif (strpos($path, '*') !== FALSE && drupal_match_path($_GET['q'], $path)) {
      popups_add_popups($popups[$path]);
    }
  }
  $render_mode = '';
  if (isset($_SERVER['HTTP_X_DRUPAL_RENDER_MODE'])) {
    $render_mode = $_SERVER['HTTP_X_DRUPAL_RENDER_MODE'];
  }

  // Check and see if the page_override param is in the URL.
  // Note - the magic happens here.
  // Need to cache the page_override flag in the session, so it will effect
  // the results page that follows a form submission.
  if ($render_mode == 'json/popups') {
    $_SESSION['page_override'] = TRUE;
  }

  // Move the page_override flag back out of the session.
  if (isset($_SESSION['page_override'])) {

    // This call will not return on form submission.
    $content = menu_execute_active_handler();

    // The call did return, so it wasn't a form request,
    // so we are returning a result, so clear the session flag.
    $override = $_SESSION['page_override'];
    unset($_SESSION['page_override']);

    // Menu status constants are integers; page content is a string.
    if (isset($content) && !is_int($content) && isset($override)) {
      print popups_render_as_json($content);
      exit;

      // Do not continue processing request in index.html.
    }
  }
}