/** * Unlink the social account */ function the_champ_unlink() { if (isset($_POST['provider'])) { global $user_ID, $wpdb; $linkedAccounts = get_user_meta($user_ID, 'thechamp_linked_accounts', true); if ($linkedAccounts) { $linkedAccounts = maybe_unserialize($linkedAccounts); unset($linkedAccounts[$_POST['provider']]); update_user_meta($user_ID, 'thechamp_linked_accounts', maybe_serialize($linkedAccounts)); the_champ_ajax_response(array('status' => 1, 'message' => '')); } } die; }
/** * Prevent Social Login if registration is disabled */ function heateor_ss_disable_social_registration($profileData) { global $theChampLoginOptions; if (isset($theChampLoginOptions['disable_reg'])) { the_champ_ajax_response(array('status' => false, 'message' => 'registration disabled')); } }
/** * Get sharing count for providers */ function the_champ_sharing_count() { if (isset($_GET['urls']) && count($_GET['urls']) > 0) { $targetUrls = array_unique($_GET['urls']); foreach ($targetUrls as $k => $v) { $targetUrls[$k] = esc_attr($v); } } else { the_champ_ajax_response(array('status' => 0, 'message' => __('Invalid request'))); } global $theChampSharingOptions; $horizontalSharingNetworks = isset($theChampSharingOptions['providers']) ? $theChampSharingOptions['providers'] : array(); $verticalSharingNetworks = isset($theChampSharingOptions['vertical_providers']) ? $theChampSharingOptions['vertical_providers'] : array(); $sharingNetworks = array_unique(array_merge($horizontalSharingNetworks, $verticalSharingNetworks)); if (count($sharingNetworks) == 0) { the_champ_ajax_response(array('status' => 0, 'message' => __('Providers not selected'))); } $responseData = array(); foreach ($targetUrls as $targetUrl) { foreach ($sharingNetworks as $provider) { switch ($provider) { case 'facebook': $url = 'http://api.facebook.com/restserver.php?method=links.getStats&urls=' . $targetUrl . '&format=json&callback='; break; case 'twitter': $url = 'http://urls.api.twitter.com/1/urls/count.json?url=' . $targetUrl; break; case 'linkedin': $url = 'http://www.linkedin.com/countserv/count/share?url=' . $targetUrl . '&format=json'; break; case 'reddit': $url = 'http://www.reddit.com/api/info.json?url=' . $targetUrl; break; case 'delicious': $url = 'http://feeds.delicious.com/v2/json/urlinfo/data?url=' . $targetUrl; break; case 'pinterest': $url = 'http://api.pinterest.com/v1/urls/count.json?callback=theChamp&url=' . $targetUrl; break; case 'buffer': $url = 'https://api.bufferapp.com/1/links/shares.json?url=' . $targetUrl; break; case 'stumbleupon': $url = 'http://www.stumbleupon.com/services/1.01/badge.getinfo?url=' . $targetUrl; break; case 'google': $url = 'http://share.yandex.ru/gpp.xml?url=' . $targetUrl; break; case 'vkontakte': $url = 'https://vk.com/share.php?act=count&url=' . $targetUrl; break; default: $url = ''; } if ($url == '') { continue; } $response = wp_remote_get($url, array('timeout' => 15)); if (!is_wp_error($response) && isset($response['response']['code']) && 200 === $response['response']['code']) { $body = wp_remote_retrieve_body($response); if ($provider == 'pinterest') { $body = str_replace(array('theChamp(', ')'), '', $body); } if (!in_array($provider, array('google', 'vkontakte'))) { $body = json_decode($body); } switch ($provider) { case 'facebook': if (!empty($body[0]->total_count)) { $responseData[$targetUrl]['facebook'] = $body[0]->total_count; } else { $responseData[$targetUrl]['facebook'] = 0; } break; case 'twitter': if (!empty($body->count)) { $responseData[$targetUrl]['twitter'] = $body->count; } else { $responseData[$targetUrl]['twitter'] = 0; } break; case 'linkedin': if (!empty($body->count)) { $responseData[$targetUrl]['linkedin'] = $body->count; } else { $responseData[$targetUrl]['linkedin'] = 0; } break; case 'reddit': $responseData[$targetUrl]['reddit'] = 0; if (!empty($body->data->children)) { $children = $body->data->children; if (!empty($children[0]->data->score)) { $responseData[$targetUrl]['reddit'] = $children[0]->data->score; } } break; case 'delicious': if (!empty($body[0]->total_posts)) { $responseData[$targetUrl]['delicious'] = $body[0]->total_posts; } else { $responseData[$targetUrl]['delicious'] = 0; } break; case 'pinterest': if (!empty($body->count)) { $responseData[$targetUrl]['pinterest'] = $body->count; } else { $responseData[$targetUrl]['pinterest'] = 0; } break; case 'buffer': if (!empty($body->shares)) { $responseData[$targetUrl]['buffer'] = $body->shares; } else { $responseData[$targetUrl]['buffer'] = 0; } break; case 'stumbleupon': if (!empty($body->result) && isset($body->result->views)) { $responseData[$targetUrl]['stumbleupon'] = $body->result->views; } else { $responseData[$targetUrl]['stumbleupon'] = 0; } break; case 'google': if (!empty($body)) { $responseData[$targetUrl]['google'] = $body; } else { $responseData[$targetUrl]['google'] = 0; } break; case 'vkontakte': if (!empty($body)) { $responseData[$targetUrl]['vkontakte'] = $body; } else { $responseData[$targetUrl]['vkontakte'] = 0; } break; } } } } the_champ_ajax_response(array('status' => 1, 'message' => $responseData)); }
/** * Get sharing count for providers */ function the_champ_sharing_count() { if (isset($_GET['urls']) && count($_GET['urls']) > 0) { $targetUrls = array_unique($_GET['urls']); foreach ($targetUrls as $k => $v) { $targetUrls[$k] = esc_attr($v); } } else { the_champ_ajax_response(array('status' => 0, 'message' => __('Invalid request'))); } global $theChampSharingOptions; $horizontalSharingNetworks = isset($theChampSharingOptions['horizontal_re_providers']) ? $theChampSharingOptions['horizontal_re_providers'] : array(); $verticalSharingNetworks = isset($theChampSharingOptions['vertical_re_providers']) ? $theChampSharingOptions['vertical_re_providers'] : array(); $sharingNetworks = array_unique(array_merge($horizontalSharingNetworks, $verticalSharingNetworks)); if (count($sharingNetworks) == 0) { the_champ_ajax_response(array('status' => 0, 'message' => __('Providers not selected'))); } $tweetCountService = 'newsharecounts'; if (isset($theChampSharingOptions['tweet_count_service'])) { $tweetCountService = $theChampSharingOptions['tweet_count_service']; } elseif (isset($theChampSharingOptions['vertical_tweet_count_service'])) { $tweetCountService = $theChampSharingOptions['vertical_tweet_count_service']; } if ($tweetCountService == 'opensharecount') { $twitterCountApi = 'http://opensharecount.com/count.json?url='; } elseif ($tweetCountService == 'newsharecounts') { $twitterCountApi = 'http://public.newsharecounts.com/count.json?url='; } $responseData = array(); $multiplier = 60; switch ($theChampSharingOptions['share_count_cache_refresh_unit']) { case 'seconds': $multiplier = 1; break; case 'minutes': $multiplier = 60; break; case 'hours': $multiplier = 3600; break; case 'days': $multiplier = 3600 * 24; break; default: $multiplier = 60; break; } $transientExpirationTime = $multiplier * $theChampSharingOptions['share_count_cache_refresh_count']; foreach ($targetUrls as $targetUrl) { $shareCountTransient = array(); foreach ($sharingNetworks as $provider) { switch ($provider) { case 'facebook': $url = 'http://api.facebook.com/restserver.php?method=links.getStats&urls=' . $targetUrl . '&format=json&callback='; break; case 'twitter': $url = $twitterCountApi . $targetUrl; break; case 'linkedin': $url = 'http://www.linkedin.com/countserv/count/share?url=' . $targetUrl . '&format=json'; break; case 'reddit': $url = 'http://www.reddit.com/api/info.json?url=' . $targetUrl; break; case 'delicious': $url = 'http://feeds.delicious.com/v2/json/urlinfo/data?url=' . $targetUrl; break; case 'pinterest': $url = 'http://api.pinterest.com/v1/urls/count.json?callback=theChamp&url=' . $targetUrl; break; case 'buffer': $url = 'https://api.bufferapp.com/1/links/shares.json?url=' . $targetUrl; break; case 'stumbleupon': $url = 'http://www.stumbleupon.com/services/1.01/badge.getinfo?url=' . $targetUrl; break; case 'google_plus': $url = 'http://share.yandex.ru/gpp.xml?url=' . $targetUrl; break; case 'vkontakte': $url = 'https://vk.com/share.php?act=count&url=' . $targetUrl; break; default: $url = ''; } if ($url == '') { continue; } $response = wp_remote_get($url, array('timeout' => 15)); if (!is_wp_error($response) && isset($response['response']['code']) && 200 === $response['response']['code']) { $body = wp_remote_retrieve_body($response); if ($provider == 'pinterest') { $body = str_replace(array('theChamp(', ')'), '', $body); } if (!in_array($provider, array('google', 'vkontakte'))) { $body = json_decode($body); } switch ($provider) { case 'facebook': if (!empty($body[0]->total_count)) { $responseData[$targetUrl]['facebook'] = $body[0]->total_count; $shareCountTransient['facebook'] = $body[0]->total_count; } else { $responseData[$targetUrl]['facebook'] = 0; } break; case 'twitter': if (!empty($body->count)) { $responseData[$targetUrl]['twitter'] = $body->count; $shareCountTransient['twitter'] = $body->count; } else { $responseData[$targetUrl]['twitter'] = 0; } break; case 'linkedin': if (!empty($body->count)) { $responseData[$targetUrl]['linkedin'] = $body->count; $shareCountTransient['linkedin'] = $body->count; } else { $responseData[$targetUrl]['linkedin'] = 0; } break; case 'reddit': $responseData[$targetUrl]['reddit'] = 0; if (!empty($body->data->children)) { $children = $body->data->children; if (!empty($children[0]->data->score)) { $responseData[$targetUrl]['reddit'] = $children[0]->data->score; $shareCountTransient['reddit'] = $children[0]->data->score; } } break; case 'delicious': if (!empty($body[0]->total_posts)) { $responseData[$targetUrl]['delicious'] = $body[0]->total_posts; $shareCountTransient['delicious'] = $body[0]->total_posts; } else { $responseData[$targetUrl]['delicious'] = 0; } break; case 'pinterest': if (!empty($body->count)) { $responseData[$targetUrl]['pinterest'] = $body->count; $shareCountTransient['pinterest'] = $body->count; } else { $responseData[$targetUrl]['pinterest'] = 0; } break; case 'buffer': if (!empty($body->shares)) { $responseData[$targetUrl]['buffer'] = $body->shares; $shareCountTransient['buffer'] = $body->shares; } else { $responseData[$targetUrl]['buffer'] = 0; } break; case 'stumbleupon': if (!empty($body->result) && isset($body->result->views)) { $responseData[$targetUrl]['stumbleupon'] = $body->result->views; $shareCountTransient['stumbleupon'] = $body->result->views; } else { $responseData[$targetUrl]['stumbleupon'] = 0; } break; case 'google_plus': if (!empty($body)) { $responseData[$targetUrl]['google_plus'] = $body; $shareCountTransient['google_plus'] = (int) str_replace('"', '', $body); } else { $responseData[$targetUrl]['google_plus'] = 0; } break; case 'vkontakte': if (!empty($body)) { $responseData[$targetUrl]['vkontakte'] = $body; $shareCountTransient['vkontakte'] = (int) str_replace(array('VK.Share.count(0, ', ');'), '', $body); } else { $responseData[$targetUrl]['vkontakte'] = 0; } break; } } } set_transient('heateor_ss_share_count_' . heateor_ss_get_share_count_transient_id($targetUrl), $shareCountTransient, $transientExpirationTime); } do_action('heateor_ss_share_count_ajax_hook', $responseData); the_champ_ajax_response(array('status' => 1, 'message' => $responseData)); }
/** * Save email submitted in popup */ function the_champ_save_email() { if (isset($_POST['elemId'])) { $elementId = trim($_POST['elemId']); if (isset($_POST['id']) && ($id = trim($_POST['id'])) != '') { if ($elementId == 'save') { global $theChampLoginOptions; $email = isset($_POST['email']) ? trim(esc_attr($_POST['email'])) : ''; // validate email if (is_email($email) && !email_exists($email)) { if (($tempData = get_user_meta($id, 'the_champ_temp_data', true)) != '') { delete_user_meta($id, 'the_champ_temp_data'); // get temp data unserialized $tempData = maybe_unserialize($tempData); $tempData['email'] = $email; if (isset($theChampLoginOptions['email_verification']) && $theChampLoginOptions['email_verification'] == 1) { $verify = true; } else { $verify = false; } // create new user $userId = the_champ_create_user($tempData, $verify); if ($userId && !$verify) { // login user the_champ_login_user($userId, array(), $tempData['id']); if (isset($theChampLoginOptions['register_redirection']) && $theChampLoginOptions['register_redirection'] == 'same' && isset($tempData['twitter_redirect'])) { the_champ_ajax_response(array('status' => 1, 'message' => array('response' => 'success', 'url' => $tempData['twitter_redirect']))); } elseif (isset($theChampLoginOptions['register_redirection']) && $theChampLoginOptions['register_redirection'] == 'bp_profile') { the_champ_ajax_response(array('status' => 1, 'message' => array('response' => 'success', 'url' => bp_core_get_user_domain($userId)))); } else { the_champ_ajax_response(array('status' => 1, 'message' => 'success')); } } elseif ($userId && $verify) { $verificationKey = $userId . time() . mt_rand(); update_user_meta($userId, 'thechamp_key', $verificationKey); the_champ_send_verification_email($email, $verificationKey); the_champ_ajax_response(array('status' => 1, 'message' => 'verify')); } } } else { the_champ_ajax_response(array('status' => 0, 'message' => isset($theChampLoginOptions['email_error_message']) ? __($theChampLoginOptions['email_error_message'], 'Super-Socializer') : '')); } } // delete temporary data delete_user_meta($id, 'the_champ_temp_data'); the_champ_ajax_response(array('status' => 1, 'message' => 'cancelled')); } } die; }