loginradius_get_user_profiledata($_REQUEST['token']); } catch ( LoginRadiusException $e ) { // Error Handling if ($loginRadiusSettings['enable_degugging'] == '0') { // if debugging is off and Social profile not recieved, redirect to home page. wp_redirect(site_url()); exit(); } else { $loginRadiusUserprofile = null; $message = isset( $e->getErrorResponse()->description ) ? $e->getErrorResponse()->description : $e->getMessage(); error_log( $message ); // If debug option is set and Social Profile not retrieved Login_Helper::login_radius_notify($message, 'isProfileNotRetrieved'); return; } } $loginRadiusMappingData['id'] = (!empty($loginRadiusUserprofile->ID) ? $loginRadiusUserprofile->ID : ''); $loginRadiusMappingData['provider'] = (!empty($loginRadiusUserprofile->Provider) ? $loginRadiusUserprofile->Provider : ''); $loginRadiusMappingData['thumbnail'] = (!empty($loginRadiusUserprofile->ThumbnailImageUrl) ? trim($loginRadiusUserprofile->ThumbnailImageUrl) : ''); if (empty($loginRadiusMappingData['thumbnail']) && $loginRadiusMappingData['provider'] == 'facebook') { $loginRadiusMappingData['thumbnail'] = 'http://graph.facebook.com/' . $loginRadiusMappingData['id'] . '/picture?type=large'; } $loginRadiusMappingData['pictureUrl'] = (!empty($loginRadiusUserprofile->ImageUrl) ? trim($loginRadiusUserprofile->ImageUrl) : ''); $wp_user_id = $wpdb->get_var($wpdb->prepare('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key="loginradius_provider_id" AND meta_value = %s', $loginRadiusMappingData['id'])); if ( ! empty( $wp_user_id ) ) { // Check if verified field exist or not. $loginRadiusVfyExist = $wpdb->get_var($wpdb->prepare('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE user_id = %d AND meta_key = "loginradius_isVerified"', $wp_user_id)); if (!empty($loginRadiusVfyExist)) { // if verified field exists $loginRadiusVerify = $wpdb->get_var($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->usermeta . ' WHERE user_id = %d AND meta_key = "loginradius_isVerified"', $wp_user_id)); if ($loginRadiusVerify != '1') { self::link_account($user_ID, $loginRadiusMappingData['id'], $loginRadiusMappingData['provider'], $loginRadiusMappingData['thumbnail'], $loginRadiusMappingData['pictureUrl']); return true; } else { //account already mapped return false; } } else { return false; } } else { $loginRadiusMappingProvider = $loginRadiusMappingData['provider']; $wp_user_lrid = $wpdb->get_var( $wpdb->prepare('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key="' . $loginRadiusMappingProvider . 'Lrid" AND meta_value = %s', $loginRadiusMappingData['id'])); if ( ! empty( $wp_user_lrid ) ) { $lrVerified = get_user_meta( $wp_user_lrid, $loginRadiusMappingProvider . 'LrVerified', true); if ($lrVerified == '1') { // Check if lrid is the same that verified email. // account already mapped return false; } else { // map account self::link_account( $user_ID, $loginRadiusMappingData['id'], $loginRadiusMappingData['provider'], $loginRadiusMappingData['thumbnail'], $loginRadiusMappingData['pictureUrl']); return true; } } else { // map account self::link_account( $user_ID, $loginRadiusMappingData['id'], $loginRadiusMappingData['provider'], $loginRadiusMappingData['thumbnail'], $loginRadiusMappingData['pictureUrl']); return true; } } } } /** * Get current protocol ( http OR https ) */ public static function get_protocol() { if ( isset( $_SERVER['HTTPS'] ) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { return 'https://'; } else { return 'http://'; } } /** * Update usermeta to store linked account information */ public static function link_account( $id, $lrid, $provider, $thumb, $pictureUrl ) { add_user_meta( $id, 'loginradius_provider_id', $lrid ); add_user_meta( $id, 'loginradius_mapped_provider', $provider ); add_user_meta( $id, 'loginradius_' . $provider . '_id', $lrid ); if ( $thumb != '' ) { add_user_meta( $id, 'loginradius_' . $lrid . '_thumbnail', $thumb ); } if ( $pictureUrl != '' ) { add_user_meta( $id, 'loginradius_' . $lrid . '_picture', $pictureUrl ); } } /** * Check if scripts are to be loaded in footer according to plugin option */ public static function scripts_in_footer_enabled() { global $loginradius_api_settings; if ( isset($loginradius_api_settings['scripts_in_footer'] ) && $loginradius_api_settings['scripts_in_footer'] == '1') { return true; } return false; } /** * Perform linking operation and return parameters if account mapped or not accordingly */ public static function perform_linking_operation() { // Public function call. if (LR_Common::link_account_if_possible() === true) { $linked = 1; } else { $linked = 0; } $redirectionUrl = LR_Common::get_protocol() . htmlspecialchars($_SERVER['HTTP_HOST']) . remove_query_arg('lrlinked'); if (strpos($redirectionUrl, '?') !== false) { $redirectionUrl .= '&lrlinked=' . $linked; } else { $redirectionUrl .= '?lrlinked=' . $linked; } wp_redirect($redirectionUrl); exit(); } public static function enqueue_login_scripts() { global $lr_custom_interface_settings; wp_enqueue_script('lr-sdk'); if ( isset( $lr_custom_interface_settings['custom_interface'] ) && $lr_custom_interface_settings['custom_interface'] == '1' ) { wp_enqueue_script('lr-custom-interface'); } else { wp_enqueue_script('lr-social-login'); } } /** * Loading Login Script for loggedin user to provide account linking */ public static function load_login_script( $isLinkingWidget = false ) { global $loginRadiusObject, $loginRadiusSettings, $loginradius_api_settings, $lr_custom_interface_settings, $lr_raas_settings; if( ! class_exists( 'LR_Raas_Install' ) ) { $loginradius_api_settings['LoginRadius_apikey'] = isset( $loginradius_api_settings['LoginRadius_apikey'] ) ? trim($loginradius_api_settings['LoginRadius_apikey']) : ''; if ( ! class_exists( 'Login_Helper' ) ) { require_once LOGINRADIUS_PLUGIN_DIR . 'public/inc/login/class-login-helper.php'; } $register = Login_Helper::is_register_page(); $location = urlencode( Login_Helper::get_redirect_url( '', $register ) ); if ( isset( $lr_custom_interface_settings['custom_interface']) && $lr_custom_interface_settings['custom_interface'] == '1' ) { if ( isset( $lr_custom_interface_settings['selected_providers'] ) && $lr_custom_interface_settings['selected_providers'] != '' ) { $selected_providers = implode( '\',\'', $lr_custom_interface_settings['selected_providers'] ); } $interface_url = LR_CUSTOM_INTERFACE_URL.'assets/images/custom_interface/'; if( is_multisite() ){ $interface_url .= get_current_blog_id().'/'; } ?> '; $html .= __('Account mapped successfully', 'lr-plugin-slug'); } else { $html .= '
'; $html .= __('This account is already mapped', 'lr-plugin-slug'); } $html .= '
'; return $html; } } /** * Display connectd/linked providers on user wp profile page */ public static function get_connected_providers_list() { global $user_ID; $html = ''; $loginRadiusMappings = get_user_meta($user_ID, 'loginradius_mapped_provider', false); $loginRadiusMappings = array_unique($loginRadiusMappings); $connected = false; $loginRadiusLoggedIn = get_user_meta( $user_ID, 'loginradius_current_id', true ); $totalAccounts = get_user_meta($user_ID, 'loginradius_provider_id' ); $location = LR_Common::get_protocol() . $_SERVER['HTTP_HOST'] . remove_query_arg( array('lrlinked', 'loginradius_linking', 'loginradius_post', 'loginradius_invite', 'loginRadiusMappingProvider', 'loginRadiusMap', 'loginRadiusMain')); if ( count( $loginRadiusMappings ) > 0 ) { foreach ($loginRadiusMappings as $map) { $loginRadiusMappingId = get_user_meta( $user_ID, 'loginradius_' . $map . '_id' ); if ( count( $loginRadiusMappingId ) > 0 ) { foreach ( $loginRadiusMappingId as $tempId ) { $html .= ''; if ( $loginRadiusLoggedIn == $tempId ) { $append = 'Currently '; $connected = true; } else { $append = ''; } $html .= '' . $append; $html .= __( 'Connected with', 'lr-plugin-slug' ); $html .= ' ' . ucfirst($map) . ''; if ( count( $totalAccounts) > 1 ) { $html .= ''; } $html .= ''; } } } } $map = get_user_meta($user_ID, 'loginradius_provider', true); if ($map != false) { $html .= ''; $tempId = $loginRadiusLoggedIn; $append = ! $connected ? 'Currently ' : ''; $html .= '' . $append; $html .= __( 'Connected with', 'lr-plugin-slug' ); $html .= ' ' . ucfirst( $map ) . ' '; if ( count( $totalAccounts ) != 1) { $html .= ''; } $html .= ''; } return $html; } /** * Display provider , user is currently connected with */ public static function display_currently_connected_provider() { global $user_ID; $loginRadiusLoggedIn = get_user_meta( $user_ID, 'loginradius_current_id', true ); $totalAccounts = get_user_meta($user_ID, 'loginradius_provider_id'); $location = LR_Common::get_protocol() . $_SERVER['HTTP_HOST'] . remove_query_arg(array('lrlinked', 'loginradius_linking', 'loginradius_post', 'loginradius_invite', 'loginRadiusMappingProvider', 'loginRadiusMap', 'loginRadiusMain')); $html = ''; $map = get_user_meta($user_ID, 'loginradius_provider', true); if ($map != false) { $html .= ''; $tempId = $loginRadiusLoggedIn; $append = 'Currently '; $html .= '' . $append; $html .= __('Connected with', 'lr-plugin-slug' ); $html .= ' ' . ucfirst($map) . ' '; if (count($totalAccounts) != 1) { $html .= ''; } $html .= ''; } return $html; } /** * Function which sends email on user activation to admin and users */ public static function login_radius_send_verification_email( $loginRadiusEmail, $loginRadiusKey, $loginRadiusProvider = '', $emailType = '', $username = '') { $loginRadiusSubject = ''; $loginRadiusMessage = ''; switch ($emailType) { case "activation": $loginRadiusSubject = '[' . htmlspecialchars( trim( get_option('blogname') ) ) . '] AccountActivation'; $loginRadiusMessage = 'Hi ' . $username . ", \r\n" . 'Your account has been activated at ' . site_url() . '. Now you can login to your account.'; break; case "admin notification": $user = get_userdata($username); $loginRadiusSubject = '[' . htmlspecialchars( trim( get_option('blogname') ) ) . '] New User Registration'; $loginRadiusMessage = 'New user registration on your site ' . htmlspecialchars( trim( get_option( 'blogname') ) ) . ": \r\n" . 'Username: ' . $user->user_login . " \r\n" . 'E-mail: ' . $user->user_email . ''; break; default: $loginRadiusSubject = '[' . htmlspecialchars( trim( get_option( 'blogname' ) ) ) . '] Email Verification'; $loginRadiusUrl = site_url() . '?loginRadiusVk=' . $loginRadiusKey; if ( ! empty( $loginRadiusProvider ) ) { $loginRadiusUrl .= '&loginRadiusProvider=' . $loginRadiusProvider; } $loginRadiusMessage = "Please click on the following link or paste it in browser to verify your email \r\n" . $loginRadiusUrl; break; } $headers = "MIME-Version: 1.0\n" . "Content-Type: text/plain; charset='" . get_option( 'blog_charset' ) . "\"\n" . 'From: '; wp_mail( $loginRadiusEmail, $loginRadiusSubject, $loginRadiusMessage, $headers ); } } }