You are here

function janrain_capture_page_build in Janrain Registration 7.3

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

Implements hook_page_build().

File

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

Code

function janrain_capture_page_build(&$page) {

  // 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;
  }

  // Initialise Janrain Capture's Fancybox functions
  module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.fancybox');
  janrain_capture_fancybox_init();

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

  // 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'],
    );
  }
  $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),
      '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,
      )),
    ),
  );

  // Set up the scripts array
  $scripts = array(
    'file' => array(),
    'inline' => array(),
    'external' => array(),
  );
  $scripts['file'][] = drupal_get_path('module', 'janrain_capture') . '/janrain_capture.js';
  if ($janrain_capture_ver == JANRAIN_CAPTURE_VERSION_LEGACY) {
    module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.legacy');
    janrain_capture_legacy_add_settings($settings);
    janrain_capture_legacy_add_scripts($scripts);
  }
  else {
    module_load_include('inc', 'janrain_capture', 'includes/janrain_capture.widget');
    janrain_capture_widget_add_settings($settings);
    janrain_capture_widget_add_scripts($scripts);
    $screens = janrain_capture_widget_signin_screens();
    drupal_add_js($screens['js'], array(
      'type' => 'inline',
      'every_page' => TRUE,
      'weight' => 4,
      'preprocess' => FALSE,
    ));
    $page['page_bottom']['janrainCaptureSigninScreen'] = array(
      '#weight' => 0,
      '#markup' => $screens['html'],
    );
  }

  /*$capture_client_id = !empty($janrain_capture_main['capture_client_id'])
    ? $janrain_capture_main['capture_client_id'] : '';*/

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