function janrain_capture_ui_init in Janrain Registration 6
Same name and namespace in other branches
- 7 janrain_capture_ui.module \janrain_capture_ui_init()
Implements hook_init().
File
- ./
janrain_capture_ui.module, line 13 - This module implements UI elements for Janrain Capture
Code
function janrain_capture_ui_init() {
global $user;
$janrain_capture_main = variable_get('janrain_capture_main', array());
$janrain_capture_optional = variable_get('janrain_capture_optional', array());
$janrain_capture_dependencies = variable_get('janrain_capture_dependencies', array());
// Don't do anything if the module settings have not been configured.
if (!isset($janrain_capture_main['capture_address']) || !isset($janrain_capture_main['capture_client_id']) || !isset($janrain_capture_main['capture_client_secret'])) {
return;
}
$capture_sso_address = !empty($janrain_capture_optional['capture_sso_address']) ? $janrain_capture_optional['capture_sso_address'] : '';
$capture_client_id = !empty($janrain_capture_main['capture_client_id']) ? $janrain_capture_main['capture_client_id'] : '';
$uri_opts = array(
'absolute' => TRUE,
);
if ($_GET['q']) {
$uri_opts['query'] = array(
'destination' => $_GET['q'],
);
}
$settings = array(
'janrainCapture' => array(
'profile_sync_url' => url('janrain_capture/profile_sync', $uri_opts),
'token_expired_url' => url('janrain_capture/token_expired/' . drupal_get_token('janrain_capture_token_expired')),
'logout_url' => url('user/logout', array(
'absolute' => TRUE,
)),
),
);
if (!empty($capture_sso_address)) {
$settings['janrainCapture']['sso_address'] = $capture_sso_address;
}
if (!empty($janrain_capture_optional['backplane_server']) && !empty($janrain_capture_optional['backplane_bus_name'])) {
$settings['janrainCapture']['backplane_server'] = $janrain_capture_optional['backplane_server'];
$settings['janrainCapture']['backplane_bus_name'] = $janrain_capture_optional['backplane_bus_name'];
}
drupal_add_js($settings, 'setting');
drupal_set_html_head('<script src="https://d7v0k4dt27zlp.cloudfront.net/assets/capture_client.js" type="text/javascript"></script>');
if (!empty($capture_sso_address)) {
drupal_set_html_head('<script src="https://' . $capture_sso_address . '/sso.js" type="text/javascript"></script>');
}
if (!empty($janrain_capture_optional['backplane_js_path'])) {
drupal_set_html_head('<script src="' . $janrain_capture_optional['backplane_js_path'] . '" type="text/javascript"></script>');
}
$scripts = array(
'module' => array(),
'inline' => array(),
);
$scripts['module'][] = !empty($janrain_capture_dependencies['capture_json2']) ? $janrain_capture_dependencies['capture_json2'] : 'sites/all/libraries/json2/json2.js';
$scripts['module'][] = !empty($janrain_capture_dependencies['capture_fancy_js']) ? $janrain_capture_dependencies['capture_fancy_js'] : 'sites/all/libraries/fancybox/jquery.fancybox-1.3.4.pack.js';
$scripts['module'][] = drupal_get_path('module', 'janrain_capture') . '/janrain_capture_ui.js';
$styles = array();
$styles[] = !empty($janrain_capture_dependencies['capture_fancy_css']) ? $janrain_capture_dependencies['capture_fancy_css'] : 'sites/all/libraries/fancybox/jquery.fancybox-1.3.4.css';
if (!empty($capture_sso_address)) {
$scripts['inline'][] = 'JANRAIN.SSO.CAPTURE.check_login({
sso_server: "https://' . $capture_sso_address . '",
client_id: "' . $capture_client_id . '",
redirect_uri: "' . url('janrain_capture/oauth', array(
'absolute' => TRUE,
)) . '",
logout_uri: "' . url('logout', array(
'absolute' => TRUE,
)) . '",
xd_receiver: "' . url(NULL, array(
'absolute' => TRUE,
)) . drupal_get_path('module', 'janrain_capture') . '/xdcomm.html"
});';
}
if (isset($_SESSION['janrain_capture_password_recover']) && $_SESSION['janrain_capture_password_recover'] == TRUE) {
$scripts['inline'][] = 'jQuery(function($) {
$.fancybox({
type: "iframe",
href: "' . url('janrain_capture/profile', array(
'absolute' => TRUE,
'query' => array(
'method' => '_change_password',
'callback' => 'CAPTURE.closeRecoverPassword',
),
)) . '",
padding: 0,
scrolling: "no",
autoScale: true,
width: 666,
autoDimensions: false
});
});';
$_SESSION['janrain_capture_password_recover'] = FALSE;
}
$final_scripts = module_invoke_all('janrain_capture_add_js', $scripts);
$final_styles = module_invoke_all('janrain_capture_add_css', $styles);
if (is_array($final_scripts) && !empty($final_scripts)) {
$scripts = $final_scripts;
}
if (is_array($final_styles) && !empty($final_styles)) {
$styles = $final_styles;
}
if (isset($scripts['module']) && is_array($scripts['module'])) {
foreach ($scripts['module'] as $s) {
drupal_add_js($s, 'module');
}
}
if (isset($scripts['inline']) && is_array($scripts['inline'])) {
foreach ($scripts['inline'] as $s) {
drupal_add_js($s, 'inline');
}
}
if (is_array($styles)) {
foreach ($styles as $s) {
drupal_add_css($s);
}
}
}