You are here

function popups_init in Popups API (Ajax Dialogs) 5

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

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 81
popups.module

Code

function popups_init() {
  $popups = popups_get_popups();
  if (isset($popups[$_GET['q']])) {
    popups_add_popups($popups[$_GET['q']]);
  }
  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.
    }
  }
}