You are here

function janrain_capture_page_build in Janrain Registration 7.4

Same name and namespace in other branches
  1. 7.2 janrain_capture.module \janrain_capture_page_build()
  2. 7.3 janrain_capture.module \janrain_capture_page_build()

Implements hook_page_build().

File

./janrain_capture.module, line 68
This module implements authentication endpoints for Janrain Capture.

Code

function janrain_capture_page_build(&$page) {
  global $user;

  // Check to see if settings are configured before proceeding
  if (!janrain_capture_configured()) {
    drupal_set_message(t('Janrain Capture: Capture cannot start because one or more settings is not properly configured.'), 'error');
    return;
  }
  if ($user->uid == 1 || !isset($_SESSION['country_id'])) {
    return;
  }

  // Get the selected version of Capture
  $janrain_capture_ver = variable_get('janrain_capture_ver', JANRAIN_CAPTURE_VERSION_DEFAULT);

  // Initialise Janrain Capture's Fancybox functions
  if ($janrain_capture_ver == JANRAIN_CAPTURE_VERSION_LEGACY) {
    module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.fancybox');
    janrain_capture_fancybox_init();
  }

  // Set up the settings array with values from the admin page
  $profile_sync_options = array(
    'absolute' => TRUE,
  );
  if ($_GET['q']) {
    $profile_sync_options['query'] = array(
      'destination' => $_GET['q'],
    );
  }
  $enforce = variable_get('janrain_capture_enforce', FALSE);
  $settings = array(
    'janrainCapture' => array(
      'profile_sync_url' => url('janrain_capture/profile_sync', $profile_sync_options),
      'token_expired_url' => url('janrain_capture/token_expired/' . drupal_get_token('janrain_capture_token_expired')),
      'logout_url' => url('user/logout', array(
        'absolute' => TRUE,
        'real_logout' => TRUE,
      )),
      //'enforce' => variable_get('janrain_capture_enforce', FALSE),
      'enforce' => $enforce[$_SESSION['country_id']],
      'ver' => $janrain_capture_ver,
      // janrain.settings.capture.redirectUri may be changed by JS to include
      // a destination param, depending on where the user clicks to start the
      // signin flow. Save the original redirect URL in case we need to roll
      // back.
      'originalRedirectUri' => url('janrain_capture/oauth', array(
        'absolute' => TRUE,
      )),
    ),
  );
  if ($janrain_capture_ver == JANRAIN_CAPTURE_VERSION_LEGACY) {
    module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.legacy');
    janrain_capture_legacy_add_js($settings);
  }
  else {
    if (!empty($_SESSION['janrain_capture_admin_signin'])) {
      unset($_SESSION['janrain_capture_admin_signin']);
      drupal_goto('janrain_capture/admin_signin');
    }
    module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.widget');
    janrain_capture_widget_add_settings($settings);
    janrain_capture_widget_add_scripts();

    // Add signin screens, but not to the user profile pages
    $path = current_path();
    if ($path === 'user' || strpos($path, 'user/') === 0) {
      return;
    }
    $html = _janrain_capture_widget_get_screen("signin", "html");
    $js = _janrain_capture_widget_get_screen("signin", "js");
    drupal_add_js($js, array(
      'type' => 'inline',
      'every_page' => TRUE,
      'weight' => 10,
      'preprocess' => FALSE,
    ));
    $page['page_bottom']['janrainCaptureSigninScreen'] = array(
      '#weight' => 0,
      '#markup' => $html,
    );
  }

  // Add the jQuery BBQ plugin to handle destination redirects.
  drupal_add_library('system', 'jquery.bbq', TRUE);
}