function janrain_capture_widget_js in Janrain Registration 7.4
Same name and namespace in other branches
- 7.2 includes/janrain_capture.widget.inc \janrain_capture_widget_js()
- 7.3 includes/janrain_capture.widget.inc \janrain_capture_widget_js()
Returns Capture widget js.
2 calls to janrain_capture_widget_js()
- janrain_capture_oauth in includes/
janrain_capture.endpoints.inc - Callback for the janrain_capture/oauth menu item. This serves as the redirect_uri Capture redirects the user to and performs the authentication.
- janrain_capture_widget_add_scripts in includes/
janrain_capture.widget.inc - Adds widget JS scripts to the page.
1 string reference to 'janrain_capture_widget_js'
- janrain_capture_widget_add_scripts in includes/
janrain_capture.widget.inc - Adds widget JS scripts to the page.
File
- includes/
janrain_capture.widget.inc, line 230 - Widget-related functions
Code
function janrain_capture_widget_js() {
global $base_url;
global $base_path;
//global $language;
$country_id = $_SESSION['country_id'];
$country = janrain_capture_ui_get_country($country_id);
$janrain_capture_fields2 = variable_get('janrain_capture_fields2', array());
$janrain_settings = $janrain_capture_fields2[$country_id];
$janrain_capture_main2 = variable_get('janrain_capture_main2', array());
$janrain_capture_main2 = $janrain_capture_main2[$country_id];
$janrain_capture_ui2 = variable_get('janrain_capture_ui2', array());
$janrain_capture_ui2 = $janrain_capture_ui2[$country_id];
$janrain_capture_federate2 = variable_get('janrain_capture_federate2', array());
$janrain_capture_federate2 = $janrain_capture_federate2[$country_id];
$janrain_capture_backplane2 = variable_get('janrain_capture_backplane2', array());
$janrain_capture_backplane2 = $janrain_capture_backplane2[$country_id];
$janrain_settings = array_merge($janrain_settings, $janrain_capture_main2);
$janrain_settings = array_merge($janrain_settings, $janrain_capture_ui2);
$janrain_settings = array_merge($janrain_settings, $janrain_capture_federate2);
$janrain_settings = array_merge($janrain_settings, $janrain_capture_backplane2);
// module
$settings["plex.moduleVersion"] = JANRAIN_CAPTURE_MODULE_VERSION;
// capture
$settings["capture.redirectUri"] = url('janrain_capture/oauth', array(
'absolute' => TRUE,
));
$settings["capture.appId"] = $janrain_settings['capture_app_id'];
$settings["capture.clientId"] = $janrain_settings['capture_client_id'];
$settings["capture.responseType"] = "code";
$settings["capture.captureServer"] = $janrain_settings['capture_address'];
$settings["capture.loadJsUrl"] = $janrain_settings['capture_load_js_settings']['load_js'];
$share_settings = variable_get('janrain_capture_share', array());
$share_settings = $share_settings[$country_id];
if (isset($share_settings["enabled"]) && $share_settings["enabled"]) {
$settings["packages"] = '["login","capture","share"]';
}
else {
$settings["packages"] = '["login","capture"]';
}
// engage
$settings["appUrl"] = $janrain_settings['engage_address'];
// federate
$settings["capture.federate"] = $janrain_settings['capture_sso_enabled'];
$settings["capture.federateServer"] = 'https://' . $janrain_settings['capture_sso_address'];
$settings["capture.federateXdReceiver"] = $base_url . base_path() . drupal_get_path('module', 'janrain_capture') . '/xdcomm.html';
$settings["capture.federateLogoutUri"] = url('janrain_capture/simple_logout', array(
'absolute' => TRUE,
));
$settings["capture.federateSegment"] = isset($janrain_settings['capture_sso_segment_name']) ? $janrain_settings['capture_sso_segment_name'] : '';
if (isset($janrain_settings['capture_sso_supported_segment_names'])) {
$segment_names = explode(',', $janrain_settings['capture_sso_supported_segment_names']);
if ($segment_names) {
$settings["capture.federateSupportedSegments"] = json_encode($segment_names);
}
}
// backplane
$settings["capture.backplane"] = $janrain_settings['backplane_enabled'];
$settings["capture.backplaneServerBaseUrl"] = isset($janrain_settings['backplane_server_base_url']) ? $janrain_settings['backplane_server_base_url'] : '';
$settings["capture.backplaneBusName"] = $janrain_settings['backplane_bus_name'];
$settings["capture.backplaneVersion"] = $janrain_settings['backplane_version'];
// miscellaneous
$settings["capture.language"] = $country['language'];
$settings["mobileFriendly"] = empty($janrain_settings['mobile_friendly']) ? FALSE : (bool) $janrain_settings['mobile_friendly'];
if (module_exists('janrain_capture_screens')) {
$settings["capture.stylesheets"] = "'" . file_create_url(_janrain_capture_get_screen_file('stylesheets/styles.css')) . "'";
if ($mobile_stylesheet = _janrain_capture_get_screen_file('stylesheets/mobile-styles.css')) {
$settings["capture.mobileStylesheets"] = "'" . file_create_url($mobile_stylesheet) . "'";
}
if ($ie_stylesheet = _janrain_capture_get_screen_file('stylesheets/ie-styles.css')) {
$settings["capture.conditionalIEStylesheets"] = "'" . file_create_url($ie_stylesheet) . "'";
}
}
else {
$folder_url = variable_get('janrain_capture_screens_folder', 'file:///sites/all/themes/janrain-capture-screens/');
if (is_array($folder_url)) {
$folder_url = $folder_url[$_SESSION['country_id']];
}
// If path is local, search for user agent-specific stylesheets in the file system.
if (strpos($folder_url, 'file:///', 0) === 0) {
// Example of $folder_url: file:///sites/all/themes/janrain-capture-screens/
$web_path = str_replace('file://', '', $folder_url);
// Example of $web_path: /sites/all/themes/janrain-capture-screens/
$fs_path = DRUPAL_ROOT . $web_path;
// Example of $fs_path: /var/www/d7/sites/all/themes/janrain-capture-screens/
$web_url = $base_url . $web_path;
$base_stylesheet_path = "'{$web_url}stylesheets/janrain.css'";
$mobile_stylesheet_path = "'{$web_url}stylesheets/janrain_mobile.css'";
$ie_stylesheet_path = "'{$web_url}stylesheets/janrain_ie.css'";
$settings["capture.stylesheets"] = $base_stylesheet_path;
$settings["capture.mobileStylesheets"] = $mobile_stylesheet_path;
$settings["capture.conditionalIEStylesheets"] = $ie_stylesheet_path;
}
else {
// Remote stylesheets
$settings["capture.stylesheets"] = "'{$folder_url}stylesheets/janrain.css'";
$settings["capture.mobileStylesheets"] = "'{$folder_url}stylesheets/janrain_mobile.css'";
$settings["capture.conditionalIEStylesheets"] = "'{$folder_url}stylesheets/janrain_ie.css'";
}
// Log a warning if directories are setup properly but no stylesheets were found
if (!count($settings["capture.stylesheets"]) && !count($settings["capture.mobileStylesheets"]) && !count($settings["capture.conditionalIEStylesheets"])) {
watchdog('janrain_capture', 'No stylesheets were found in the screens folder (@path). Please check the Janrain Capture module settings.', array(
'@path' => $fs_path ?: $folder_url,
), WATCHDOG_WARNING, l(t('Janrain Capture module settings'), 'admin/config/people/janrain_capture'));
}
}
$output = <<<EOD
function janrainSignOut(){
janrain.capture.ui.endCaptureSession();
}
(function() {
if (typeof window.janrain !== 'object') window.janrain = {};
window.janrain.plex = {};
window.janrain.settings = {};
window.janrain.settings.capture = {};
// module settings
janrain.plex.moduleVersion = '{<span class="php-variable">$settings</span>[<span class="php-string">"plex.moduleVersion"</span>]}';
// capture settings
janrain.settings.capture.redirectUri = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.redirectUri"</span>]}';
janrain.settings.capture.appId= '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.appId"</span>]}';
janrain.settings.capture.clientId = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.clientId"</span>]}';
janrain.settings.capture.responseType = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.responseType"</span>]}';
janrain.settings.capture.captureServer = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.captureServer"</span>]}';
janrain.settings.capture.registerFlow = 'socialRegistration';
janrain.settings.packages = {<span class="php-variable">$settings</span>[<span class="php-string">'packages'</span>]};
janrain.settings.capture.setProfileCookie = true;
janrain.settings.capture.keepProfileCookieAfterLogout = true;
janrain.settings.capture.setProfileData = true;
janrain.settings.capture.federateEnableSafari = true;
// styles
janrain.settings.capture.stylesheets = [{<span class="php-variable">$settings</span>[<span class="php-string">"capture.stylesheets"</span>]}];
EOD;
// mobile styles
if (isset($settings["capture.mobileStylesheets"]) && $settings["capture.mobileStylesheets"] != '') {
$output .= "janrain.settings.capture.mobileStylesheets = [{$settings['capture.mobileStylesheets']}];\n";
}
//IE styles
if (isset($settings["capture.conditionalIEStylesheets"]) && $settings["capture.conditionalIEStylesheets"] != '') {
$output .= "janrain.settings.capture.conditionalIEStylesheets = [{$settings['capture.conditionalIEStylesheets']}];\n";
}
// captcha
$output .= "janrain.settings.capture.recaptchaPublicKey = '6LeVKb4SAAAAAGv-hg5i6gtiOV4XrLuCDsJOnYoP';\n";
$output .= <<<EOD
// engage settings
janrain.settings.appUrl = '{<span class="php-variable">$settings</span>[<span class="php-string">"appUrl"</span>]}';
janrain.settings.tokenAction = 'event';
EOD;
// Backplane
if ($settings["capture.backplane"]) {
$output .= <<<EOD
// backplane settings
janrain.settings.capture.backplane = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.backplane"</span>]}';
janrain.settings.capture.backplaneBusName = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.backplaneBusName"</span>]}';
janrain.settings.capture.backplaneVersion = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.backplaneVersion"</span>]}';
EOD;
if ($settings['capture.backplaneServerBaseUrl']) {
$output .= "janrain.settings.capture.backplaneServerBaseUrl = 'https://{$settings['capture.backplaneServerBaseUrl']}';\n";
}
}
if ($settings["capture.federate"]) {
$output .= <<<EOD
// federate settings
janrain.settings.capture.federate = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.federate"</span>]}';
janrain.settings.capture.federateServer = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.federateServer"</span>]}';
janrain.settings.capture.federateXdReceiver = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.federateXdReceiver"</span>]}';
janrain.settings.capture.federateLogoutUri = '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.federateLogoutUri"</span>]}';
EOD;
if (isset($settings["capture.federateSegment"])) {
$output .= "janrain.settings.capture.federateSegment = '{$settings["capture.federateSegment"]}';\n";
}
if (isset($settings["capture.federateSupportedSegments"])) {
$output .= "janrain.settings.capture.federateSupportedSegments = {$settings["capture.federateSupportedSegments"]};\n";
}
}
if ($settings["capture.language"]) {
$output .= "janrain.settings.language = '{$settings["capture.language"]}';\n";
}
if ($settings["mobileFriendly"]) {
global $base_root;
$current_url = $base_root . request_uri();
$_SESSION['janrain_capture_redirect_uri'] = $current_url;
$output .= "\n// mobile-specific settings\n janrain.settings.tokenAction = 'url';\n janrain.settings.popup = false;\n janrain.settings.tokenUrl = janrain.settings.capture.captureServer;\n janrain.settings.capture.redirectUri = '{$current_url}';\n janrain.settings.capture.redirectFlow = true;\n";
}
else {
if (isset($_SESSION['janrain_capture_redirect_uri'])) {
unset($_SESSION['janrain_capture_redirect_uri']);
}
}
if (!isset($_SESSION['janrain_capture_access_token'])) {
$api = new JanrainCaptureApi();
$api
->refreshAccessToken();
}
$access_token = "var access_token = '";
$access_token .= isset($_SESSION['janrain_capture_access_token']) ? $_SESSION['janrain_capture_access_token'] : "";
$access_token .= "';";
$output .= <<<EOD
function isReady() { janrain.ready = true; };
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", isReady, false);
} else {
window.attachEvent('onload', isReady);
}
var e = document.createElement('script');
e.type = 'text/javascript';
e.id = 'janrainAuthWidget';
var url = document.location.protocol === 'https:' ? 'https://' : 'http://';
url += '{<span class="php-variable">$settings</span>[<span class="php-string">"capture.loadJsUrl"</span>]}';
e.src = url;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(e, s);
})();
{<span class="php-variable">$access_token</span>}
EOD;
return $output;
}