Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
1,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 112.69 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Super Socializer
  4. Plugin URI: https://super-socializer-wordpress.heateor.com
  5. Description: A complete 360 degree solution to provide all the social features like Social Login, Social Commenting, Social Sharing, Social Media follow and more.
  6. Version: 7.11.10
  7. Author: Team Heateor
  8. Author URI: https://www.heateor.com
  9. Text Domain: super-socializer
  10. Domain Path: /languages
  11. License: GPL2+
  12. */
  13. defined('ABSPATH') or die("Cheating........Uh!!");
  14. define('THE_CHAMP_SS_VERSION', '7.11.10');
  15.  
  16. require 'helper.php';
  17.  
  18. $theChampLoginOptions = get_option('the_champ_login');
  19. if(the_champ_social_login_enabled()){
  20.     if(isset($theChampLoginOptions['providers']) && in_array('twitter', $theChampLoginOptions['providers'])){
  21.         require 'library/twitteroauth.php';
  22.     }
  23.     if(isset($theChampLoginOptions['providers']) && (in_array('xing', $theChampLoginOptions['providers']) || in_array('linkedin', $theChampLoginOptions['providers']))){
  24.         $theChampOauthConfigurationFile = plugins_url('library/oauth_configuration.json', __FILE__);
  25.         require 'library/http.php';
  26.         require 'library/oauth_client.php';
  27.     }
  28.     if(isset($theChampLoginOptions['providers']) && in_array('steam', $theChampLoginOptions['providers'])){
  29.         require 'library/SteamLogin/SteamLogin.php';
  30.         $theChampSteamLogin = new SteamLogin();
  31.     }
  32. }
  33.  
  34. $theChampFacebookOptions = get_option('the_champ_facebook');
  35. $theChampSharingOptions = get_option('the_champ_sharing');
  36. $theChampCounterOptions = get_option('the_champ_counter');
  37. $theChampGeneralOptions = get_option('the_champ_general');
  38.  
  39. $theChampIsBpActive = false;
  40.  
  41. // include social login functions
  42. require 'inc/social_login.php';
  43.  
  44. // include social sharing functions
  45. if(the_champ_social_sharing_enabled() || the_champ_social_counter_enabled()){
  46.     require 'inc/social_sharing_networks.php';
  47.     require 'inc/social_sharing.php';
  48. }
  49. //include widget class
  50. require 'inc/widget.php';
  51. //include shortcode
  52. require 'inc/shortcode.php';
  53.  
  54. /**
  55.  * Hook the plugin function on 'init' event.
  56.  */
  57. function the_champ_init(){
  58.     global $theChampSharingOptions;
  59.     add_action('wp_enqueue_scripts', 'the_champ_load_event');
  60.     add_action('wp_enqueue_scripts', 'the_champ_frontend_scripts');
  61.     add_action('wp_enqueue_scripts', 'the_champ_frontend_styles');
  62.     add_action('login_enqueue_scripts', 'the_champ_load_event');
  63.     add_action('login_enqueue_scripts', 'the_champ_frontend_scripts');
  64.     add_action('login_enqueue_scripts', 'the_champ_frontend_styles');
  65.     add_action('parse_request', 'the_champ_connect');
  66.     load_plugin_textdomain('super-socializer', false, dirname(plugin_basename(__FILE__)).'/languages/');
  67.     if(heateor_ss_is_plugin_active('woocommerce/woocommerce.php')){
  68.         add_action('the_champ_user_successfully_created', 'the_champ_sync_woocom_profile', 10, 3);
  69.     }
  70.     if(isset($theChampSharingOptions['amp_enable'])){
  71.         // CSS for AMP pages
  72.         add_action('amp_post_template_css', 'the_champ_frontend_amp_css');
  73.     }
  74. }
  75. add_action('init', 'the_champ_init');
  76.  
  77. /**
  78.  * Sync social profile data with WooCommerce billing and shipping address
  79.  */
  80. function the_champ_sync_woocom_profile($userId, $userdata, $profileData){
  81.     $billingFirstName = get_user_meta($userId, 'billing_first_name', true);
  82.     $billingLastName = get_user_meta($userId, 'billing_last_name', true);
  83.     $billingEmail = get_user_meta($userId, 'billing_email', true);
  84.    
  85.     $shippingFirstName = get_user_meta($userId, 'shipping_first_name', true);
  86.     $shippingLastName = get_user_meta($userId, 'shipping_last_name', true);
  87.     $shippingEmail = get_user_meta($userId, 'shipping_email', true);
  88.  
  89.     // create username, firstname and lastname
  90.     $usernameFirstnameLastname = explode('|tc|', the_champ_create_username($profileData));
  91.     $username = $usernameFirstnameLastname[0];
  92.     $firstName = $usernameFirstnameLastname[1];
  93.     $lastName = $usernameFirstnameLastname[2];
  94.    
  95.  
  96.     if($firstName || $username){
  97.         if(!$billingFirstName){
  98.             update_user_meta($userId, 'billing_first_name', $firstName ? $firstName : $username);
  99.         }
  100.         if(!$shippingFirstName){
  101.             update_user_meta($userId, 'shipping_first_name', $firstName ? $firstName : $username);
  102.         }
  103.     }
  104.     if($lastName){
  105.         if(!$billingLastName){
  106.             update_user_meta($userId, 'billing_last_name', $lastName);
  107.         }
  108.         if(!$shippingLastName){
  109.             update_user_meta($userId, 'shipping_last_name', $lastName);
  110.         }
  111.     }
  112.     if(!empty($profileData['email'])){
  113.         if(!$billingEmail){
  114.             update_user_meta($userId, 'billing_email', $profileData['email']);
  115.         }
  116.         if(!$shippingEmail){
  117.             update_user_meta($userId, 'shipping_email', $profileData['email']);
  118.         }
  119.     }
  120. }
  121.  
  122. function the_champ_load_event(){
  123.     ?>
  124.     <script>function theChampLoadEvent(e){var t=window.onload;if(typeof window.onload!="function"){window.onload=e}else{window.onload=function(){t();e()}}}</script>
  125.     <?php
  126. }
  127.  
  128. /**
  129.  * Check querystring variables
  130.  */
  131. function the_champ_connect(){
  132.     global $theChampLoginOptions;
  133.  
  134.     // verify email
  135.     if((isset($_GET['SuperSocializerKey']) && ($verificationKey = sanitize_text_field($_GET['SuperSocializerKey'])) != '') || (isset($_GET['supersocializerkey']) && ($verificationKey = sanitize_text_field($_GET['supersocializerkey'])) != '')){
  136.         $users = get_users('meta_key=thechamp_key&meta_value='.$verificationKey);
  137.         if(count($users) > 0 && isset($users[0] -> ID)){
  138.             delete_user_meta($users[0] -> ID, 'thechamp_key');
  139.             wp_redirect(esc_url(home_url()).'?SuperSocializerVerified=1');
  140.             die;
  141.         }
  142.     }
  143.    
  144.     // Instagram auth
  145.     if(isset($_GET['SuperSocializerInstaToken']) && trim($_GET['SuperSocializerInstaToken']) != ''){
  146.         $instaAuthUrl = 'https://api.instagram.com/v1/users/self?access_token=' . sanitize_text_field($_GET['SuperSocializerInstaToken']);
  147.         $response = wp_remote_get( $instaAuthUrl,  array( 'timeout' => 15 ) );
  148.         if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ){
  149.             $body = json_decode(wp_remote_retrieve_body( $response ));
  150.             if(is_object($body -> data) && isset($body -> data) && isset($body -> data -> id)){
  151.                 $redirection = isset($_GET['super_socializer_redirect_to']) && heateor_ss_validate_url($_GET['super_socializer_redirect_to']) !== false ? esc_url($_GET['super_socializer_redirect_to']) : '';
  152.                 $profileData = the_champ_sanitize_profile_data($body -> data, 'instagram');
  153.                 if(strpos($redirection, 'heateorMSEnabled') !== false){
  154.                     $profileData['mc_subscribe'] = 1;
  155.                 }
  156.                 $response = the_champ_user_auth($profileData, 'instagram', $redirection);
  157.                 if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  158.                     $redirectTo = the_champ_get_login_redirection_url($redirection, true);
  159.                 }elseif(isset($response['message']) && $response['message'] == 'linked'){
  160.                     $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=1';
  161.                 }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  162.                     $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=0';
  163.                 }elseif(isset($response['url']) && $response['url'] != ''){
  164.                     $redirectTo = $response['url'];
  165.                 }else{
  166.                     $redirectTo = the_champ_get_login_redirection_url($redirection);
  167.                 }
  168.                 the_champ_close_login_popup($redirectTo);
  169.             }
  170.         }
  171.     }
  172.     // Steam auth
  173.     if(isset($_GET['SuperSocializerSteamAuth']) && trim($_GET['SuperSocializerSteamAuth']) != '' && isset($theChampLoginOptions['steam_api_key']) && $theChampLoginOptions['steam_api_key'] != ''){
  174.         global $theChampSteamLogin;
  175.         $theChampSteamId = $theChampSteamLogin->validate();
  176.         $result = wp_remote_get("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$theChampLoginOptions['steam_api_key']."&steamids=".$theChampSteamId."/?xml=1",  array('timeout' => 15));
  177.         if(!is_wp_error($result) && isset($result['response']['code']) && 200 === $result['response']['code']){
  178.             $data = json_decode(wp_remote_retrieve_body($result));
  179.             if($data && isset($data->response) && isset($data->response->players) && is_array($data->response->players)){
  180.                 $steamProfileData = $data->response->players;
  181.                 if(isset($steamProfileData[0]) && isset($steamProfileData[0]->steamid)){
  182.                     $steamRedirect = heateor_ss_validate_url($_GET['SuperSocializerSteamAuth']) !== false ? esc_url(trim($_GET['SuperSocializerSteamAuth'])) : '';
  183.                     $profileData = the_champ_sanitize_profile_data($steamProfileData[0], 'steam');
  184.                     if(strpos($steamRedirect, 'heateorMSEnabled') !== false){
  185.                         $profileData['mc_subscribe'] = 1;
  186.                     }
  187.                     $response = the_champ_user_auth($profileData, 'steam', $steamRedirect);
  188.                     if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  189.                         $redirectTo = the_champ_get_login_redirection_url($steamRedirect, true);
  190.                     }elseif(isset($response['message']) && $response['message'] == 'linked'){
  191.                         $redirectTo = $steamRedirect . (strpos($steamRedirect, '?') !== false ? '&' : '?') . 'linked=1';
  192.                     }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  193.                         $redirectTo = $steamRedirect . (strpos($steamRedirect, '?') !== false ? '&' : '?') . 'linked=0';
  194.                     }elseif(isset($response['url']) && $response['url'] != ''){
  195.                         $redirectTo = $response['url'];
  196.                     }else{
  197.                         $redirectTo = the_champ_get_login_redirection_url($steamRedirect);
  198.                     }
  199.                     the_champ_close_login_popup($redirectTo);
  200.                 }
  201.             }
  202.         }
  203.         die;
  204.     }
  205.    
  206.     // send request to Xing
  207.     if((isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Xing')){
  208.         if(function_exists('session_start')){
  209.             session_start();
  210.         }
  211.         if(!isset($_GET['oauth_token']) && isset($_SESSION['OAUTH_ACCESS_TOKEN'])){
  212.             Unset($_SESSION['OAUTH_ACCESS_TOKEN']);
  213.         }
  214.         if(isset($theChampLoginOptions['xing_ck']) && $theChampLoginOptions['xing_ck'] != '' && isset($theChampLoginOptions['xing_cs']) && $theChampLoginOptions['xing_cs'] != ''){
  215.             $xingClient = new oauth_client_class;
  216.             $xingClient->debug = 0;
  217.             $xingClient->debug_http = 1;
  218.             $xingClient->server = 'XING';
  219.             $xingClient->redirect_uri = home_url() . '/index.php?SuperSocializerAuth=Xing&super_socializer_redirect_to=' . str_replace(array('http://', 'https://'), '', esc_url(urldecode(trim($_GET['super_socializer_redirect_to'])))) . (isset($_GET['heateorMSEnabled']) ? '&heateorMSEnabled=1' : '');
  220.             $xingClient->client_id = $theChampLoginOptions['xing_ck'];
  221.             $xingClient->client_secret = $theChampLoginOptions['xing_cs'];
  222.             if(($success = $xingClient->Initialize())){
  223.                 if(($success = $xingClient->Process())){
  224.                     if(strlen($xingClient->access_token)){
  225.                         $success = $xingClient->CallAPI(
  226.                             'https://api.xing.com/v1/users/me',
  227.                             'GET', array(), array('FailOnAccessError'=>true), $xingResponse);
  228.                     }
  229.                 }
  230.                 $success = $xingClient->Finalize($success);
  231.             }
  232.             if($xingClient->exit) die('exit');
  233.             if($success){
  234.                 if(isset($xingResponse -> users) && is_array($xingResponse -> users) && isset($xingResponse -> users[0] -> id)){
  235.                     $xingRedirect = the_champ_get_http() . esc_attr($_GET['super_socializer_redirect_to']);
  236.                     $profileData = the_champ_sanitize_profile_data($xingResponse -> users[0], 'xing');
  237.                     if(isset($_GET['heateorMSEnabled'])){
  238.                         $profileData['mc_subscribe'] = 1;
  239.                     }
  240.                     $response = the_champ_user_auth($profileData, 'xing', $xingRedirect);
  241.                     if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  242.                         $redirectTo = the_champ_get_login_redirection_url($xingRedirect, true);
  243.                     }elseif(isset($response['message']) && $response['message'] == 'linked'){
  244.                         $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=1';
  245.                     }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  246.                         $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=0';
  247.                     }elseif(isset($response['url']) && $response['url'] != ''){
  248.                         $redirectTo = $response['url'];
  249.                     }else{
  250.                         $redirectTo = the_champ_get_login_redirection_url($xingRedirect);
  251.                     }
  252.                     the_champ_close_login_popup($redirectTo);
  253.                 }
  254.             }else{
  255.                 echo 'Error:' . $xingClient->error;
  256.                 die;
  257.             }
  258.         }
  259.     }
  260.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Linkedin'){
  261.         if(isset($theChampLoginOptions['li_key']) && $theChampLoginOptions['li_key'] != '' && isset($theChampLoginOptions['li_secret']) && $theChampLoginOptions['li_secret'] != ''){
  262.             $linkedinScope = 'r_basicprofile r_emailaddress';
  263.             $linkedinClient = new oauth_client_class;
  264.  
  265.             if(!isset($_GET['session_cleared']) && !isset($_GET['code']) && !isset($_GET['state'])){
  266.                 if(function_exists('session_start')){
  267.                     session_start();
  268.                     session_unset();
  269.                     session_destroy();
  270.                 }
  271.                 wp_redirect(home_url() . '?SuperSocializerAuth=Linkedin&super_socializer_redirect_to=' . esc_url(trim($_GET['super_socializer_redirect_to'])) . '&session_cleared=1');
  272.                 die;
  273.             }
  274.             $linkedinClient->debug = false;
  275.             $linkedinClient->debug_http = true;
  276.             $linkedinClient->server = 'LinkedIn2';
  277.             $linkedinClient->redirect_uri = home_url() . '?SuperSocializerAuth=Linkedin&super_socializer_redirect_to=' . esc_url(trim($_GET['super_socializer_redirect_to']));
  278.  
  279.             $linkedinClient->client_id = $theChampLoginOptions['li_key'];
  280.             $application_line = __LINE__;
  281.             $linkedinClient->client_secret = $theChampLoginOptions['li_secret'];
  282.  
  283.             // API permissions
  284.             $linkedinClient->scope = $linkedinScope;
  285.             if(($success = $linkedinClient->Initialize())) {
  286.                 if(($success = $linkedinClient->Process())) {
  287.                     if(strlen($linkedinClient->authorization_error)) {
  288.                         $linkedinClient->error = $linkedinClient->authorization_error;
  289.                         $success = false;
  290.                     }elseif(strlen($linkedinClient->access_token)) {
  291.                         $success = $linkedinClient->CallAPI(
  292.                             'https://api.linkedin.com/v1/people/~:(email-address,id,picture-urls::(original),first-name,last-name,headline,picture-url,public-profile-url,num-connections)',
  293.                             'GET', array(
  294.                             'format'=>'json'
  295.                         ), array('FailOnAccessError'=>true), $user);
  296.                     }
  297.                 }
  298.                 $success = $linkedinClient->Finalize($success);
  299.                 if(is_object($user) && isset($user->id)){
  300.                     $profileData = the_champ_sanitize_profile_data((array)$user, 'linkedin');
  301.                     if(isset($_GET['heateorMSEnabled'])){
  302.                         $profileData['mc_subscribe'] = 1;
  303.                     }
  304.                     $linkedinRedirectUrl = isset($_GET['super_socializer_redirect_to']) ? esc_url(trim($_GET['super_socializer_redirect_to'])) : home_url();
  305.                     $response = the_champ_user_auth($profileData, 'linkedin', $linkedinRedirectUrl);
  306.                     if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  307.                         $redirectTo = the_champ_get_login_redirection_url($linkedinRedirectUrl, true);
  308.                     }elseif(isset($response['message']) && $response['message'] == 'linked'){
  309.                         $redirectTo = $linkedinRedirectUrl . (strpos($linkedinRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  310.                     }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  311.                         $redirectTo = $linkedinRedirectUrl . (strpos($linkedinRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  312.                     }elseif(isset($response['url']) && $response['url'] != ''){
  313.                         $redirectTo = $response['url'];
  314.                     }else{
  315.                         $redirectTo = the_champ_get_login_redirection_url($linkedinRedirectUrl);
  316.                     }
  317.                     the_champ_close_login_popup($redirectTo);
  318.                 }
  319.             }
  320.             if($linkedinClient->exit) exit('exiting');
  321.         }
  322.     }
  323.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Twitch'){
  324.         if(function_exists('session_start')){
  325.             session_start();
  326.         }
  327.         require 'library/Twitch/twitch.php';
  328.         $twitchAuth = new TwitchTV($theChampLoginOptions['twitch_client_id'], $theChampLoginOptions['twitch_client_secret'], home_url() . '/?SuperSocializerAuth=Twitch', array('user_read'));
  329.         if(!isset($_GET['code'])){
  330.             $_SESSION['super_socializer_twitch_redirect'] = isset($_GET['super_socializer_redirect_to']) ? esc_url(trim($_GET['super_socializer_redirect_to'])) : home_url();
  331.             wp_redirect($twitchAuth->authenticate());
  332.             die;
  333.         }else{
  334.             $accessToken = $twitchAuth->get_access_token($_GET['code']);
  335.             $username = $twitchAuth->authenticated_user($accessToken);
  336.             if(isset($username)){
  337.                 $profileData = $twitchAuth->get_userid($username, true);
  338.                 if(is_array($profileData) && isset($profileData['_id'])){
  339.                     $profileData = the_champ_sanitize_profile_data($profileData, 'twitch');
  340.                     if(isset($_GET['heateorMSEnabled'])){
  341.                         $profileData['mc_subscribe'] = 1;
  342.                     }
  343.                     $twitchRedirectUrl = isset($_SESSION['super_socializer_twitch_redirect']) && $_SESSION['super_socializer_twitch_redirect'] ? $_SESSION['super_socializer_twitch_redirect'] : home_url();
  344.                     unset($_SESSION['super_socializer_twitch_redirect']);
  345.                     $response = the_champ_user_auth($profileData, 'twitch', $twitchRedirectUrl);
  346.                     if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  347.                         $redirectTo = the_champ_get_login_redirection_url($twitchRedirectUrl, true);
  348.                     }elseif(isset($response['message']) && $response['message'] == 'linked'){
  349.                         $redirectTo = $twitchRedirectUrl . (strpos($twitchRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  350.                     }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  351.                         $redirectTo = $twitchRedirectUrl . (strpos($twitchRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  352.                     }elseif(isset($response['url']) && $response['url'] != ''){
  353.                         $redirectTo = $response['url'];
  354.                     }else{
  355.                         $redirectTo = the_champ_get_login_redirection_url($twitchRedirectUrl);
  356.                     }
  357.                     the_champ_close_login_popup($redirectTo);
  358.                 }
  359.             }
  360.         }
  361.     }
  362.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Facebook'){
  363.         if(isset($theChampLoginOptions['fb_key']) && $theChampLoginOptions['fb_key'] != '' && isset($theChampLoginOptions['fb_secret']) && $theChampLoginOptions['fb_secret'] != ''){
  364.             if(function_exists('session_start')){
  365.                 session_start();
  366.                 if(!isset($_GET['code'])){
  367.                     // save referrer url in state
  368.                     $_SESSION['super_socializer_facebook_redirect'] = isset($_GET['super_socializer_redirect_to']) ? esc_url(trim($_GET['super_socializer_redirect_to'])) : home_url();
  369.                 }
  370.             }
  371.             require 'library/Facebook/autoload.php';
  372.             $facebook = new Facebook\Facebook(array(
  373.               'app_id' => $theChampLoginOptions['fb_key'],
  374.               'app_secret' => $theChampLoginOptions['fb_secret'],
  375.               'default_graph_version' => 'v2.10',
  376.             ));
  377.  
  378.             $helper = $facebook->getRedirectLoginHelper();
  379.  
  380.             $permissions = array('email'); // Optional permissions
  381.             if(!isset($_GET['code'])){
  382.                 $loginUrl = $helper->getLoginUrl(home_url() . '/?SuperSocializerAuth=Facebook', $permissions);
  383.                 wp_redirect($loginUrl);
  384.                 die;
  385.             }else{
  386.                 try{
  387.                    $accessToken = $helper->getAccessToken(home_url() . '/?SuperSocializerAuth=Facebook');
  388.                 }catch(Facebook\Exceptions\FacebookResponseException $e){
  389.                     _e('Problem fetching access token: ', 'super-socializer');
  390.                     echo $e->getMessage();
  391.                     die;
  392.                 }catch(Facebook\Exceptions\FacebookSDKException $e){
  393.                    _e('Facebook SDK returned an error: ', 'super-socializer');
  394.                    echo $e->getMessage();
  395.                    die;
  396.                 }
  397.  
  398.                 if(isset($accessToken)){
  399.                     $permissions = $facebook->get('/me/permissions', $accessToken);
  400.                     try{
  401.                         $response = $facebook->get('/me?fields=id,name,about,link,email,first_name,last_name', $accessToken);
  402.                     }catch(Facebook\Exceptions\FacebookResponseException $e){
  403.                         _e('Graph returned an error: ', 'super-socializer');
  404.                         echo $e->getMessage();
  405.                         die;
  406.                     }catch(Facebook\Exceptions\FacebookSDKException $e){
  407.                         _e('Facebook SDK returned an error: ', 'super-socializer');
  408.                         echo $e->getMessage();
  409.                         die;
  410.                     }
  411.                    
  412.                     $user = $response->getGraphUser();
  413.                     if(is_object($user) && isset($user['id'])){
  414.                         $profileData = the_champ_sanitize_profile_data($user, 'facebook');
  415.                         if(isset($_GET['heateorMSEnabled'])){
  416.                             $profileData['mc_subscribe'] = 1;
  417.                         }
  418.                         $facebookRedirectUrl = isset($_SESSION['super_socializer_facebook_redirect'])  && $_SESSION['super_socializer_facebook_redirect'] ? esc_url(trim($_SESSION['super_socializer_facebook_redirect'])) : home_url();
  419.                         unset($_SESSION['super_socializer_facebook_redirect']);
  420.                         $response = the_champ_user_auth($profileData, 'facebook', $facebookRedirectUrl);
  421.                         if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  422.                             $redirectTo = the_champ_get_login_redirection_url($facebookRedirectUrl, true);
  423.                         }elseif(isset($response['message']) && $response['message'] == 'linked'){
  424.                             $redirectTo = $facebookRedirectUrl . (strpos($facebookRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  425.                         }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  426.                             $redirectTo = $facebookRedirectUrl . (strpos($facebookRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  427.                         }elseif(isset($response['url']) && $response['url'] != ''){
  428.                             $redirectTo = $response['url'];
  429.                         }else{
  430.                             $redirectTo = the_champ_get_login_redirection_url($facebookRedirectUrl);
  431.                         }
  432.                         the_champ_close_login_popup($redirectTo);
  433.                     }
  434.                 }
  435.             }
  436.         }
  437.     }
  438.     if((isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Google') || (isset($_GET['code']) && isset($_GET['state']))){
  439.         if(isset($theChampLoginOptions['google_key']) && $theChampLoginOptions['google_key'] != '' && isset($theChampLoginOptions['google_secret']) && $theChampLoginOptions['google_secret'] != ''){
  440.             require_once 'library/Google/Config.php';
  441.             require_once 'library/Google/Service.php';
  442.             require_once 'library/Google/Task/Runner.php';
  443.             require_once 'library/Google/Http/REST.php';
  444.             require_once 'library/Google/Resource.php';
  445.             require_once 'library/Google/Model.php';
  446.             require_once 'library/Google/Oauth2.php';
  447.             require_once 'library/Google/Utils.php';
  448.             require_once 'library/Google/Http/Request.php';
  449.             require_once 'library/Google/Auth/Abstract.php';
  450.             require_once 'library/Google/Auth/OAuth2.php';
  451.             require_once 'library/Google/Http/CacheParser.php';
  452.             require_once 'library/Google/IO/Abstract.php';
  453.             require_once 'library/Google/Task/Retryable.php';
  454.             require_once 'library/Google/Exception.php';
  455.             require_once 'library/Google/IO/Exception.php';
  456.             require_once 'library/Google/IO/Curl.php';
  457.             require_once 'library/Google/Logger/Abstract.php';
  458.             require_once 'library/Google/Logger/Null.php';
  459.             require_once 'library/Google/Client.php';
  460.            
  461.             $googleClient = new Google_Client();
  462.             $googleClient->setClientId($theChampLoginOptions['google_key']);
  463.             $googleClient->setClientSecret($theChampLoginOptions['google_secret']);
  464.             $googleClient->setRedirectUri(home_url());
  465.             $googleClient->setScopes(array('https://www.googleapis.com/auth/userinfo.email'));
  466.             //Send Client Request
  467.             $objOAuthService = new Google_Service_Oauth2($googleClient);
  468.             $gpAuthUrl = $googleClient->createAuthUrl() . '&state=' . (isset($_GET['super_socializer_redirect_to']) ? esc_url(trim($_GET['super_socializer_redirect_to'])) : '');
  469.             if(!isset($_GET['code']) && !isset($_GET['state'])){
  470.                 wp_redirect($gpAuthUrl);
  471.                 die;
  472.             }    
  473.         }
  474.     }
  475.     if(isset($_GET['code']) && isset($_GET['state'])){
  476.         //Authenticate code from Google OAuth Flow
  477.         $googleClient->authenticate($_GET['code']);
  478.         $accessTokenStr = $googleClient->getAccessToken();
  479.         if($accessTokenStr){
  480.             $userData = $objOAuthService->userinfo->get();
  481.             if(is_object($userData) && isset($userData -> id)){
  482.                 $profileData = the_champ_sanitize_profile_data($userData, 'google');
  483.                 if(isset($_GET['heateorMSEnabled'])){
  484.                     $profileData['mc_subscribe'] = 1;
  485.                 }
  486.                 $googleRedirectUrl = isset($_GET['state']) ? esc_url(trim($_GET['state'])) : home_url();
  487.                 $response = the_champ_user_auth($profileData, 'google', $googleRedirectUrl);
  488.                 if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  489.                     $redirectTo = the_champ_get_login_redirection_url($googleRedirectUrl, true);
  490.                 }elseif(isset($response['message']) && $response['message'] == 'linked'){
  491.                     $redirectTo = $googleRedirectUrl . (strpos($googleRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  492.                 }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  493.                     $redirectTo = $googleRedirectUrl . (strpos($googleRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  494.                 }elseif(isset($response['url']) && $response['url'] != ''){
  495.                     $redirectTo = $response['url'];
  496.                 }else{
  497.                     $redirectTo = the_champ_get_login_redirection_url($googleRedirectUrl);
  498.                 }
  499.                 the_champ_close_login_popup($redirectTo);
  500.             }
  501.         }
  502.     }
  503.     // Vkontakte
  504.     if((isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Vkontakte') || (isset($_GET['code']) && !isset($_GET['SuperSocializerAuth']))){
  505.         if(function_exists('session_start')){
  506.             session_start();
  507.         }
  508.         require 'library/Vkontakte/Vkontakte.php';
  509.         $heateorSsVkontakte = new Vkontakte(array(
  510.             'client_id' => $theChampLoginOptions['vk_key'],
  511.             'client_secret' => $theChampLoginOptions['vk_secure_key'],
  512.             'redirect_uri' => home_url()
  513.         ));
  514.         $heateorSsVkontakte->setScope(array('email'));
  515.     }
  516.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Vkontakte'){
  517.         if(isset($theChampLoginOptions['providers']) && in_array('vkontakte', $theChampLoginOptions['providers']) && isset($theChampLoginOptions['vk_key']) && $theChampLoginOptions['vk_key'] != '' && isset($theChampLoginOptions['vk_secure_key']) && $theChampLoginOptions['vk_secure_key'] != ''){
  518.             $_SESSION['super_socializer_vkontakte_redirect'] = isset($_GET['super_socializer_redirect_to']) ? esc_url(trim($_GET['super_socializer_redirect_to'])) : home_url();
  519.             wp_redirect($heateorSsVkontakte->getLoginUrl());
  520.             die;
  521.         }
  522.     }
  523.     if(isset($_GET['code']) && !isset($_GET['SuperSocializerAuth'])){
  524.         if(isset($heateorSsVkontakte)){
  525.             $heateorSsVkontakte->authenticate($_GET['code']);
  526.             $userId = $heateorSsVkontakte->getUserId();
  527.             $email = $heateorSsVkontakte->getUserEmail();
  528.             if($userId){
  529.                 $users = $heateorSsVkontakte->api('users.get', array(
  530.                     'user_id' => $userId,
  531.                     'fields' => array('first_name','last_name','nickname','screen_name','photo_rec','photo_big')
  532.                 ));
  533.                 if(isset($users[0]) && isset($users[0]["id"]) && $users[0]["id"]){
  534.                     $profileData = the_champ_sanitize_profile_data($users[0], 'vkontakte');
  535.                     $profileData['email'] = '';
  536.                     if($email){
  537.                         $profileData['email'] = sanitize_email($email);
  538.                     }
  539.                     if(isset($_GET['heateorMSEnabled'])){
  540.                         $profileData['mc_subscribe'] = 1;
  541.                     }
  542.                     $vkontakteRedirectUrl = isset($_SESSION['super_socializer_vkontakte_redirect'])  && $_SESSION['super_socializer_vkontakte_redirect'] ? esc_url(trim($_SESSION['super_socializer_vkontakte_redirect'])) : home_url();
  543.                     $response = the_champ_user_auth($profileData, 'vkontakte', $vkontakteRedirectUrl);
  544.                     if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  545.                         $redirectTo = the_champ_get_login_redirection_url($vkontakteRedirectUrl, true);
  546.                     }elseif(isset($response['message']) && $response['message'] == 'linked'){
  547.                         $redirectTo = $vkontakteRedirectUrl . (strpos($vkontakteRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  548.                     }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  549.                         $redirectTo = $vkontakteRedirectUrl . (strpos($vkontakteRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  550.                     }elseif(isset($response['url']) && $response['url'] != ''){
  551.                         $redirectTo = $response['url'];
  552.                     }else{
  553.                         $redirectTo = the_champ_get_login_redirection_url($vkontakteRedirectUrl);
  554.                     }
  555.                     the_champ_close_login_popup($redirectTo);
  556.                 }
  557.             }
  558.         }
  559.     }
  560.     // send request to twitter
  561.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Twitter' && !isset($_REQUEST['oauth_token'])){
  562.         if(isset($theChampLoginOptions['twitter_key']) && $theChampLoginOptions['twitter_key'] != '' && isset($theChampLoginOptions['twitter_secret']) && $theChampLoginOptions['twitter_secret'] != ''){
  563.             if(!function_exists('curl_init')){
  564.                 ?>
  565.                 <div style="width: 500px; margin: 0 auto">
  566.                 <?php _e('cURL is not enabled at your website server. Please contact your website server administrator to enable it.', 'super-socializer') ?>
  567.                 </div>
  568.                 <?php
  569.                 die;
  570.             }
  571.             /* Build TwitterOAuth object with client credentials. */
  572.             $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret']);
  573.             /* Get temporary credentials. */
  574.             $requestToken = $connection->getRequestToken(esc_url(home_url()).'/index.php?SuperSocializerAuth=Twitter');
  575.             if($connection->http_code == 200){
  576.                 // generate unique ID
  577.                 $uniqueId = mt_rand();
  578.                 // save oauth token and secret in db temporarily
  579.                 update_user_meta($uniqueId, 'thechamp_twitter_oauthtoken', $requestToken['oauth_token']);
  580.                 update_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', $requestToken['oauth_token_secret']);
  581.                 if(isset($_GET['heateorMSEnabled'])){
  582.                     update_user_meta($uniqueId, 'thechamp_mc_subscribe', '1');
  583.                 }
  584.                 if(isset($_GET['super_socializer_redirect_to']) && heateor_ss_validate_url($_GET['super_socializer_redirect_to']) !== false){
  585.                     update_user_meta($uniqueId, 'thechamp_twitter_redirect', esc_url(trim($_GET['super_socializer_redirect_to'])));
  586.                 }
  587.                 wp_redirect($connection->getAuthorizeURL($requestToken['oauth_token']));
  588.                 die;
  589.             }else{
  590.                 ?>
  591.                 <div style="width: 500px; margin: 0 auto">
  592.                     <ol>
  593.                     <li><?php echo sprintf(__('Enter exactly the following url in <strong>Website</strong> and <strong>Callback Url</strong> options in your Twitter app (see step 3 %s)', 'super-socializer'), '<a target="_blank" href="http://support.heateor.com/how-to-get-twitter-api-key-and-secret/">here</a>') ?><br/>
  594.                     <?php echo esc_url(home_url()) ?>
  595.                     </li>
  596.                     <li><?php _e('Make sure cURL is enabled at your website server. You may need to contact the server administrator of your website to verify this', 'super-socializer') ?></li>
  597.                     <li><?php echo sprintf(__('Make sure that "Enable Callback Locking" option is disabled. See step 4 %s', 'super-socializer'), '<a target="_blank" href="http://support.heateor.com/how-to-get-twitter-api-key-and-secret">here</a>') ?></li>
  598.                     </ol>
  599.                 </div>
  600.                 <?php
  601.                 die;
  602.             }
  603.         }
  604.     }
  605.     // twitter authentication
  606.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'Twitter' && isset($_REQUEST['oauth_token'])){
  607.         global $wpdb;
  608.         $uniqueId = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'thechamp_twitter_oauthtoken' and meta_value = %s", sanitize_text_field($_REQUEST['oauth_token'])));
  609.         $oauthTokenSecret = get_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', true);
  610.         // twitter redirect url
  611.         $twitterRedirectUrl = get_user_meta($uniqueId, 'thechamp_twitter_redirect', true);
  612.         if(empty($uniqueId) || $oauthTokenSecret == ''){
  613.             // invalid request
  614.             wp_redirect(esc_url(home_url()));
  615.             die;
  616.         }
  617.         $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $_REQUEST['oauth_token'], $oauthTokenSecret);
  618.         /* Request access tokens from twitter */
  619.         $accessToken = $connection->getAccessToken($_REQUEST['oauth_verifier']);
  620.         /* Create a TwitterOauth object with consumer/user tokens. */
  621.         $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $accessToken['oauth_token'], $accessToken['oauth_token_secret']);
  622.         $content = $connection->get('account/verify_credentials', array('include_email' => 'true'));
  623.         // delete temporary data
  624.         delete_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret');
  625.         delete_user_meta($uniqueId, 'thechamp_twitter_oauthtoken');
  626.         delete_user_meta($uniqueId, 'thechamp_twitter_redirect');
  627.         if(is_object($content) && isset($content -> id)){
  628.             $profileData = the_champ_sanitize_profile_data($content, 'twitter');
  629.             if(get_user_meta($uniqueId, 'thechamp_mc_subscribe', true) != ''){
  630.                 $profileData['mc_subscribe'] = 1;
  631.             }
  632.             delete_user_meta($uniqueId, 'thechamp_mc_subscribe');
  633.             $response = the_champ_user_auth($profileData, 'twitter', $twitterRedirectUrl);
  634.             if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  635.                 $redirectTo = the_champ_get_login_redirection_url($twitterRedirectUrl, true);
  636.             }elseif(isset($response['message']) && $response['message'] == 'linked'){
  637.                 $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
  638.             }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  639.                 $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
  640.             }elseif(isset($response['url']) && $response['url'] != ''){
  641.                 $redirectTo = $response['url'];
  642.             }else{
  643.                 $redirectTo = the_champ_get_login_redirection_url($twitterRedirectUrl);
  644.             }
  645.             the_champ_close_login_popup($redirectTo);
  646.         }
  647.     }
  648.  
  649.     // LiveJournal auth
  650.     if(isset($_GET['SuperSocializerAuth']) && sanitize_text_field($_GET['SuperSocializerAuth']) == 'LiveJournal'){
  651.         the_champ_livejournal_auth();
  652.     }
  653. }
  654.  
  655. /**
  656.  * LiveJournal auth
  657.  */
  658. function the_champ_livejournal_auth(){
  659.     require('library/LiveJournalLogin/class.openid.v3.php');
  660.     $currentPageUrl = the_champ_get_valid_url(html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])));
  661.     if(isset($_POST['openid_action']) && $_POST['openid_action'] == "SuperSocializerLogin"){ // Get identity from user and redirect browser to OpenID Server
  662.         $theChampOpenId = new SimpleOpenID;
  663.         $theChampOpenId->SetIdentity(sanitize_text_field($_POST['openid_url']).'.livejournal.com');
  664.         $theChampOpenId->SetTrustRoot($currentPageUrl);
  665.         $theChampOpenId->SetRequiredFields(array('email','fullname'));
  666.         $theChampOpenId->SetOptionalFields(array('dob','gender','postcode','country','language','timezone'));
  667.         if($theChampOpenId->GetOpenIDServer()){
  668.             $theChampOpenId->SetApprovedURL($currentPageUrl);   // Send Response from OpenID server to this script
  669.             $theChampOpenId->Redirect();    // This will redirect user to OpenID Server
  670.         }else{
  671.             $error = $theChampOpenId->GetError();
  672.             echo "ERROR CODE: " . $error['code'] . "<br>";
  673.             echo "ERROR DESCRIPTION: " . $error['description'] . "<br>";
  674.         }
  675.         exit;
  676.     }elseif(isset($_GET['openid_mode']) && $_GET['openid_mode'] == 'id_res'){   // Perform HTTP Request to OpenID server to validate key
  677.         $theChampOpenId = new SimpleOpenID;
  678.         $theChampOpenId->SetIdentity($_GET['openid_identity']);
  679.         $theChampOpenIdValidationResult = $theChampOpenId->ValidateWithServer();
  680.         if($theChampOpenIdValidationResult == true){        // OK HERE KEY IS VALID
  681.             $userpicUrl = '';
  682.             if(isset($_GET['openid_claimed_id']) && $_GET['openid_claimed_id'] != ''){
  683.                 $usernameParts = explode('.', str_replace('http://', '', sanitize_text_field($_GET['openid_claimed_id'])));
  684.                 $response = wp_remote_get( 'http://www.livejournal.com/allpics.bml?user=' . $usernameParts[0],  array( 'timeout' => 15 ) );
  685.                 if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ){
  686.                     $body = wp_remote_retrieve_body( $response );
  687.                     if($body){
  688.                         $userpicsHtmlParts = explode('https://l-userpic.livejournal.com', $body);
  689.                         $userpicsId = explode("'", $userpicsHtmlParts[1]);
  690.                         $userpicUrl = 'https://l-userpic.livejournal.com' . $userpicsId[0];
  691.                     }
  692.                 }
  693.                 $profileData = array();
  694.                 $profileData['username'] = $usernameParts[0];
  695.                 $profileData['link'] = trim($_GET['openid_claimed_id']);
  696.                 $profileData['avatar'] = $userpicUrl;
  697.                 $profileData['name'] = $usernameParts[0];
  698.                 $profileData['first_name'] = $usernameParts[0];
  699.                 $profileData['last_name'] = $usernameParts[0];
  700.                 $redirection = isset($_GET['super_socializer_redirect_to']) && heateor_ss_validate_url($_GET['super_socializer_redirect_to']) !== false ? esc_url($_GET['super_socializer_redirect_to']) : '';
  701.                 $profileData = the_champ_sanitize_profile_data($profileData, 'liveJournal');
  702.                 if(isset($_GET['heateorMSEnabled'])){
  703.                     $profileData['mc_subscribe'] = 1;
  704.                 }
  705.                 $response = the_champ_user_auth($profileData, 'liveJournal', $redirection);
  706.                 if(is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')){
  707.                     $redirectTo = the_champ_get_login_redirection_url($redirection, true);
  708.                 }elseif(isset($response['message']) && $response['message'] == 'linked'){
  709.                     $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=1';
  710.                 }elseif(isset($response['message']) && $response['message'] == 'not linked'){
  711.                     $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=0';
  712.                 }elseif(isset($response['url']) && $response['url'] != ''){
  713.                     $redirectTo = $response['url'];
  714.                 }else{
  715.                     $redirectTo = the_champ_get_login_redirection_url($redirection);
  716.                 }
  717.                 the_champ_close_login_popup($redirectTo);
  718.             }
  719.         }elseif($theChampOpenId->IsError() == true){            // Oops, WE GOT SOME ERROR
  720.             $error = $theChampOpenId->GetError();
  721.             echo "ERROR CODE: " . $error['code'] . "<br>";
  722.             echo "ERROR DESCRIPTION: " . $error['description'] . "<br>";
  723.         }else{                                          // Signature Verification Failed
  724.             echo "INVALID AUTHORIZATION";
  725.         }
  726.     }elseif(isset($_GET['openid_mode']) && $_GET['openid_mode'] == 'cancel'){ // User Canceled the Request
  727.         the_champ_close_login_popup($currentPageUrl);
  728.     }else{
  729.         wp_redirect(remove_query_arg(array('SuperSocializerAuth', 'action'), html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]))), 301);
  730.         exit;
  731.     }
  732.     die;
  733. }
  734.  
  735. /**
  736.  * Close Social Login popup
  737.  */
  738. function the_champ_close_login_popup($redirectionUrl){
  739.     ?>
  740.     <script>
  741.     if(window.opener){
  742.         window.opener.location.href="<?php echo trim($redirectionUrl); ?>";
  743.         window.close();
  744.     }else{
  745.         window.location.href="<?php echo trim($redirectionUrl); ?>";
  746.     }
  747.     </script>
  748.     <?php
  749.     die;
  750. }
  751.  
  752. /**
  753.  * Validate url
  754.  */
  755. function the_champ_validate_url($url){
  756.     $expression = "/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|)?[a-z0-9_\-]+[a-z0-9_\-\.]+\.[a-z]{2,4}(\/+[a-z0-9_\.\-\/]*)?$/i";
  757.     return (bool)preg_match($expression, $url);
  758. }
  759.  
  760. /**
  761.  * Get http/https protocol at the website
  762.  */
  763. function the_champ_get_http(){
  764.     if(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'){
  765.         return "https://";
  766.     }else{
  767.         return "http://";
  768.     }
  769. }
  770.  
  771. /**
  772.  * Return valid redirection url
  773.  */
  774. function the_champ_get_valid_url($url){
  775.     $decodedUrl = urldecode($url);
  776.     if(html_entity_decode(esc_url(remove_query_arg(array('ss_message', 'SuperSocializerVerified', 'SuperSocializerUnverified'), $decodedUrl))) == wp_login_url() || $decodedUrl == home_url().'/wp-login.php?action=register' || $decodedUrl == home_url().'/wp-login.php?loggedout=true'){
  777.         $url = esc_url(home_url()).'/';
  778.     }elseif(isset($_GET['redirect_to'])){
  779.         if(urldecode($_GET['redirect_to']) == admin_url()){
  780.             $url = esc_url(home_url()).'/';
  781.         }elseif(the_champ_validate_url(urldecode($_GET['redirect_to'])) && (strpos(urldecode($_GET['redirect_to']), 'http://') !== false || strpos(urldecode($_GET['redirect_to']), 'https://') !== false)){
  782.             $url = $_GET['redirect_to'];
  783.         }else{
  784.             $url = esc_url(home_url()).'/';
  785.         }
  786.     }
  787.     return $url;
  788. }
  789.  
  790. /**
  791.  * Return webpage url to redirect after login
  792.  */
  793. function the_champ_get_login_redirection_url($twitterRedirect = '', $register = false){
  794.     global $theChampLoginOptions, $user_ID;
  795.     if($register){
  796.         $option = 'register';
  797.     }else{
  798.         $option = 'login';
  799.     }
  800.     $redirectionUrl = esc_url(home_url());
  801.     if(isset($theChampLoginOptions[$option.'_redirection'])){
  802.         if($theChampLoginOptions[$option.'_redirection'] == 'same'){
  803.             $http = the_champ_get_http();
  804.             if($twitterRedirect != ''){
  805.                 $url = $twitterRedirect;
  806.             }else{
  807.                 $url = html_entity_decode(esc_url($http.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
  808.             }
  809.             $redirectionUrl = the_champ_get_valid_url($url);
  810.         }elseif($theChampLoginOptions[$option.'_redirection'] == 'homepage'){
  811.             $redirectionUrl = esc_url(home_url());
  812.         }elseif($theChampLoginOptions[$option.'_redirection'] == 'account'){
  813.             $redirectionUrl = admin_url();
  814.         }elseif($theChampLoginOptions[$option.'_redirection'] == 'custom' && $theChampLoginOptions[$option.'_redirection_url'] != ''){
  815.             $redirectionUrl = esc_url($theChampLoginOptions[$option.'_redirection_url']);
  816.         }elseif($theChampLoginOptions[$option.'_redirection'] == 'bp_profile' && $user_ID != 0){
  817.             $redirectionUrl = function_exists('bp_core_get_user_domain') ? bp_core_get_user_domain($user_ID) : admin_url();
  818.         }
  819.     }
  820.     $redirectionUrl = apply_filters('heateor_ss_login_redirection_url_filter', $redirectionUrl, $theChampLoginOptions, $user_ID, $twitterRedirect, $register);
  821.  
  822.     return $redirectionUrl;
  823. }
  824.  
  825. /**
  826.  * The javascript to load at front end
  827.  */
  828. function the_champ_frontend_scripts(){
  829.     global $theChampFacebookOptions, $theChampLoginOptions, $theChampSharingOptions, $theChampGeneralOptions;
  830.     $inFooter = isset($theChampGeneralOptions['footer_script']) ? true : false;
  831.     $combinedScript = isset($theChampGeneralOptions['combined_script']) ? true : false;
  832.     ?>
  833.     <script type="text/javascript">var theChampCloseIconPath = '<?php echo plugins_url('images/close.png', __FILE__) ?>';<?php if(isset($theChampGeneralOptions["browser_msg_enable"]) && $theChampGeneralOptions["browser_msg"] != ""){ ?>var heateorSsSDKBlockedMsg = `<?php echo str_replace("{support_url}", "<a href=\'http://support.heateor.com/browser-blocking-social-features/\' target=\'_blank\' style=\'color:#33a9d8\'>http://support.heateor.com/browser-blocking-social-features/</a>", htmlspecialchars($theChampGeneralOptions["browser_msg"], ENT_QUOTES)); ?>`<?php } ?></script>
  834.     <?php
  835.     if(!$combinedScript){
  836.         wp_enqueue_script('the_champ_ss_general_scripts', plugins_url('js/front/social_login/general.js', __FILE__), false, THE_CHAMP_SS_VERSION, $inFooter);
  837.     }
  838.     $websiteUrl = esc_url(home_url());
  839.     $fbKey = isset($theChampLoginOptions["fb_key"]) && $theChampLoginOptions["fb_key"] != "" ? $theChampLoginOptions["fb_key"] : "";
  840.     $userVerified = false;
  841.     $emailPopup = false;
  842.     ?>
  843.     <script> var theChampSiteUrl = '<?php echo $websiteUrl ?>', theChampVerified = <?php echo intval($userVerified) ?>, theChampEmailPopup = <?php echo intval($emailPopup); ?>; </script>
  844.     <?php
  845.     // scripts used for common Social Login functionality
  846.     if(the_champ_social_login_enabled() && !is_user_logged_in()){
  847.         $loadingImagePath = plugins_url('images/ajax_loader.gif', __FILE__);
  848.         $theChampAjaxUrl = get_admin_url().'admin-ajax.php';
  849.         $redirectionUrl = the_champ_get_login_redirection_url();
  850.         $regRedirectionUrl = the_champ_get_login_redirection_url('', true);
  851.         ?>
  852.         <script> var theChampLoadingImgPath = '<?php echo $loadingImagePath ?>'; var theChampAjaxUrl = '<?php echo $theChampAjaxUrl ?>'; var theChampRedirectionUrl = '<?php echo $redirectionUrl ?>'; var theChampRegRedirectionUrl = '<?php echo $regRedirectionUrl ?>'; </script>
  853.         <?php
  854.         $ajaxUrl = 'admin-ajax.php';
  855.         $notification = '';
  856.         if(isset($_GET['SuperSocializerVerified']) || isset($_GET['SuperSocializerUnverified'])){
  857.             $userVerified = true;
  858.             $ajaxUrl = esc_url(add_query_arg(
  859.                 array(
  860.                     'height' => 60,
  861.                     'width' => 300,
  862.                     'action' => 'the_champ_notify',
  863.                     'message' => urlencode(isset($_GET['SuperSocializerUnverified']) ? __('Please verify your email address to login.', 'super-socializer') : __('Your email has been verified. Now you can login to your account', 'super-socializer'))
  864.                 ),
  865.                 'admin-ajax.php'
  866.             ));
  867.             $notification = __('Notification', 'super-socializer');
  868.         }
  869.        
  870.         $emailAjaxUrl = 'admin-ajax.php';
  871.         $emailPopupTitle = '';
  872.         $emailPopupErrorMessage = '';
  873.         $emailPopupUniqueId = '';
  874.         $emailPopupVerifyMessage = '';
  875.         if(isset($_GET['SuperSocializerEmail']) && isset($_GET['par']) && trim($_GET['par']) != ''){
  876.             $emailPopup = true;
  877.             $emailAjaxUrl = esc_url(add_query_arg(
  878.                 array(
  879.                     'height' => isset($theChampLoginOptions['popup_height']) && $theChampLoginOptions['popup_height'] != '' ? esc_attr( $theChampLoginOptions['popup_height'] ) : 210,
  880.                     'width' => 300,
  881.                     'action' => 'the_champ_ask_email'
  882.                 ),
  883.                 'admin-ajax.php'
  884.             ));
  885.             $emailPopupTitle = __('Email required', 'super-socializer');
  886.             $emailPopupErrorMessage = isset($theChampLoginOptions["email_error_message"]) ? $theChampLoginOptions["email_error_message"] : "";
  887.             $emailPopupUniqueId = isset($_GET['par']) ? sanitize_text_field($_GET['par']) : '';
  888.             $emailPopupVerifyMessage = __('Please check your email inbox to complete the registration.', 'super-socializer');
  889.         }
  890.         global $theChampSteamLogin;
  891.         $twitterRedirect = urlencode(the_champ_get_valid_url(html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]))));
  892.         $currentPageUrl = urldecode($twitterRedirect);
  893.         $theChampLJAuthUrl = remove_query_arg('action', the_champ_get_valid_url($currentPageUrl));
  894.         ?>
  895.         <script> var theChampFBKey = '<?php echo $fbKey ?>', theChampVerified = <?php echo intval($userVerified) ?>; var theChampAjaxUrl = '<?php echo html_entity_decode(admin_url().$ajaxUrl) ?>'; var theChampPopupTitle = '<?php echo $notification; ?>'; var theChampEmailPopup = <?php echo intval($emailPopup); ?>; var theChampEmailAjaxUrl = '<?php echo html_entity_decode(admin_url().$emailAjaxUrl); ?>'; var theChampEmailPopupTitle = '<?php echo $emailPopupTitle; ?>'; var theChampEmailPopupErrorMsg = '<?php echo htmlspecialchars($emailPopupErrorMessage, ENT_QUOTES); ?>'; var theChampEmailPopupUniqueId = '<?php echo $emailPopupUniqueId; ?>'; var theChampEmailPopupVerifyMessage = '<?php echo $emailPopupVerifyMessage; ?>'; var theChampLJLoginUsernameString = '<?php echo htmlspecialchars(__('Enter your LiveJournal username', 'super-socializer'), ENT_QUOTES); ?>'; var theChampLJAuthUrl = '<?php echo $theChampLJAuthUrl . (strpos($theChampLJAuthUrl, '?') !== false ? '&' : '?') . "SuperSocializerAuth=LiveJournal"; ?>'; var theChampSteamAuthUrl = "<?php echo $theChampSteamLogin ? $theChampSteamLogin->url( esc_url(home_url()) . '?SuperSocializerSteamAuth=' . $twitterRedirect ) : ''; ?>"; var theChampTwitterRedirect = '<?php echo $twitterRedirect ?>'; <?php echo isset($theChampLoginOptions['disable_reg']) && isset($theChampLoginOptions['disable_reg_redirect']) && $theChampLoginOptions['disable_reg_redirect'] != '' ? 'var theChampDisableRegRedirect = "' . html_entity_decode(esc_url($theChampLoginOptions['disable_reg_redirect'])) . '";' : ''; ?> var heateorMSEnabled = 0; var theChampTwitterAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Twitter&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampFacebookAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Facebook&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampTwitchAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Twitch&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampGoogleAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Google&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampVkontakteAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Vkontakte&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampLinkedinAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Linkedin&super_socializer_redirect_to=" + theChampTwitterRedirect; var theChampXingAuthUrl = theChampSiteUrl + "?SuperSocializerAuth=Xing&super_socializer_redirect_to=" + theChampTwitterRedirect;</script>
  896.         <?php
  897.         if(!$combinedScript){
  898.             wp_enqueue_script('the_champ_sl_common', plugins_url('js/front/social_login/common.js', __FILE__), array('jquery'), THE_CHAMP_SS_VERSION, $inFooter);
  899.         }
  900.         wp_enqueue_script('thickbox');
  901.         wp_enqueue_style('thickbox');
  902.     }
  903.     // Instagram scripts
  904.     if(the_champ_social_login_provider_enabled('instagram')){
  905.         ?>
  906.         <script> var theChampInstaId = '<?php echo (isset($theChampLoginOptions["insta_id"]) && $theChampLoginOptions["insta_id"] != "") ? $theChampLoginOptions["insta_id"] : 0 ?>'; var theChampTwitterRedirect = '<?php echo urlencode(the_champ_get_valid_url(html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])))); ?>';</script>
  907.         <?php
  908.         if(!$combinedScript){
  909.             wp_enqueue_script('the_champ_sl_instagram', plugins_url('js/front/social_login/instagram.js', __FILE__), false, THE_CHAMP_SS_VERSION, $inFooter);
  910.         }
  911.     }
  912.     // Facebook scripts
  913.     if(the_champ_facebook_plugin_enabled()){
  914.         ?>
  915.         <script> var theChampFBKey = '<?php echo $fbKey ?>', theChampFBLang = '<?php echo (isset($theChampFacebookOptions["comment_lang"]) && $theChampFacebookOptions["comment_lang"] != '') ? $theChampFacebookOptions["comment_lang"] : "en_US" ?>', theChampFbLikeMycred = <?php echo defined( 'HEATEOR_SOCIAL_SHARE_MYCRED_INTEGRATION_VERSION' ) && the_champ_facebook_like_rec_enabled() ? 1 : 0 ?>, theChampSsga = <?php echo defined( 'HEATEOR_SHARING_GOOGLE_ANALYTICS_VERSION' ) ? 1 : 0 ?>, theChampCommentNotification = <?php echo (defined('HEATEOR_FB_COM_NOT_VERSION') && version_compare('1.1.4', HEATEOR_FB_COM_NOT_VERSION) > 0) || function_exists('heateor_ss_check_querystring') || function_exists('the_champ_check_querystring') ? 1 : 0; ?>, theChampHeateorFcmRecentComments = <?php echo defined('HEATEOR_FB_COM_MOD_VERSION') && HEATEOR_FB_COM_MOD_VERSION == '1.1.4' ? 1 : 0 ?>, theChampFbIosLogin = <?php echo !is_user_logged_in() && isset($_GET['code']) && esc_attr(trim($_GET['code'])) != '' ? 1 : 0; ?>; </script>
  916.         <?php
  917.         add_action('wp_footer', 'the_champ_fb_root_div');
  918.         if(!$combinedScript){
  919.             wp_enqueue_script('the_champ_fb_sdk', plugins_url('js/front/facebook/sdk.js', __FILE__), false, THE_CHAMP_SS_VERSION, $inFooter);
  920.         }
  921.     }
  922.    
  923.     // Social commenting
  924.     if(the_champ_social_commenting_enabled()){
  925.         global $post;
  926.         if($post){
  927.             $postMeta = get_post_meta($post -> ID, '_the_champ_meta', true);
  928.             if(isset($theChampFacebookOptions['enable_' . $post->post_type]) && !(isset($postMeta) && isset($postMeta['fb_comments']) && $postMeta['fb_comments'] == 1)){
  929.                 if(isset($theChampFacebookOptions['urlToComment']) && $theChampFacebookOptions['urlToComment'] != ''){
  930.                     $commentUrl = $theChampFacebookOptions['urlToComment'];
  931.                 }elseif(isset($post -> ID) && $post -> ID){
  932.                     $commentUrl = get_permalink($post -> ID);
  933.                 }else{
  934.                     $commentUrl = html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
  935.                 }
  936.  
  937.                 $commentingTabsOrder = ($theChampFacebookOptions['commenting_order'] != '' ? $theChampFacebookOptions['commenting_order'] : 'wordpress,facebook,googleplus,disqus');
  938.                 $commentingTabsOrder = explode(',', str_replace('facebook', 'fb', $commentingTabsOrder));
  939.                 $enabledTabs = array();
  940.                 foreach($commentingTabsOrder as $tab){
  941.                     $tab = trim($tab);
  942.                     if($tab == 'wordpress'){
  943.                         $enabledTabs[] = 'wordpress';
  944.                     }elseif(isset($theChampFacebookOptions['enable_'. $tab .'comments'])){
  945.                         $enabledTabs[] = $tab;
  946.                     }
  947.                 }
  948.                 $labels = array();
  949.                 $labels['wordpress'] = $theChampFacebookOptions['label_wordpress_comments'] != '' ? htmlspecialchars($theChampFacebookOptions['label_wordpress_comments'], ENT_QUOTES) : 'Default Comments';
  950.                 $commentsCount = wp_count_comments($post->ID);
  951.                 $labels['wordpress'] .= ' ('. ($commentsCount && isset($commentsCount -> approved) ? $commentsCount -> approved : '') .')';
  952.                 $labels['fb'] = $theChampFacebookOptions['label_facebook_comments'] != '' ? htmlspecialchars($theChampFacebookOptions['label_facebook_comments'], ENT_QUOTES) : 'Facebook Comments';
  953.                 $labels['fb'] .= ' (<fb:comments-count href='. $commentUrl .'></fb:comments-count>)';
  954.                 $labels['googleplus'] = $theChampFacebookOptions['label_googleplus_comments'] != '' ? htmlspecialchars($theChampFacebookOptions['label_googleplus_comments'], ENT_QUOTES) : 'GooglePlus Comments';
  955.                 $labels['disqus'] = $theChampFacebookOptions['label_disqus_comments'] != '' ? htmlspecialchars($theChampFacebookOptions['label_disqus_comments'], ENT_QUOTES) : 'Disqus Comments';
  956.                 ?>
  957.                 <script>var theChampFBCommentUrl = '<?php echo $commentUrl ?>'; var theChampFBCommentColor = '<?php echo (isset($theChampFacebookOptions['comment_color']) && $theChampFacebookOptions['comment_color'] != '') ? $theChampFacebookOptions["comment_color"] : ''; ?>'; var theChampFBCommentNumPosts = '<?php echo (isset($theChampFacebookOptions['comment_numposts']) && $theChampFacebookOptions['comment_numposts'] != '') ? $theChampFacebookOptions["comment_numposts"] : ''; ?>'; var theChampFBCommentWidth = '<?php echo (isset($theChampFacebookOptions['comment_width']) && $theChampFacebookOptions['comment_width'] != '') ? $theChampFacebookOptions["comment_width"] : '100%'; ?>'; var theChampFBCommentOrderby = '<?php echo (isset($theChampFacebookOptions['comment_orderby']) && $theChampFacebookOptions['comment_orderby'] != '') ? $theChampFacebookOptions["comment_orderby"] : ''; ?>'; var theChampCommentingTabs = "<?php echo isset($theChampFacebookOptions['commenting_order']) ? $theChampFacebookOptions['commenting_order'] : ''; ?>", theChampGpCommentsUrl = '<?php echo isset($theChampFacebookOptions['gpcomments_url']) && $theChampFacebookOptions['gpcomments_url'] != '' ? $theChampFacebookOptions['gpcomments_url'] : $commentUrl; ?>', theChampDisqusShortname = '<?php echo isset($theChampFacebookOptions['dq_shortname']) ? $theChampFacebookOptions['dq_shortname'] : ''; ?>', theChampScEnabledTabs = '<?php echo implode(',', $enabledTabs) ?>', theChampScLabel = '<?php echo $theChampFacebookOptions['commenting_label'] != '' ? htmlspecialchars(wp_specialchars_decode($theChampFacebookOptions['commenting_label'], ENT_QUOTES), ENT_QUOTES) : __('Leave a reply', 'super-socializer'); ?>', theChampScTabLabels = <?php echo json_encode($labels) ?>, theChampGpCommentsWidth = <?php echo isset($theChampFacebookOptions['gpcomments_width']) && $theChampFacebookOptions['gpcomments_width'] != '' ? $theChampFacebookOptions['gpcomments_width'] : 0; ?>, theChampCommentingId = '<?php echo isset($theChampFacebookOptions['commenting_id']) && $theChampFacebookOptions['commenting_id'] != '' ? $theChampFacebookOptions['commenting_id'] : 'respond' ?>'</script>
  958.                 <?php
  959.                 if(!$combinedScript){
  960.                     wp_enqueue_script('the_champ_fb_commenting', plugins_url('js/front/facebook/commenting.js', __FILE__), false, THE_CHAMP_SS_VERSION, $inFooter);
  961.                 }
  962.             }
  963.         }
  964.     }
  965.     // sharing script
  966.     if(the_champ_social_sharing_enabled() || (the_champ_social_counter_enabled() && the_champ_vertical_social_counter_enabled())){
  967.         global $theChampSharingOptions, $theChampCounterOptions, $post;
  968.         ?>
  969.         <script> var theChampSharingAjaxUrl = '<?php echo get_admin_url() ?>admin-ajax.php', heateorSsUrlCountFetched = [], heateorSsSharesText = '<?php echo htmlspecialchars(__('Shares', 'super-socializer'), ENT_QUOTES); ?>', heateorSsShareText = '<?php echo htmlspecialchars(__('Share', 'super-socializer'), ENT_QUOTES); ?>', theChampPluginIconPath = '<?php echo plugins_url('images/logo.png', __FILE__) ?>', theChampHorizontalSharingCountEnable = <?php echo isset($theChampSharingOptions['enable']) && isset($theChampSharingOptions['hor_enable']) && ( isset($theChampSharingOptions['horizontal_counts']) || isset($theChampSharingOptions['horizontal_total_shares']) ) ? 1 : 0 ?>, theChampVerticalSharingCountEnable = <?php echo isset($theChampSharingOptions['enable']) && isset($theChampSharingOptions['vertical_enable']) && ( isset($theChampSharingOptions['vertical_counts']) || isset($theChampSharingOptions['vertical_total_shares']) ) ? 1 : 0 ?>, theChampSharingOffset = <?php echo (isset($theChampSharingOptions['alignment']) && $theChampSharingOptions['alignment'] != '' && isset($theChampSharingOptions[$theChampSharingOptions['alignment'].'_offset']) && $theChampSharingOptions[$theChampSharingOptions['alignment'].'_offset'] != '' ? $theChampSharingOptions[$theChampSharingOptions['alignment'].'_offset'] : 0) ?>, theChampCounterOffset = <?php echo (isset($theChampCounterOptions['alignment']) && $theChampCounterOptions['alignment'] != '' && isset($theChampCounterOptions[$theChampCounterOptions['alignment'].'_offset']) && $theChampCounterOptions[$theChampCounterOptions['alignment'].'_offset'] != '' ? $theChampCounterOptions[$theChampCounterOptions['alignment'].'_offset'] : 0) ?>, theChampMobileStickySharingEnabled = <?php echo isset($theChampSharingOptions['vertical_enable']) && isset($theChampSharingOptions['bottom_mobile_sharing']) && $theChampSharingOptions['horizontal_screen_width'] != '' ? 1 : 0; ?>, heateorSsCopyLinkMessage = "<?php echo htmlspecialchars(__('Link copied.', 'super-socializer'), ENT_QUOTES); ?>";
  970.         <?php
  971.         if(isset($theChampSharingOptions['horizontal_re_providers']) && (isset($theChampSharingOptions['horizontal_more']) || in_array('Copy_Link', $theChampSharingOptions['horizontal_re_providers']))){
  972.             if(isset($theChampSharingOptions['horizontal_target_url']) && $theChampSharingOptions['horizontal_target_url'] == 'default'){
  973.                 $postId = 0;
  974.                 $postUrl = html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
  975.                 if(isset($theChampSharingOptions['horizontal_target_url'])){
  976.                     if($theChampSharingOptions['horizontal_target_url'] == 'default'){
  977.                         if($post){
  978.                             $postUrl = get_permalink($post->ID);
  979.                             $postId = $post->ID;
  980.                         }
  981.                     }elseif($theChampSharingOptions['horizontal_target_url'] == 'home'){
  982.                         $postUrl = esc_url(home_url());
  983.                         $postId = 0;
  984.                     }elseif($theChampSharingOptions['horizontal_target_url'] == 'custom'){
  985.                         $postUrl = isset($theChampSharingOptions['horizontal_target_url_custom']) ? trim($theChampSharingOptions['horizontal_target_url_custom']) : get_permalink($post->ID);
  986.                         $postId = 0;
  987.                     }
  988.                 }else{
  989.                     if($post){
  990.                         $postUrl = get_permalink($post->ID);
  991.                         $postId = $post->ID;
  992.                     }
  993.                 }
  994.                 $postUrl = heateor_ss_apply_target_share_url_filter($postUrl, 'horizontal', false);
  995.                 $sharingShortUrl = the_champ_generate_social_sharing_short_url($postUrl, $postId);
  996.                 echo 'var heateorSsHorSharingShortUrl = "'. $sharingShortUrl .'";';
  997.             }
  998.         }
  999.         if(isset($theChampSharingOptions['vertical_re_providers']) && (isset($theChampSharingOptions['vertical_more']) || in_array('Copy_Link', $theChampSharingOptions['vertical_re_providers']))){
  1000.             if(isset($theChampSharingOptions['vertical_target_url']) && $theChampSharingOptions['vertical_target_url'] == 'default'){
  1001.                 $postId = 0;
  1002.                 $postUrl = html_entity_decode(esc_url(the_champ_get_http().$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
  1003.                 if(isset($theChampSharingOptions['vertical_target_url'])){
  1004.                     if($theChampSharingOptions['vertical_target_url'] == 'default'){
  1005.                         if($post){
  1006.                             $postUrl = get_permalink($post->ID);
  1007.                             $postId = $post->ID;
  1008.                         }
  1009.                     }elseif($theChampSharingOptions['vertical_target_url'] == 'home'){
  1010.                         $postUrl = esc_url(home_url());
  1011.                         $postId = 0;
  1012.                     }elseif($theChampSharingOptions['vertical_target_url'] == 'custom'){
  1013.                         $postUrl = isset($theChampSharingOptions['vertical_target_url_custom']) ? trim($theChampSharingOptions['vertical_target_url_custom']) : get_permalink($post->ID);
  1014.                         $postId = 0;
  1015.                     }
  1016.                 }else{
  1017.                     if($post){
  1018.                         $postUrl = get_permalink($post->ID);
  1019.                         $postId = $post->ID;
  1020.                     }
  1021.                 }
  1022.                 $postUrl = heateor_ss_apply_target_share_url_filter($postUrl, 'vertical', false);
  1023.                 $sharingShortUrl = the_champ_generate_social_sharing_short_url($postUrl, $postId);
  1024.                 echo 'var heateorSsVerticalSharingShortUrl = "'. $sharingShortUrl .'";';
  1025.             }
  1026.         }
  1027.         if(isset($theChampSharingOptions['horizontal_counts']) && isset($theChampSharingOptions['horizontal_counter_position'])){
  1028.             echo in_array($theChampSharingOptions['horizontal_counter_position'], array('inner_left', 'inner_right')) ? 'var theChampReduceHorizontalSvgWidth = true;' : '';
  1029.             echo in_array($theChampSharingOptions['horizontal_counter_position'], array('inner_top', 'inner_bottom')) ? 'var theChampReduceHorizontalSvgHeight = true;' : '';
  1030.         }
  1031.         if(isset($theChampSharingOptions['vertical_counts'])){
  1032.             echo isset($theChampSharingOptions['vertical_counter_position']) && in_array($theChampSharingOptions['vertical_counter_position'], array('inner_left', 'inner_right')) ? 'var theChampReduceVerticalSvgWidth = true;' : '';
  1033.             echo !isset($theChampSharingOptions['vertical_counter_position']) || in_array($theChampSharingOptions['vertical_counter_position'], array('inner_top', 'inner_bottom')) ? 'var theChampReduceVerticalSvgHeight = true;' : '';
  1034.         }
  1035.         ?>
  1036.         </script>
  1037.         <?php
  1038.         if(!$combinedScript){
  1039.             wp_enqueue_script('the_champ_share_counts', plugins_url('js/front/sharing/sharing.js', __FILE__), array('jquery'), THE_CHAMP_SS_VERSION, $inFooter);
  1040.         }
  1041.     }
  1042.  
  1043.     if($combinedScript){
  1044.         wp_enqueue_script('the_champ_combined_script', plugins_url('js/front/combined.js', __FILE__), array('jquery'), THE_CHAMP_SS_VERSION, $inFooter);
  1045.     }
  1046. }
  1047.  
  1048. /**
  1049.  * Stylesheets to load at front end
  1050.  */
  1051. function the_champ_frontend_styles(){
  1052.     global $theChampSharingOptions, $theChampGeneralOptions;
  1053.     ?>
  1054.     <style type="text/css">
  1055.     .the_champ_horizontal_sharing .theChampSharing{
  1056.         <?php if ( $theChampSharingOptions['horizontal_bg_color_default'] != '' ) { ?>
  1057.             background-color: <?php echo $theChampSharingOptions['horizontal_bg_color_default'] ?>;
  1058.         <?php  } ?>
  1059.             color: <?php echo $theChampSharingOptions['horizontal_font_color_default'] ? $theChampSharingOptions['horizontal_font_color_default'] : '#fff' ?>;
  1060.         <?php
  1061.         $border_width = 0;
  1062.         if ( $theChampSharingOptions['horizontal_border_width_default'] != '' ) {
  1063.             $border_width = $theChampSharingOptions['horizontal_border_width_default'];
  1064.         } elseif ( $theChampSharingOptions['horizontal_border_width_hover'] != '' ) {
  1065.             $border_width = $theChampSharingOptions['horizontal_border_width_hover'];
  1066.         }
  1067.         ?>
  1068.         border-width: <?php echo $border_width ?>px;
  1069.         border-style: solid;
  1070.         border-color: <?php echo $theChampSharingOptions['horizontal_border_color_default'] != '' ? $theChampSharingOptions['horizontal_border_color_default'] : 'transparent'; ?>;
  1071.     }
  1072.     <?php if ( $theChampSharingOptions['horizontal_font_color_default'] == '' ) { ?>
  1073.     .the_champ_horizontal_sharing .theChampTCBackground{
  1074.         color:#666;
  1075.     }
  1076.     <?php } ?>
  1077.     .the_champ_horizontal_sharing .theChampSharing:hover{
  1078.         <?php if ( $theChampSharingOptions['horizontal_bg_color_hover'] != '' ) { ?>
  1079.             background-color: <?php echo $theChampSharingOptions['horizontal_bg_color_hover'] ?>;
  1080.         <?php }
  1081.         if ( $theChampSharingOptions['horizontal_font_color_hover'] != '' ) { ?>
  1082.             color: <?php echo $theChampSharingOptions['horizontal_font_color_hover'] ?>;
  1083.         <?php  } ?>
  1084.         border-color: <?php echo $theChampSharingOptions['horizontal_border_color_hover'] != '' ? $theChampSharingOptions['horizontal_border_color_hover'] : 'transparent'; ?>;
  1085.     }
  1086.     .the_champ_vertical_sharing .theChampSharing{
  1087.         <?php if ( $theChampSharingOptions['vertical_bg_color_default'] != '' ) { ?>
  1088.             background-color: <?php echo $theChampSharingOptions['vertical_bg_color_default'] ?>;
  1089.         <?php } ?>
  1090.             color: <?php echo $theChampSharingOptions['vertical_font_color_default'] ? $theChampSharingOptions['vertical_font_color_default'] : '#fff' ?>;
  1091.         <?php
  1092.         $verticalBorderWidth = 0;
  1093.         if ( $theChampSharingOptions['vertical_border_width_default'] != '' ) {
  1094.             $verticalBorderWidth = $theChampSharingOptions['vertical_border_width_default'];
  1095.         } elseif ( $theChampSharingOptions['vertical_border_width_hover'] != '' ) {
  1096.             $verticalBorderWidth = $theChampSharingOptions['vertical_border_width_hover'];
  1097.         }
  1098.         ?>
  1099.         border-width: <?php echo $verticalBorderWidth ?>px;
  1100.         border-style: solid;
  1101.         border-color: <?php echo $theChampSharingOptions['vertical_border_color_default'] != '' ? $theChampSharingOptions['vertical_border_color_default'] : 'transparent'; ?>;
  1102.     }
  1103.     <?php if ( $theChampSharingOptions['horizontal_font_color_default'] == '' ) { ?>
  1104.     .the_champ_vertical_sharing .theChampTCBackground{
  1105.         color:#666;
  1106.     }
  1107.     <?php } ?>
  1108.     .the_champ_vertical_sharing .theChampSharing:hover{
  1109.         <?php if ( $theChampSharingOptions['vertical_bg_color_hover'] != '' ) { ?>
  1110.             background-color: <?php echo $theChampSharingOptions['vertical_bg_color_hover'] ?>;
  1111.         <?php }
  1112.         if ( $theChampSharingOptions['vertical_font_color_hover'] != '' ) { ?>
  1113.             color: <?php echo $theChampSharingOptions['vertical_font_color_hover'] ?>;
  1114.         <?php  } ?>
  1115.         border-color: <?php echo $theChampSharingOptions['vertical_border_color_hover'] != '' ? $theChampSharingOptions['vertical_border_color_hover'] : 'transparent'; ?>;
  1116.     }
  1117.     <?php
  1118.     if ( isset( $theChampSharingOptions['horizontal_counts'] ) ) {
  1119.         $svg_height = $theChampSharingOptions['horizontal_sharing_shape'] == 'rectangle' ? $theChampSharingOptions['horizontal_sharing_height'] : $theChampSharingOptions['horizontal_sharing_size'];
  1120.         if ( isset( $theChampSharingOptions['horizontal_counter_position'] ) && in_array( $theChampSharingOptions['horizontal_counter_position'], array( 'inner_top', 'inner_bottom' ) ) ) {
  1121.             $line_height_percent = $theChampSharingOptions['horizontal_counter_position'] == 'inner_top' ? 38 : 19;
  1122.             ?>
  1123.             div.the_champ_horizontal_sharing .theChampSharingSvg{height:70%;margin-top:<?php echo $svg_height*15/100 ?>px}div.the_champ_horizontal_sharing .the_champ_square_count{line-height:<?php echo $svg_height*$line_height_percent/100 ?>px;}
  1124.             <?php
  1125.         } elseif ( isset( $theChampSharingOptions['horizontal_counter_position'] ) && in_array( $theChampSharingOptions['horizontal_counter_position'], array( 'inner_left', 'inner_right' ) ) ) { ?>
  1126.             div.the_champ_horizontal_sharing .theChampSharingSvg{width:50%;margin:auto;}div.the_champ_horizontal_sharing .the_champ_square_count{float:left;width:50%;line-height:<?php echo $svg_height; ?>px;}
  1127.             <?php
  1128.         } elseif ( isset( $theChampSharingOptions['horizontal_counter_position'] ) && in_array( $theChampSharingOptions['horizontal_counter_position'], array( 'left', 'right' ) ) ) { ?>
  1129.             div.the_champ_horizontal_sharing .the_champ_square_count{float:<?php echo $theChampSharingOptions['horizontal_counter_position'] ?>;margin:0 8px;line-height:<?php echo $svg_height + 2 * $border_width; ?>px;}
  1130.             <?php
  1131.         } elseif ( ! isset( $theChampSharingOptions['horizontal_counter_position'] ) || $theChampSharingOptions['horizontal_counter_position'] == 'top' ) { ?>
  1132.             div.the_champ_horizontal_sharing .the_champ_square_count{display: block}
  1133.             <?php
  1134.         }
  1135.  
  1136.     }
  1137.     if ( isset( $theChampSharingOptions['vertical_counts'] ) ) {
  1138.         $vertical_svg_height = $theChampSharingOptions['vertical_sharing_shape'] == 'rectangle' ? $theChampSharingOptions['vertical_sharing_height'] : $theChampSharingOptions['vertical_sharing_size'];
  1139.         $vertical_svg_width = $theChampSharingOptions['vertical_sharing_shape'] == 'rectangle' ? $theChampSharingOptions['vertical_sharing_width'] : $theChampSharingOptions['vertical_sharing_size'];
  1140.         if ( ( isset( $theChampSharingOptions['vertical_counter_position'] ) && in_array( $theChampSharingOptions['vertical_counter_position'], array( 'inner_top', 'inner_bottom' ) ) ) || ! isset( $theChampSharingOptions['vertical_counter_position'] ) ) {
  1141.             $vertical_line_height_percent = ! isset( $theChampSharingOptions['vertical_counter_position'] ) || $theChampSharingOptions['vertical_counter_position'] == 'inner_top' ? 38 : 19;
  1142.             ?>
  1143.             div.the_champ_vertical_sharing .theChampSharingSvg{height:70%;margin-top:<?php echo $vertical_svg_height*15/100 ?>px}div.the_champ_vertical_sharing .the_champ_square_count{line-height:<?php echo $vertical_svg_height*$vertical_line_height_percent/100; ?>px;}
  1144.             <?php
  1145.         } elseif ( isset( $theChampSharingOptions['vertical_counter_position'] ) && in_array( $theChampSharingOptions['vertical_counter_position'], array( 'inner_left', 'inner_right' ) ) ) { ?>
  1146.             div.the_champ_vertical_sharing .theChampSharingSvg{width:50%;margin:auto;}div.the_champ_vertical_sharing .the_champ_square_count{float:left;width:50%;line-height:<?php echo $vertical_svg_height; ?>px;}
  1147.             <?php
  1148.         }  elseif ( isset( $theChampSharingOptions['vertical_counter_position'] ) && in_array( $theChampSharingOptions['vertical_counter_position'], array( 'left', 'right' ) ) ) { ?>
  1149.             div.the_champ_vertical_sharing .the_champ_square_count{float:<?php echo $theChampSharingOptions['vertical_counter_position'] ?>;margin:0 8px;line-height:<?php echo $vertical_svg_height; ?>px; <?php echo $theChampSharingOptions['vertical_counter_position'] == 'left' ? 'min-width:' . $vertical_svg_width*30/100 . 'px;display: block' : '';?>}
  1150.             <?php
  1151.         } elseif ( isset( $theChampSharingOptions['vertical_counter_position'] ) && $theChampSharingOptions['vertical_counter_position'] == 'top' ) { ?>
  1152.             div.the_champ_vertical_sharing .the_champ_square_count{display: block}
  1153.             <?php
  1154.         }
  1155.     }
  1156.     echo isset( $theChampSharingOptions['hide_mobile_sharing'] ) && $theChampSharingOptions['vertical_screen_width'] != '' ? '@media screen and (max-width:' . $theChampSharingOptions['vertical_screen_width'] . 'px){.the_champ_vertical_sharing{display:none!important}}' : '';
  1157.     $bottom_sharing_postion_inverse = $theChampSharingOptions['bottom_sharing_alignment'] == 'left' ? 'right' : 'left';
  1158.     $bottom_sharing_responsive_css = '';
  1159.     if($theChampSharingOptions['bottom_sharing_position_radio'] == 'responsive'){
  1160.         $vertical_sharing_icon_height = $theChampSharingOptions['vertical_sharing_shape'] == 'rectangle' ? $theChampSharingOptions['vertical_sharing_height'] : $theChampSharingOptions['vertical_sharing_size'];
  1161.         $num_sharing_icons = isset($theChampSharingOptions['vertical_re_providers']) ? count($theChampSharingOptions['vertical_re_providers']) : 0;
  1162.         $total_share_count_enabled = isset($theChampSharingOptions['vertical_total_shares']) ? 1 : 0;
  1163.         $more_icon_enabled = isset($theChampSharingOptions['vertical_more']) ? 1 : 0;
  1164.         $bottom_sharing_responsive_css = 'div.the_champ_bottom_sharing{width:100%!important;left:0!important;}div.the_champ_bottom_sharing li{width:'.(100/($num_sharing_icons+$total_share_count_enabled+$more_icon_enabled)).'% !important;}div.the_champ_bottom_sharing .theChampSharing{width: 100% !important;}div.the_champ_bottom_sharing div.theChampTotalShareCount{font-size:1em!important;line-height:' . ( $vertical_sharing_icon_height*70/100 ) . 'px!important}div.the_champ_bottom_sharing div.theChampTotalShareText{font-size:.7em!important;line-height:0px!important}';
  1165.     }
  1166.     echo isset($theChampSharingOptions['vertical_enable']) && isset( $theChampSharingOptions['bottom_mobile_sharing'] ) && $theChampSharingOptions['horizontal_screen_width'] != '' ? 'div.heateor_ss_mobile_footer{display:none;}@media screen and (max-width:' . $theChampSharingOptions['horizontal_screen_width'] . 'px){'.$bottom_sharing_responsive_css.'div.heateor_ss_mobile_footer{display:block;height:'.($theChampSharingOptions['vertical_sharing_shape'] == 'rectangle' ? $theChampSharingOptions['vertical_sharing_height'] : $theChampSharingOptions['vertical_sharing_size']).'px;}.the_champ_bottom_sharing{padding:0!important;' . ( $theChampSharingOptions['bottom_sharing_position_radio'] == 'nonresponsive' && $theChampSharingOptions['bottom_sharing_position'] != '' ? $theChampSharingOptions['bottom_sharing_alignment'] . ':' . $theChampSharingOptions['bottom_sharing_position'] . 'px!important;' . $bottom_sharing_postion_inverse . ':auto!important;' : '' ) . 'display:block!important;width: auto!important;bottom:' . ( isset( $theChampSharingOptions['vertical_total_shares'] ) ? '-10' : '-2' ) . 'px!important;top: auto!important;}.the_champ_bottom_sharing .the_champ_square_count{line-height: inherit;}.the_champ_bottom_sharing .theChampSharingArrow{display:none;}.the_champ_bottom_sharing .theChampTCBackground{margin-right: 1.1em !important}}' : '';
  1167.     echo $theChampGeneralOptions['custom_css'];
  1168.     ?>
  1169.     </style>
  1170.     <?php
  1171.     wp_enqueue_style( 'the_champ_frontend_css', plugins_url( 'css/front.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1172.     $default_svg = false;
  1173.     if ( isset( $theChampSharingOptions['enable'] ) ) {
  1174.         if ( isset( $theChampSharingOptions['hor_enable'] ) ) {
  1175.             if ( isset( $theChampSharingOptions['horizontal_more'] ) ) {
  1176.                 $default_svg = true;
  1177.             }
  1178.             if ( $theChampSharingOptions['horizontal_font_color_default'] != '' ) {
  1179.                 wp_enqueue_style( 'the_champ_sharing_svg', plugins_url( 'css/share-default-svg-horizontal.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1180.             } else {
  1181.                 $default_svg = true;
  1182.             }
  1183.             if ( $theChampSharingOptions['horizontal_font_color_hover'] != '' ) {
  1184.                 wp_enqueue_style( 'the_champ_sharing_svg_hover', plugins_url( 'css/share-hover-svg-horizontal.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1185.             }
  1186.         }
  1187.         if ( isset( $theChampSharingOptions['vertical_enable'] ) ) {
  1188.             if ( isset( $theChampSharingOptions['vertical_more'] ) ) {
  1189.                 $default_svg = true;
  1190.             }
  1191.             if ( $theChampSharingOptions['vertical_font_color_default'] != '' ) {
  1192.                 wp_enqueue_style( 'the_champ_vertical_sharing_svg', plugins_url( 'css/share-default-svg-vertical.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1193.             } else {
  1194.                 $default_svg = true;
  1195.             }
  1196.             if ( $theChampSharingOptions['vertical_font_color_hover'] != '' ) {
  1197.                 wp_enqueue_style( 'the_champ_vertical_sharing_svg_hover', plugins_url( 'css/share-hover-svg-vertical.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1198.             }
  1199.         }
  1200.     }
  1201.     if ( $default_svg ) {
  1202.         wp_enqueue_style( 'the_champ_sharing_default_svg', plugins_url( 'css/share-svg.css', __FILE__ ), false, THE_CHAMP_SS_VERSION );
  1203.     }
  1204. }
  1205.  
  1206. /**
  1207.  * Create plugin menu in admin.
  1208.  */
  1209. function the_champ_create_admin_menu(){
  1210.     $page = add_menu_page('Super Socializer by Heateor', 'Super Socializer', 'manage_options', 'heateor-ss-general-options', 'the_champ_general_options_page', plugins_url('images/logo.png', __FILE__));
  1211.     // general options page
  1212.     $generalOptionsPage = add_submenu_page( 'heateor-ss-general-options', __( "Super Socializer - General Options", 'super-socializer' ), __( "General Options", 'super-socializer' ), 'manage_options', 'heateor-ss-general-options', 'the_champ_general_options_page' );
  1213.     // facebook page
  1214.     $facebookPage = add_submenu_page('heateor-ss-general-options', 'Super Socializer - Social Commenting', 'Social Commenting', 'manage_options', 'heateor-social-commenting', 'the_champ_facebook_page');
  1215.     // social login page
  1216.     $loginPage = add_submenu_page('heateor-ss-general-options', 'Super Socializer - Social Login', 'Social Login', 'manage_options', 'heateor-social-login', 'the_champ_social_login_page');
  1217.     // social sharing page
  1218.     $sharingPage = add_submenu_page('heateor-ss-general-options', 'Super Socializer - Social Sharing', 'Social Sharing', 'manage_options', 'heateor-social-sharing', 'the_champ_social_sharing_page');
  1219.     // like buttons page
  1220.     $counterPage = add_submenu_page('heateor-ss-general-options', 'Super Socializer - Like Buttons', 'Like Buttons', 'manage_options', 'heateor-like-buttons', 'the_champ_like_buttons_page');
  1221.     add_action('admin_print_scripts-' . $page, 'the_champ_admin_scripts');
  1222.     add_action('admin_print_scripts-' . $page, 'the_champ_admin_style');
  1223.     add_action('admin_print_scripts-' . $page, 'the_champ_fb_sdk_script');
  1224.     add_action('admin_print_scripts-' . $generalOptionsPage, 'the_champ_admin_scripts');
  1225.     add_action('admin_print_scripts-' . $generalOptionsPage, 'the_champ_fb_sdk_script');
  1226.     add_action('admin_print_styles-' . $generalOptionsPage, 'the_champ_admin_style');
  1227.     add_action('admin_print_scripts-' . $facebookPage, 'the_champ_admin_scripts');
  1228.     add_action('admin_print_scripts-' . $facebookPage, 'the_champ_fb_sdk_script');
  1229.     add_action('admin_print_styles-' . $facebookPage, 'the_champ_admin_style');
  1230.     add_action('admin_print_scripts-' . $loginPage, 'the_champ_admin_scripts');
  1231.     add_action('admin_print_scripts-' . $loginPage, 'the_champ_fb_sdk_script');
  1232.     add_action('admin_print_styles-' . $loginPage, 'the_champ_admin_style');
  1233.     add_action('admin_print_scripts-' . $sharingPage, 'the_champ_admin_scripts');
  1234.     add_action('admin_print_scripts-' . $sharingPage, 'the_champ_fb_sdk_script');
  1235.     add_action('admin_print_scripts-' . $sharingPage, 'the_champ_admin_sharing_scripts');
  1236.     add_action('admin_print_styles-' . $sharingPage, 'the_champ_admin_style');
  1237.     add_action('admin_print_styles-' . $sharingPage, 'the_champ_admin_sharing_style');
  1238.     add_action('admin_print_scripts-' . $counterPage, 'the_champ_admin_scripts');
  1239.     add_action('admin_print_scripts-' . $counterPage, 'the_champ_fb_sdk_script');
  1240.     add_action('admin_print_scripts-' . $counterPage, 'the_champ_admin_counter_scripts');
  1241.     add_action('admin_print_styles-' . $counterPage, 'the_champ_admin_style');
  1242. }
  1243. add_action('admin_menu', 'the_champ_create_admin_menu');
  1244.  
  1245. /**
  1246.  * Auto-approve comments made by social login users
  1247.  */
  1248. function the_champ_auto_approve_comment($approved){
  1249.     global $theChampLoginOptions;
  1250.     if(empty($approved)){
  1251.         if(isset($theChampLoginOptions['autoApproveComment'])){
  1252.             $userId = get_current_user_id();
  1253.             $commentUser = get_user_meta($userId, 'thechamp_current_id', true);
  1254.             if($commentUser !== false){
  1255.                 $approved = 1;
  1256.             }  
  1257.         }
  1258.     }
  1259.     return $approved;
  1260. }
  1261. add_action('pre_comment_approved', 'the_champ_auto_approve_comment');
  1262.  
  1263. /**
  1264.  * Place "fb-root" div in website footer
  1265.  */
  1266. function the_champ_fb_root_div(){
  1267.     ?>
  1268.     <div id="fb-root"></div>
  1269.     <?php
  1270. }
  1271.  
  1272. /**
  1273.  * Show Social Avatar options at profile page
  1274.  */
  1275. function the_champ_show_avatar_option( $user ) {
  1276.     global $user_ID, $theChampLoginOptions;
  1277.     if ( isset( $theChampLoginOptions['enable'] ) ) {
  1278.         $dontUpdateAvatar = get_user_meta($user_ID, 'thechamp_dontupdate_avatar', true);
  1279.         ?>
  1280.         <h3><?php _e( 'Social Avatar', 'super-socializer' ) ?></h3>
  1281.         <table class="form-table">
  1282.             <tr>
  1283.                 <th><label for="ss_small_avatar"><?php _e( 'Small Avatar Url', 'super-socializer' ) ?></label></th>
  1284.                 <td><input id="ss_small_avatar" type="text" name="the_champ_small_avatar" value="<?php echo esc_attr(get_user_meta( $user->ID, 'thechamp_avatar', true )); ?>" class="regular-text" /></td>
  1285.             </tr>
  1286.             <tr>
  1287.                 <th><label for="ss_large_avatar"><?php _e( 'Large Avatar Url', 'super-socializer' ) ?></label></th>
  1288.                 <td><input id="ss_large_avatar" type="text" name="the_champ_large_avatar" value="<?php echo esc_attr(get_user_meta( $user->ID, 'thechamp_large_avatar', true )); ?>" class="regular-text" /></td>
  1289.             </tr>
  1290.             <tr>
  1291.                 <th><label for="ss_dontupdate_avatar_1"><?php _e( 'Do not fetch and update social avatar from my profile, next time I Social Login', 'super-socializer' ) ?></label></th>
  1292.                 <td><input id="ss_dontupdate_avatar_1" style="margin-right:5px" type="radio" name="ss_dontupdate_avatar" value="1" <?php echo $dontUpdateAvatar ? 'checked' : '' ?> /></td>
  1293.             </tr>
  1294.             <tr>
  1295.                 <th><label for="ss_dontupdate_avatar_0"><?php _e( 'Update social avatar, next time I Social Login', 'super-socializer' ) ?></label></th>
  1296.                 <td><input id="ss_dontupdate_avatar_0" style="margin-right:5px" type="radio" name="ss_dontupdate_avatar" value="0" <?php echo ! $dontUpdateAvatar ? 'checked' : '' ?> /></td>
  1297.             </tr>
  1298.         </table>
  1299.         <?php
  1300.     }
  1301. }
  1302. add_action( 'edit_user_profile', 'the_champ_show_avatar_option' );
  1303. add_action( 'show_user_profile', 'the_champ_show_avatar_option' );
  1304.  
  1305. /**
  1306.  * Save social avatar options from profile page
  1307.  */
  1308. function the_champ_save_avatar( $user_id ) {    
  1309.     if ( ! current_user_can( 'edit_user', $user_id ) ) {
  1310.         return false;
  1311.     }
  1312.     if ( isset( $_POST['the_champ_small_avatar'] ) ) {
  1313.         update_user_meta( $user_id, 'thechamp_avatar', esc_url(trim($_POST['the_champ_small_avatar'])) );
  1314.     }
  1315.     if ( isset( $_POST['the_champ_large_avatar'] ) ) {
  1316.         update_user_meta( $user_id, 'thechamp_large_avatar', esc_url(trim($_POST['the_champ_large_avatar'])) );
  1317.     }
  1318.     if ( isset( $_POST['ss_dontupdate_avatar'] ) ) {
  1319.         update_user_meta( $user_id, 'thechamp_dontupdate_avatar', intval( $_POST['ss_dontupdate_avatar'] ) );
  1320.     }
  1321. }
  1322. add_action( 'personal_options_update', 'the_champ_save_avatar' );
  1323. add_action( 'edit_user_profile_update', 'the_champ_save_avatar' );
  1324.  
  1325. if(!function_exists('array_replace')){
  1326.     /**
  1327.      * Custom 'array_replace' function for PHP version < 5.3
  1328.      */
  1329.     function array_replace(){
  1330.         $args = func_get_args();
  1331.         $numArgs = func_num_args();
  1332.         $res = array();
  1333.         for($i = 0; $i < $numArgs; $i++){
  1334.             if(is_array($args[$i])){
  1335.                 foreach($args[$i] as $key => $val){
  1336.                     $res[$key] = $val;
  1337.                 }
  1338.             }else{
  1339.                 trigger_error(__FUNCTION__ .'(): Argument #'.($i+1).' is not an array', E_USER_WARNING);
  1340.                 return NULL;
  1341.             }
  1342.         }
  1343.         return $res;
  1344.     }
  1345. }
  1346.  
  1347. /**
  1348.  * Replace a value in array
  1349.  */
  1350. function the_champ_replace_array_value($array, $value, $replacement){
  1351.     return array_replace($array,
  1352.         array_fill_keys(
  1353.             array_keys($array, $value),
  1354.             $replacement
  1355.         )
  1356.     );
  1357. }
  1358.  
  1359. /**
  1360.  * Default options when plugin is installed
  1361.  */
  1362. function the_champ_save_default_options(){
  1363.     // general options
  1364.     add_option('the_champ_general', array(
  1365.        'footer_script' => '1',
  1366.        'delete_options' => '1',
  1367.        'browser_msg_enable' => '1',
  1368.        'browser_msg' => __('Your browser is blocking some features of this website. Please follow the instructions at {support_url} to unblock these.', 'super-socializer'),
  1369.        'custom_css' => ''
  1370.     ));
  1371.  
  1372.     // login options
  1373.     add_option('the_champ_login', array(
  1374.        'title' => __('Login with your Social ID', 'super-socializer'),
  1375.        'email_error_message' => __('Email you entered is already registered or invalid', 'super-socializer'),
  1376.        'avatar' => 1,
  1377.        'email_required' => 1,
  1378.        'password_email' => 1,
  1379.        'new_user_admin_email' => 1,
  1380.        'email_popup_text' => __('Please enter a valid email address. You might be required to verify it', 'super-socializer'),
  1381.        'enableAtLogin' => 1,
  1382.        'enableAtRegister' => 1,
  1383.        'enableAtComment' => 1,
  1384.        'link_account' => 1
  1385.     ));
  1386.    
  1387.     // social commenting options
  1388.     add_option('the_champ_facebook', array(
  1389.        'enable_commenting' => '1',
  1390.        'enable_fbcomments' => '1',
  1391.        'enable_page' => '1',
  1392.        'enable_post' => '1',
  1393.        'comment_lang' => get_locale(),
  1394.        'commenting_order' => 'wordpress,facebook,googleplus,disqus',
  1395.        'commenting_label' => 'Leave a reply',
  1396.        'label_wordpress_comments' => 'Default Comments',
  1397.        'label_facebook_comments' => 'Facebook Comments',
  1398.        'label_googleplus_comments' => 'G+ Comments',
  1399.        'label_disqus_comments' => 'Disqus Comments',
  1400.     ));
  1401.    
  1402.     // sharing options
  1403.     add_option('the_champ_sharing', array(
  1404.        'enable' => '1',
  1405.        'horizontal_sharing_shape' => 'round',
  1406.        'horizontal_sharing_size' => '35',
  1407.        'horizontal_sharing_width' => '70',
  1408.        'horizontal_sharing_height' => '35',
  1409.        'horizontal_border_radius' => '',
  1410.        'horizontal_font_color_default' => '',
  1411.        'horizontal_sharing_replace_color' => '#fff',
  1412.        'horizontal_font_color_hover' => '',
  1413.        'horizontal_sharing_replace_color_hover' => '#fff',
  1414.        'horizontal_bg_color_default' => '',
  1415.        'horizontal_bg_color_hover' => '',
  1416.        'horizontal_border_width_default' => '',
  1417.        'horizontal_border_color_default' => '',
  1418.        'horizontal_border_width_hover' => '',
  1419.        'horizontal_border_color_hover' => '',
  1420.        'vertical_sharing_shape' => 'square',
  1421.        'vertical_sharing_size' => '40',
  1422.        'vertical_sharing_width' => '80',
  1423.        'vertical_sharing_height' => '40',
  1424.        'vertical_border_radius' => '',
  1425.        'vertical_font_color_default' => '',
  1426.        'vertical_sharing_replace_color' => '#fff',
  1427.        'vertical_font_color_hover' => '',
  1428.        'vertical_sharing_replace_color_hover' => '#fff',
  1429.        'vertical_bg_color_default' => '',
  1430.        'vertical_bg_color_hover' => '',
  1431.        'vertical_border_width_default' => '',
  1432.        'vertical_border_color_default' => '',
  1433.        'vertical_border_width_hover' => '',
  1434.        'vertical_border_color_hover' => '',
  1435.        'hor_enable' => '1',
  1436.        'horizontal_target_url' => 'default',
  1437.        'horizontal_target_url_custom' => '',
  1438.        'title' => 'Spread the love',
  1439.        'instagram_username' => '',
  1440.        'comment_container_id' => 'respond',
  1441.        'horizontal_re_providers' => array( 'facebook', 'twitter', 'google_plus', 'linkedin', 'pinterest', 'reddit', 'delicious', 'stumbleupon', 'whatsapp' ),
  1442.        'hor_sharing_alignment' => 'left',
  1443.        'top' => '1',
  1444.        'post' => '1',
  1445.        'page' => '1',
  1446.        'horizontal_more' => '1',
  1447.        'vertical_enable' => '1',
  1448.        'vertical_target_url' => 'default',
  1449.        'vertical_target_url_custom' => '',
  1450.        'vertical_instagram_username' => '',
  1451.        'vertical_comment_container_id' => 'respond',
  1452.        'vertical_re_providers' => array( 'facebook', 'twitter', 'google_plus', 'linkedin', 'pinterest', 'reddit', 'delicious', 'stumbleupon', 'whatsapp' ),
  1453.        'vertical_bg' => '',
  1454.        'alignment' => 'left',
  1455.        'left_offset' => '-10',
  1456.        'right_offset' => '-10',
  1457.        'top_offset' => '100',
  1458.        'vertical_post' => '1',
  1459.        'vertical_page' => '1',
  1460.        'vertical_home' => '1',
  1461.        'vertical_more' => '1',
  1462.        'hide_mobile_sharing' => '1',
  1463.        'vertical_screen_width' => '783',
  1464.        'bottom_mobile_sharing' => '1',
  1465.        'horizontal_screen_width' => '783',
  1466.        'bottom_sharing_position' => '0',
  1467.        'bottom_sharing_alignment' => 'left',
  1468.        'bottom_sharing_position_radio' => 'responsive',
  1469.        'bitly_username' => '',
  1470.        'bitly_key' => '',
  1471.        'share_count_cache_refresh_count' => '10',
  1472.        'share_count_cache_refresh_unit' => 'minutes',
  1473.        'language' => get_locale(),
  1474.        'twitter_username' => '',
  1475.        'buffer_username' => '',
  1476.        'tweet_count_service' => 'newsharecounts'
  1477.     ));
  1478.  
  1479.     // counter options
  1480.     add_option('the_champ_counter', array(
  1481.        'left_offset' => '-10',
  1482.        'right_offset' => '-10',
  1483.        'top_offset' => '100',
  1484.        'alignment' => 'left',
  1485.     ));
  1486.  
  1487.     add_option('the_champ_ss_version', THE_CHAMP_SS_VERSION);
  1488. }
  1489.  
  1490. /**
  1491.  * Plugin activation function
  1492.  */
  1493. function the_champ_activate_plugin($networkWide){
  1494.     global $wpdb;
  1495.     if(function_exists('is_multisite') && is_multisite()){
  1496.         //check if it is network activation if so run the activation function for each id
  1497.         if($networkWide){
  1498.             $oldBlog =  $wpdb->blogid;
  1499.             //Get all blog ids
  1500.             $blogIds =  $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
  1501.  
  1502.             foreach($blogIds as $blogId){
  1503.                 switch_to_blog($blogId);
  1504.                 the_champ_save_default_options();
  1505.             }
  1506.             switch_to_blog($oldBlog);
  1507.             return;
  1508.         }
  1509.     }
  1510.     the_champ_save_default_options();
  1511. }
  1512. register_activation_hook(__FILE__, 'the_champ_activate_plugin');
  1513.  
  1514. /**
  1515.  * Save default options for the new subsite created
  1516.  */
  1517. function the_champ_new_subsite_default_options($blogId, $userId, $domain, $path, $siteId, $meta){
  1518.     if(is_plugin_active_for_network('super-socializer/super_socializer.php')){
  1519.         switch_to_blog($blogId);
  1520.         the_champ_save_default_options();
  1521.         restore_current_blog();
  1522.     }
  1523. }
  1524. add_action('wpmu_new_blog', 'the_champ_new_subsite_default_options', 10, 6);
  1525.  
  1526. /**
  1527.  * Set flag in database if browser message notification has been read
  1528.  */
  1529. function heateor_ss_browser_notification_read(){
  1530.     update_option('heateor_ss_browser_notification_read', '1');
  1531.     die;
  1532. }
  1533. add_action('wp_ajax_heateor_ss_browser_notification_read', 'heateor_ss_browser_notification_read');
  1534.  
  1535. /**
  1536.  * Set flag in database if Facebook redirection notification has been read
  1537.  */
  1538. function heateor_ss_fb_redirection_notification_read(){
  1539.     update_option('heateor_ss_fb_redirection_notification_read', '1');
  1540.     die;
  1541. }
  1542. add_action('wp_ajax_heateor_ss_fb_redirection_notification_read', 'heateor_ss_fb_redirection_notification_read');
  1543.  
  1544. /**
  1545.  * Set flag in database if Linkedin redirection notification has been read
  1546.  */
  1547. function heateor_ss_linkedin_redirection_notification_read(){
  1548.     update_option('heateor_ss_linkedin_redirection_notification_read', '1');
  1549.     die;
  1550. }
  1551. add_action('wp_ajax_heateor_ss_linkedin_redirection_notification_read', 'heateor_ss_linkedin_redirection_notification_read');
  1552.  
  1553. /**
  1554.  * Set flag in database if Google redirection notification has been read
  1555.  */
  1556. function heateor_ss_google_redirection_notification_read(){
  1557.     update_option('heateor_ss_google_redirection_notification_read', '1');
  1558.     die;
  1559. }
  1560. add_action('wp_ajax_heateor_ss_google_redirection_notification_read', 'heateor_ss_google_redirection_notification_read');
  1561.  
  1562. /**
  1563.  * Show notification related to add-on update
  1564.  */
  1565. function the_champ_addon_update_notification(){
  1566.     if(current_user_can('manage_options')){
  1567.         global $theChampLoginOptions;
  1568.         if(defined('HEATEOR_SOCIAL_SHARE_MYCRED_INTEGRATION_VERSION') && version_compare('1.3.3', HEATEOR_SOCIAL_SHARE_MYCRED_INTEGRATION_VERSION) > 0){
  1569.             ?>
  1570.             <div class="error notice">
  1571.                 <h3>Social Share - myCRED Integration</h3>
  1572.                 <p>Update "Social Share myCRED Integration" add-on for maximum compatibility with current version of Super Socialzer</p>
  1573.             </div>
  1574.             <?php
  1575.         }
  1576.  
  1577.         if(defined('HEATEOR_SOCIAL_LOGIN_MYCRED_INTEGRATION_VERSION') && version_compare('1.2.1', HEATEOR_SOCIAL_LOGIN_MYCRED_INTEGRATION_VERSION) > 0){
  1578.             ?>
  1579.             <div class="error notice">
  1580.                 <h3>Social Login - myCRED Integration</h3>
  1581.                 <p>Update "Social Login myCRED Integration" add-on for maximum compatibility with current version of Super Socialzer</p>
  1582.             </div>
  1583.             <?php
  1584.         }elseif(defined('HEATEOR_SOCIAL_LOGIN_MYCRED_INTEGRATION_VERSION') && version_compare('1.2.7', HEATEOR_SOCIAL_LOGIN_MYCRED_INTEGRATION_VERSION) > 0){
  1585.             ?>
  1586.             <div class="error notice">
  1587.                 <h3>Social Login - myCRED Integration</h3>
  1588.                 <p>Update "Social Login myCRED Integration" add-on for compatibility with LiveJournal Login of Super Socialzer</p>
  1589.             </div>
  1590.             <?php
  1591.         }
  1592.  
  1593.         $currentVersion = get_option('the_champ_ss_version');
  1594.  
  1595.         if(version_compare('7.10.5', $currentVersion) < 0 && isset($theChampLoginOptions['enable']) && isset($theChampLoginOptions['providers']) && in_array('steam', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['steam_api_key']) || $theChampLoginOptions['steam_api_key'] == '')){
  1596.             ?>
  1597.             <div class="error">
  1598.                 <h3>Super Socializer</h3>
  1599.                 <p><?php echo sprintf(__('To continue using Steam login save Steam API key <a href="%s">here</a>', 'super-socializer'), 'admin.php?page=heateor-social-login'); ?></p>
  1600.             </div>
  1601.             <?php
  1602.         }
  1603.         if(version_compare('7.11', $currentVersion) <= 0 && isset($theChampLoginOptions['enable']) && isset($theChampLoginOptions['providers']) &&
  1604.             (
  1605.                 (in_array('facebook', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['fb_secret']) || $theChampLoginOptions['fb_secret'] == '')) ||
  1606.                 (in_array('linkedin', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['li_secret']) || $theChampLoginOptions['li_secret'] == '') ) ||
  1607.                 (in_array('google', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['google_secret']) || $theChampLoginOptions['google_secret'] == '')) ||
  1608.                 (in_array('vkontakte', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['vk_secure_key']) || $theChampLoginOptions['vk_secure_key'] == '')) ||
  1609.                 (in_array('twitch', $theChampLoginOptions['providers']) && (!isset($theChampLoginOptions['twitch_client_secret']) || $theChampLoginOptions['twitch_client_secret'] == ''))
  1610.             )
  1611.         ){
  1612.             ?>
  1613.             <div class="error">
  1614.                 <h3>Super Socializer</h3>
  1615.                 <p><?php echo sprintf(__('To continue using Social Login, save the secret keys <a href="%s">here</a>', 'super-socializer'), 'admin.php?page=heateor-social-login'); ?></p>
  1616.             </div>
  1617.             <?php
  1618.         }
  1619.  
  1620.         if(version_compare('7.11', $currentVersion) <= 0 && isset($theChampLoginOptions['enable']) && in_array('facebook', $theChampLoginOptions['providers'])){
  1621.             if(!get_option('heateor_ss_fb_redirection_notification_read')){
  1622.                 ?>
  1623.                 <script type="text/javascript">
  1624.                 function heateorSsFbRedirectionNotificationRead(){
  1625.                     jQuery.ajax({
  1626.                         type: 'GET',
  1627.                         url: '<?php echo get_admin_url() ?>admin-ajax.php',
  1628.                         data: {
  1629.                             action: 'heateor_ss_fb_redirection_notification_read'
  1630.                         },
  1631.                         success: function(data, textStatus, XMLHttpRequest){
  1632.                             jQuery('#heateor_ss_fb_redirection_notification').fadeOut();
  1633.                         }
  1634.                     });
  1635.                 }
  1636.                 </script>
  1637.                 <div id="heateor_ss_fb_redirection_notification" class="error">
  1638.                     <h3>Super Socializer</h3>
  1639.                     <p><?php echo sprintf(__('Add %s in "Valid OAuth redirect URIs" option in your Facebook app settings for Facebook login to work. For more details, check step 9 <a href="%s" target="_blank">here</a>', 'super-socializer'), home_url() . '/?SuperSocializerAuth=Facebook', 'http://support.heateor.com/how-to-get-facebook-app-id/'); ?><input type="button" onclick="heateorSsFbRedirectionNotificationRead()" style="margin-left: 5px;" class="button button-primary" value="<?php _e('Okay', 'super-socializer') ?>" /></p>
  1640.                 </div>
  1641.                 <?php
  1642.             }
  1643.         }
  1644.  
  1645.         if(version_compare('7.11', $currentVersion) <= 0 && isset($theChampLoginOptions['enable']) && in_array('linkedin', $theChampLoginOptions['providers'])){
  1646.             if(!get_option('heateor_ss_linkedin_redirection_notification_read')){
  1647.                 ?>
  1648.                 <script type="text/javascript">
  1649.                 function heateorSsLinkedinRedirectionNotificationRead(){
  1650.                     jQuery.ajax({
  1651.                         type: 'GET',
  1652.                         url: '<?php echo get_admin_url() ?>admin-ajax.php',
  1653.                         data: {
  1654.                             action: 'heateor_ss_linkedin_redirection_notification_read'
  1655.                         },
  1656.                         success: function(data, textStatus, XMLHttpRequest){
  1657.                             jQuery('#heateor_ss_linkedin_redirection_notification').fadeOut();
  1658.                         }
  1659.                     });
  1660.                 }
  1661.                 </script>
  1662.                 <div id="heateor_ss_linkedin_redirection_notification" class="error">
  1663.                     <h3>Super Socializer</h3>
  1664.                     <p><?php echo sprintf(__('Add %s in "Authorized Redirect URLs" option in your Linkedin app settings for Linkedin login to work. For more details, check step 4 <a href="%s" target="_blank">here</a>', 'super-socializer'), home_url(), 'http://support.heateor.com/how-to-get-linkedin-api-key/'); ?><input type="button" onclick="heateorSsLinkedinRedirectionNotificationRead()" style="margin-left: 5px;" class="button button-primary" value="<?php _e('Okay', 'super-socializer') ?>" /></p>
  1665.                 </div>
  1666.                 <?php
  1667.             }
  1668.         }
  1669.  
  1670.         if(version_compare('7.11', $currentVersion) <= 0 && isset($theChampLoginOptions['enable']) && in_array('google', $theChampLoginOptions['providers']) && home_url() != the_champ_get_http() . $_SERVER['HTTP_HOST']){
  1671.             if(!get_option('heateor_ss_google_redirection_notification_read')){
  1672.                 ?>
  1673.                 <script type="text/javascript">
  1674.                 function heateorSsGoogleRedirectionNotificationRead(){
  1675.                     jQuery.ajax({
  1676.                         type: 'GET',
  1677.                         url: '<?php echo get_admin_url() ?>admin-ajax.php',
  1678.                         data: {
  1679.                             action: 'heateor_ss_google_redirection_notification_read'
  1680.                         },
  1681.                         success: function(data, textStatus, XMLHttpRequest){
  1682.                             jQuery('#heateor_ss_google_redirection_notification').fadeOut();
  1683.                         }
  1684.                     });
  1685.                 }
  1686.                 </script>
  1687.                 <div id="heateor_ss_google_redirection_notification" class="error">
  1688.                     <h3>Super Socializer</h3>
  1689.                     <p><?php echo sprintf(__('Add %s in "Authorized redirect URIs" option in your Google client settings for Google login to work. For more details, check step 11 <a href="%s" target="_blank">here</a>', 'super-socializer'), home_url(), 'http://support.heateor.com/how-to-get-google-plus-client-id/'); ?><input type="button" onclick="heateorSsGoogleRedirectionNotificationRead()" style="margin-left: 5px;" class="button button-primary" value="<?php _e('Okay', 'super-socializer') ?>" /></p>
  1690.                 </div>
  1691.                 <?php
  1692.             }
  1693.         }
  1694.  
  1695.         if(!get_option('heateor_ss_browser_notification_read')){
  1696.             ?>
  1697.             <script type="text/javascript">
  1698.             function heateorSsBrowserNotificationRead(){
  1699.                 jQuery.ajax({
  1700.                     type: 'GET',
  1701.                     url: '<?php echo get_admin_url() ?>admin-ajax.php',
  1702.                     data: {
  1703.                         action: 'heateor_ss_browser_notification_read'
  1704.                     },
  1705.                     success: function(data, textStatus, XMLHttpRequest){
  1706.                         jQuery('#heateor_ss_browser_notification').fadeOut();
  1707.                     }
  1708.                 });
  1709.             }
  1710.             </script>
  1711.             <div id="heateor_ss_browser_notification" class="update-nag">
  1712.                 <h3>Super Socializer</h3>
  1713.                 <p><?php echo sprintf(__('Your website visitors will see a popup notification (only once) if their browsers block any of the features of the plugin so that they can change their browser settings to unblock these. You can turn it OFF by disabling "Show popup notification to users if their browsers block the plugin features" option <a href="%s">here</a>', 'super-socializer'), 'admin.php?page=heateor-ss-general-options'); ?><input type="button" onclick="heateorSsBrowserNotificationRead()" style="margin-left: 5px;" class="button button-primary" value="<?php _e('Okay', 'super-socializer') ?>" /></p>
  1714.             </div>
  1715.             <?php
  1716.         }
  1717.     }
  1718. }
  1719. add_action('admin_notices', 'the_champ_addon_update_notification');
  1720.  
  1721. /**
  1722.  * Update options based on plugin version check
  1723.  */
  1724. function the_champ_update_db_check(){
  1725.     $currentVersion = get_option('the_champ_ss_version');
  1726.  
  1727.     if($currentVersion && $currentVersion != THE_CHAMP_SS_VERSION){
  1728.  
  1729.         if(version_compare("7.9", $currentVersion) > 0){
  1730.             global $theChampSharingOptions;
  1731.             $theChampSharingOptions['comment_container_id'] = 'respond';
  1732.             $theChampSharingOptions['vertical_comment_container_id'] = 'respond';
  1733.             update_option('the_champ_sharing', $theChampSharingOptions);
  1734.         }
  1735.  
  1736.         if(version_compare("7.8.22", $currentVersion) > 0){
  1737.             global $theChampSharingOptions;
  1738.             $theChampSharingOptions['bottom_sharing_position_radio'] = 'responsive';
  1739.             update_option('the_champ_sharing', $theChampSharingOptions);
  1740.         }
  1741.  
  1742.         if(version_compare("7.8.14", $currentVersion) > 0){
  1743.             global $theChampLoginOptions;
  1744.             $theChampLoginOptions['link_account'] = '1';
  1745.             update_option('the_champ_login', $theChampLoginOptions);
  1746.         }
  1747.  
  1748.         if(version_compare("7.8.13", $currentVersion) > 0){
  1749.             global $theChampGeneralOptions;
  1750.             $theChampGeneralOptions['browser_msg_enable'] = '1';
  1751.             $theChampGeneralOptions['browser_msg'] = __('Your browser is blocking some features of this website. Please follow the instructions at {support_url} to unblock these.', 'super-socializer');
  1752.             update_option('the_champ_general', $theChampGeneralOptions);
  1753.         }
  1754.  
  1755.         if(version_compare("7.7", $currentVersion) > 0){
  1756.             global $theChampSharingOptions;
  1757.             $theChampSharingOptions['instagram_username'] = '';
  1758.             $theChampSharingOptions['vertical_instagram_username'] = '';
  1759.             update_option('the_champ_sharing', $theChampSharingOptions);
  1760.         }
  1761.        
  1762.         if(version_compare("7.6", $currentVersion) > 0){
  1763.             global $theChampLoginOptions;
  1764.             $theChampLoginOptions['new_user_admin_email'] = '1';
  1765.             update_option('the_champ_login', $theChampLoginOptions);
  1766.         }
  1767.  
  1768.         if(version_compare("6.0", $currentVersion) > 0){
  1769.             global $theChampFacebookOptions;
  1770.             $theChampFacebookOptions['enable_post'] = '1';
  1771.             $theChampFacebookOptions['enable_page'] = '1';
  1772.             update_option('the_champ_facebook', $theChampFacebookOptions);
  1773.         }
  1774.  
  1775.         if(version_compare('7.0', $currentVersion) > 0){
  1776.             global $theChampSharingOptions, $theChampLoginOptions, $theChampGeneralOptions;
  1777.            
  1778.             $theChampSharingOptions['horizontal_re_providers'] = the_champ_replace_array_value($theChampSharingOptions['horizontal_re_providers'], 'google', 'google_plus');
  1779.             $theChampSharingOptions['vertical_re_providers'] = the_champ_replace_array_value($theChampSharingOptions['vertical_re_providers'], 'google', 'google_plus');
  1780.  
  1781.             // general options
  1782.             if(isset($theChampLoginOptions['footer_script'])){
  1783.                 $theChampGeneralOptions['footer_script'] = '1';
  1784.             }
  1785.             if(isset($theChampSharingOptions['delete_options'])){
  1786.                 $theChampGeneralOptions['delete_options'] = '1';
  1787.             }
  1788.  
  1789.             $theChampSharingOptions['horizontal_sharing_width'] = '70';
  1790.             $theChampSharingOptions['horizontal_sharing_height'] = '35';
  1791.             $theChampSharingOptions['horizontal_sharing_height'] = '35';
  1792.             $theChampSharingOptions['horizontal_border_radius'] = '';
  1793.             $theChampSharingOptions['horizontal_font_color_default'] = '';
  1794.             $theChampSharingOptions['horizontal_sharing_replace_color'] = '#fff';
  1795.             $theChampSharingOptions['horizontal_font_color_hover'] = '';
  1796.             $theChampSharingOptions['horizontal_sharing_replace_color_hover'] = '#fff';
  1797.             $theChampSharingOptions['horizontal_bg_color_default'] = '';
  1798.             $theChampSharingOptions['horizontal_bg_color_hover'] = '';
  1799.             $theChampSharingOptions['horizontal_border_width_default'] = '';
  1800.             $theChampSharingOptions['horizontal_border_color_default'] = '';
  1801.             $theChampSharingOptions['horizontal_border_width_hover'] = '';
  1802.             $theChampSharingOptions['horizontal_border_color_hover'] = '';
  1803.             $theChampSharingOptions['vertical_sharing_width'] = '80';
  1804.             $theChampSharingOptions['vertical_sharing_height'] = '40';
  1805.             $theChampSharingOptions['vertical_border_radius'] = '';
  1806.             $theChampSharingOptions['vertical_font_color_default'] = '';
  1807.             $theChampSharingOptions['vertical_sharing_replace_color'] = '#fff';
  1808.             $theChampSharingOptions['vertical_font_color_hover'] = '';
  1809.             $theChampSharingOptions['vertical_sharing_replace_color_hover'] = '#fff';
  1810.             $theChampSharingOptions['vertical_bg_color_default'] = '';
  1811.             $theChampSharingOptions['vertical_bg_color_hover'] = '';
  1812.             $theChampSharingOptions['vertical_border_width_default'] = '';
  1813.             $theChampSharingOptions['vertical_border_color_default'] = '';
  1814.             $theChampSharingOptions['vertical_border_width_hover'] = '';
  1815.             $theChampSharingOptions['vertical_border_color_hover'] = '';
  1816.             $theChampSharingOptions['vertical_screen_width'] = '783';
  1817.             $theChampSharingOptions['horizontal_screen_width'] = '783';
  1818.             $theChampSharingOptions['bottom_sharing_position'] = '0';
  1819.             $theChampSharingOptions['bottom_sharing_alignment'] = 'left';
  1820.             $theChampSharingOptions['buffer_username'] = '';
  1821.             $theChampSharingOptions['language'] = get_locale();
  1822.             $theChampSharingOptions['tweet_count_service'] = 'newsharecounts';
  1823.  
  1824.             $customCss = '';
  1825.             if(isset($theChampSharingOptions['horizontal_counts'])){
  1826.                 $theChampSharingOptions['horizontal_counter_position'] = 'top';
  1827.                 $customCss .= '.the_champ_horizontal_sharing .the_champ_square_count{
  1828.             display:block;
  1829.             text-indent:0!important;
  1830.             visibility:hidden;
  1831.             background-color:#58B8F8!important;
  1832.             width:auto;
  1833.             height:auto;
  1834.             text-align:center;
  1835.             min-width:8px!important;
  1836.             padding:1px 4px!important;
  1837.             color:#fff!important;
  1838.             font-family:\'Open Sans\',arial,sans-serif!important;
  1839.             font-size:10px!important;
  1840.             font-weight:600!important;
  1841.             -webkit-border-radius:15px!important;
  1842.             border-radius:15px!important;
  1843.             -webkit-box-shadow:0 2px 2px rgba(0,0,0,.4);
  1844.             box-shadow:0 2px 2px rgba(0,0,0,.4);
  1845.             text-shadow:0 -1px 0 rgba(0,0,0,.2);
  1846.             line-height:14px!important;
  1847.             border:2px solid #fff!important;
  1848.             z-index:1;
  1849.             margin:2px auto!important;
  1850.             box-sizing:content-box!important
  1851.         }';
  1852.             }
  1853.             if(isset($theChampSharingOptions['vertical_counts'])){
  1854.                 if(!isset($theChampSharingOptions['vertical_sharing_shape']) || $theChampSharingOptions['vertical_sharing_shape'] == 'square'){
  1855.                     $theChampSharingOptions['vertical_counter_position'] = 'inner_top';
  1856.                 }elseif($theChampSharingOptions['vertical_sharing_shape'] == 'round'){
  1857.                     $theChampSharingOptions['vertical_counter_position'] = 'top';
  1858.                     $customCss .= '.the_champ_vertical_sharing .the_champ_square_count{
  1859.             display:block;
  1860.             text-indent:0!important;
  1861.             visibility:hidden;
  1862.             background-color:#58B8F8!important;
  1863.             width:auto;
  1864.             height:auto;
  1865.             text-align:center;
  1866.             min-width:8px!important;
  1867.             padding:1px 4px!important;
  1868.             color:#fff!important;
  1869.             font-family:\'Open Sans\',arial,sans-serif!important;
  1870.             font-size:10px!important;
  1871.             font-weight:600!important;
  1872.             -webkit-border-radius:15px!important;
  1873.             border-radius:15px!important;
  1874.             -webkit-box-shadow:0 2px 2px rgba(0,0,0,.4);
  1875.             box-shadow:0 2px 2px rgba(0,0,0,.4);
  1876.             text-shadow:0 -1px 0 rgba(0,0,0,.2);
  1877.             line-height:14px!important;
  1878.             border:2px solid #fff!important;
  1879.             z-index:1;
  1880.             margin:2px auto!important;
  1881.             box-sizing:content-box!important
  1882.         }';
  1883.                 }
  1884.             }
  1885.             $theChampGeneralOptions['custom_css'] = $customCss;
  1886.  
  1887.             update_option('the_champ_sharing', $theChampSharingOptions);
  1888.             update_option('the_champ_general', $theChampGeneralOptions);
  1889.         }
  1890.  
  1891.         if(version_compare($currentVersion, '6.9') > 0){
  1892.             global $theChampSharingOptions;
  1893.             if ( $theChampSharingOptions['horizontal_sharing_replace_color'] != '#fff' ) {
  1894.                 the_champ_update_svg_css( $theChampSharingOptions['horizontal_sharing_replace_color'], 'share-default-svg-horizontal' );
  1895.             }
  1896.             if ( $theChampSharingOptions['horizontal_sharing_replace_color_hover'] != '#fff' ) {
  1897.                 the_champ_update_svg_css( $theChampSharingOptions['horizontal_sharing_replace_color_hover'], 'share-hover-svg-horizontal' );
  1898.             }
  1899.             if ( $theChampSharingOptions['vertical_sharing_replace_color'] != '#fff' ) {
  1900.                 the_champ_update_svg_css( $theChampSharingOptions['vertical_sharing_replace_color'], 'share-default-svg-vertical' );
  1901.             }
  1902.             if ( $theChampSharingOptions['vertical_sharing_replace_color_hover'] != '#fff' ) {
  1903.                 the_champ_update_svg_css( $theChampSharingOptions['vertical_sharing_replace_color_hover'], 'share-hover-svg-vertical' );
  1904.             }
  1905.         }
  1906.  
  1907.         if(version_compare('7.2', $currentVersion) > 0){
  1908.             $theChampSharingOptions['share_count_cache_refresh_count'] = '10';
  1909.             $theChampSharingOptions['share_count_cache_refresh_unit'] = 'minutes';
  1910.             update_option('the_champ_sharing', $theChampSharingOptions);
  1911.         }
  1912.  
  1913.         update_option('the_champ_ss_version', THE_CHAMP_SS_VERSION);
  1914.     }
  1915. }
  1916. add_action('plugins_loaded', 'the_champ_update_db_check');
  1917.  
  1918. /**
  1919.  * Updates SVG CSS file according to chosen logo color
  1920.  */
  1921. function the_champ_update_svg_css( $colorToBeReplaced, $cssFile ) {
  1922.     $path = plugin_dir_url( __FILE__ ) . 'css/' . $cssFile . '.css';
  1923.     try{
  1924.         $content = file( $path );
  1925.         if ( $content !== false ) {
  1926.             $handle = fopen( dirname( __FILE__ ) . '/css/' . $cssFile . '.css','w' );
  1927.             if ( $handle !== false ) {
  1928.                 foreach ( $content as $value ) {
  1929.                     fwrite( $handle, str_replace( '%23fff', str_replace( '#', '%23', $colorToBeReplaced ), $value ) );
  1930.                 }
  1931.                 fclose( $handle );
  1932.             }
  1933.         }
  1934.     }catch(Exception $e){}
  1935. }
  1936.  
  1937. /**
  1938.  * CSS to load at front end for AMP
  1939.  */
  1940. function the_champ_frontend_amp_css(){
  1941.     global $theChampSharingOptions;
  1942.     // background color of amp icons
  1943.     $css = 'a.heateor_ss_amp{padding:0 4px;}div.heateor_ss_horizontal_sharing a amp-img{display:inline-block;margin:0 4px;}.heateor_ss_amp_instagram img{background-color:#624E47}.heateor_ss_amp_yummly img{background-color:#E16120}.heateor_ss_amp_buffer img{background-color:#000}.heateor_ss_amp_delicious img{background-color:#53BEEE}.heateor_ss_amp_facebook img{background-color:#3C589A}.heateor_ss_amp_digg img{background-color:#006094}.heateor_ss_amp_email img{background-color:#649A3F}.heateor_ss_amp_float_it img{background-color:#53BEEE}.heateor_ss_amp_google img{background-color:#dd4b39}.heateor_ss_amp_google_plus img{background-color:#dd4b39}.heateor_ss_amp_linkedin img{background-color:#0077B5}.heateor_ss_amp_pinterest img{background-color:#CC2329}.heateor_ss_amp_print img{background-color:#FD6500}.heateor_ss_amp_reddit img{background-color:#247CED}.heateor_ss_amp_stocktwits img{background-color: #40576F}.heateor_ss_amp_stumbleupon img{background-color:#EA4823}.heateor_ss_amp_tumblr img{background-color:#29435D}.heateor_ss_amp_twitter img{background-color:#55acee}.heateor_ss_amp_vkontakte img{background-color:#5E84AC}.heateor_ss_amp_yahoo img{background-color:#8F03CC}.heateor_ss_amp_xing img{background-color:#00797D}.heateor_ss_amp_instagram img{background-color:#527FA4}.heateor_ss_amp_whatsapp img{background-color:#55EB4C}.heateor_ss_amp_aim img{background-color: #10ff00}.heateor_ss_amp_amazon_wish_list img{background-color: #ffe000}.heateor_ss_amp_aol_mail img{background-color: #2A2A2A}.heateor_ss_amp_app_net img{background-color: #5D5D5D}.heateor_ss_amp_baidu img{background-color: #2319DC}.heateor_ss_amp_balatarin img{background-color: #fff}.heateor_ss_amp_bibsonomy img{background-color: #000}.heateor_ss_amp_bitty_browser img{background-color: #EFEFEF}.heateor_ss_amp_blinklist img{background-color: #3D3C3B}.heateor_ss_amp_blogger_post img{background-color: #FDA352}.heateor_ss_amp_blogmarks img{background-color: #535353}.heateor_ss_amp_bookmarks_fr img{background-color: #E8EAD4}.heateor_ss_amp_box_net img{background-color: #1A74B0}.heateor_ss_amp_buddymarks img{background-color: #ffd400}.heateor_ss_amp_care2_news img{background-color: #6EB43F}.heateor_ss_amp_citeulike img{background-color: #2781CD}.heateor_ss_amp_comment img{background-color: #444}.heateor_ss_amp_diary_ru img{background-color: #E8D8C6}.heateor_ss_amp_diaspora img{background-color: #2E3436}.heateor_ss_amp_dihitt img{background-color: #FF6300}.heateor_ss_amp_diigo img{background-color: #4A8BCA}.heateor_ss_amp_douban img{background-color: #497700}.heateor_ss_amp_draugiem img{background-color: #ffad66}.heateor_ss_amp_dzone img{background-color: #fff088}.heateor_ss_amp_evernote img{background-color: #8BE056}.heateor_ss_amp_facebook_messenger img{background-color: #0084FF}.heateor_ss_amp_fark img{background-color: #555}.heateor_ss_amp_flipboard img{background-color: #CC0000}.heateor_ss_amp_folkd img{background-color: #0F70B2}.heateor_ss_amp_google_classroom img{background-color: #FFC112}.heateor_ss_amp_google_bookmarks img{background-color: #CB0909}.heateor_ss_amp_google_gmail img{background-color: #E5E5E5}.heateor_ss_amp_hacker_news img{background-color: #F60}.heateor_ss_amp_hatena img{background-color: #00A6DB}.heateor_ss_amp_instapaper img{background-color: #EDEDED}.heateor_ss_amp_jamespot img{background-color: #FF9E2C}.heateor_ss_amp_kakao img{background-color: #FCB700}.heateor_ss_amp_kik img{background-color: #2A2A2A}.heateor_ss_amp_kindle_it img{background-color: #2A2A2A}.heateor_ss_amp_known img{background-color: #fff101}.heateor_ss_amp_line img{background-color: #00C300}.heateor_ss_amp_livejournal img{background-color: #EDEDED}.heateor_ss_amp_mail_ru img{background-color: #356FAC}.heateor_ss_amp_mendeley img{background-color: #A70805}.heateor_ss_amp_meneame img{background-color: #FF7D12}.heateor_ss_amp_mixi img{background-color: #EDEDED}.heateor_ss_amp_myspace img{background-color: #2A2A2A}.heateor_ss_amp_netlog img{background-color: #2A2A2A}.heateor_ss_amp_netvouz img{background-color: #c0ff00}.heateor_ss_amp_newsvine img{background-color: #055D00}.heateor_ss_amp_nujij img{background-color: #D40000}.heateor_ss_amp_odnoklassniki img{background-color: #F2720C}.heateor_ss_amp_oknotizie img{background-color: #fdff88}.heateor_ss_amp_outlook_com img{background-color: #0072C6}.heateor_ss_amp_papaly img{background-color: #3AC0F6}.heateor_ss_amp_pinboard img{background-color: #1341DE}.heateor_ss_amp_plurk img{background-color: #CF682F}.heateor_ss_amp_pocket img{background-color: #f0f0f0}.heateor_ss_amp_polyvore img{background-color: #2A2A2A}.heateor_ss_amp_printfriendly img{background-color: #61D1D5}.heateor_ss_amp_protopage_bookmarks img{background-color: #413FFF}.heateor_ss_amp_pusha img{background-color: #0072B8}.heateor_ss_amp_qzone img{background-color: #2B82D9}.heateor_ss_amp_refind img{background-color: #1492ef}.heateor_ss_amp_rediff_mypage img{background-color: #D20000}.heateor_ss_amp_renren img{background-color: #005EAC}.heateor_ss_amp_segnalo img{background-color: #fdff88}.heateor_ss_amp_sina_weibo img{background-color: #ff0}.heateor_ss_amp_sitejot img{background-color: #ffc800}.heateor_ss_amp_skype img{background-color: #00AFF0}.heateor_ss_amp_sms img{background-color: #6ebe45}.heateor_ss_amp_slashdot img{background-color: #004242}.heateor_ss_amp_stumpedia img{background-color: #EDEDED}.heateor_ss_amp_svejo img{background-color: #fa7aa3}.heateor_ss_amp_symbaloo_feeds img{background-color: #6DA8F7}.heateor_ss_amp_telegram img{background-color: #3DA5f1}.heateor_ss_amp_trello img{background-color: #1189CE}.heateor_ss_amp_tuenti img{background-color: #0075C9}.heateor_ss_amp_twiddla img{background-color: #EDEDED}.heateor_ss_amp_typepad_post img{background-color: #2A2A2A}.heateor_ss_amp_viadeo img{background-color: #2A2A2A}.heateor_ss_amp_viber img{background-color: #8B628F}.heateor_ss_amp_wanelo img{background-color: #fff}.heateor_ss_amp_webnews img{background-color: #CC2512}.heateor_ss_amp_wordpress img{background-color: #464646}.heateor_ss_amp_wykop img{background-color: #367DA9}.heateor_ss_amp_yahoo_mail img{background-color: #400090}.heateor_ss_amp_yahoo_messenger img{background-color: #400090}.heateor_ss_amp_yoolink img{background-color: #A2C538}.heateor_ss_amp_youmob img{background-color: #3B599D}';
  1944.  
  1945.     // css for horizontal sharing bar
  1946.     if ( $theChampSharingOptions['horizontal_sharing_shape'] == 'round' ) {
  1947.         $css .= '.heateor_ss_amp amp-img{border-radius:999px;}';
  1948.     } elseif ( $theChampSharingOptions['horizontal_border_radius'] != '' ) {
  1949.         $css .= '.heateor_ss_amp amp-img{border-radius:' . $this->options['horizontal_border_radius'] . 'px;}';
  1950.     }
  1951.  
  1952.     echo $css;
  1953. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement