janrain_capture_ui.module in Janrain Registration 6
Same filename and directory in other branches
This module implements UI elements for Janrain Capture
File
janrain_capture_ui.moduleView source
<?php
/**
* @file
* This module implements UI elements for Janrain Capture
*
* @see http://www.janrain.com/products/capture
*/
/**
* Implements hook_init().
*/
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);
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function janrain_capture_ui_form_user_profile_form_alter(&$form, $form_state) {
global $user;
$link = l(t('Edit Profile'), 'janrain_capture/profile', array(
'absolute' => TRUE,
'attributes' => array(
'class' => 'iframe fancy janrain_capture_anchor',
),
));
$markup = '<div class="form-item">' . $link . '</div>';
if ($user->uid == $form['#uid']) {
$form['account'] = array(
'#type' => 'fieldset',
'#title' => t('My Account'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['account']['description'] = array(
'#type' => 'markup',
'#value' => $markup,
);
}
}
/**
* Implements hook_menu_alter().
*/
function janrain_capture_ui_menu_alter(&$items) {
$items['user/register']['access callback'] = 'user_access';
$items['user/register']['access arguments'] = array(
'administer users',
);
$items['user/password']['access callback'] = 'user_access';
$items['user/password']['access arguments'] = array(
'administer users',
);
}
/**
* Implements of hook_block().
*/
function janrain_capture_ui_block($op = 'list', $delta = 0, $edit = array()) {
$janrain_capture_optional = variable_get('janrain_capture_optional', array());
global $user;
$items = array();
if ($user->uid) {
$items[] = l(t('View / Edit Profile'), 'janrain_capture/profile', array(
'absolute' => TRUE,
'attributes' => array(
'class' => 'iframe fancy janrain_capture_anchor',
),
));
if ($janrain_capture_optional['capture_sso_address']) {
$items[] = '<a href="javascript:janrain_capture_logout()">' . t('Log out') . '</a>';
}
else {
$items[] = l(t('Log out'), 'logout');
}
}
else {
$items[] = l(t('Register / Sign in'), janrain_capture_url(), array(
'attributes' => array(
'class' => 'iframe fancy janrain_capture_anchor janrain_capture_signin',
),
));
}
switch ($op) {
case 'list':
$block[0]['info'] = t('Janrain Capture user login');
break;
case 'view':
$block['subject'] = t('Janrain Capture');
$block['content'] = theme('item_list', $items);
break;
}
return $block;
}
Functions
Name | Description |
---|---|
janrain_capture_ui_block | Implements of hook_block(). |
janrain_capture_ui_form_user_profile_form_alter | Implements hook_form_FORM_ID_alter(). |
janrain_capture_ui_init | Implements hook_init(). |
janrain_capture_ui_menu_alter | Implements hook_menu_alter(). |