getUserProfiledata($_REQUEST['token']); } catch (\LoginRadiusSDK\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'])); $checkCurrentProvider = $wpdb->get_var($wpdb->prepare('SELECT meta_value FROM ' . $wpdb->usermeta . ' WHERE user_id=%s AND meta_key = "loginradius_provider"', $user_ID)); // var_dump($checkCurrentProvider);die; 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 '1'; } else { //account already mapped return '0'; } } else { return '0'; } } else { $checkLinking = $wpdb->get_results('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key="loginradius_'.$loginRadiusUserprofile->Provider.'_id" AND user_id='.$user_ID.''); if(isset($checkLinking) && empty($checkLinking[0]->meta_key) && empty($checkLinking[0]->user_id) && $checkCurrentProvider != $loginRadiusMappingData['provider']){ //if($checkCurrentProvider != $loginRadiusMappingData['provider']){ $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 '0'; } else { // map account self::link_account($user_ID, $loginRadiusMappingData['id'], $loginRadiusMappingData['provider'], $loginRadiusMappingData['thumbnail'], $loginRadiusMappingData['pictureUrl']); return '1'; } } else { // map account self::link_account($user_ID, $loginRadiusMappingData['id'], $loginRadiusMappingData['provider'], $loginRadiusMappingData['thumbnail'], $loginRadiusMappingData['pictureUrl']); return '1'; } }else{ return '2'; } } } } /** * 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() { $linked = LR_Common::link_account_if_possible(); $redirectionUrl = LR_Common::get_protocol() . htmlspecialchars($_SERVER['HTTP_HOST']) . remove_query_arg('lrlinked'); if (strpos($redirectionUrl, '?') !== false) { $redirectionUrl .= '&'; }else { $redirectionUrl .= '?'; } $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 $loginRadiusSettings, $loginradius_api_settings, $lr_custom_interface_settings, $lr_raas_settings; if (! isset($loginradius_api_settings['raas_enable']) || $loginradius_api_settings['raas_enable'] != 1 ) { $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(trim(site_url(), '/')) . '/';//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 linked successfully', 'lr-plugin-slug'); }elseif($_GET['lrlinked'] == 'false'){ $html .= '
'; $html .= __('Account unlinked successfully', 'lr-plugin-slug'); }elseif($_GET['lrlinked'] == '2'){ $html .= '
'; $html .= __('Cannot link same provider', '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 .= ''; $isconnected = false; if ($loginRadiusLoggedIn == $tempId) { $append = 'Currently '; $connected = true; $isconnected = true; } else { $append = ''; } $html .= '' . $append; $html .= __('Connected with', 'lr-plugin-slug'); $html .= ' ' . ucfirst($map) . ''; if ((count($totalAccounts) > 1) && !$isconnected) { $html .= ''; } $html .= ''; } } } } $map = get_user_meta($user_ID, 'loginradius_provider', true); if ($map != false) { $html .= ''; $isconnected = false; $tempId = $loginRadiusLoggedIn; $append = !$connected ? 'Currently ' : ''; $html .= '' . $append; $html .= __('Connected with', 'lr-plugin-slug'); $html .= ' ' . ucfirst($map) . ' '; if (count($totalAccounts) > 1 && $isconnected) { $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 && $connected) { $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); } } }