<?php

/* unserialize all saved option for  section 4 options */
$option4 = unserialize(get_option('sfsi_section4_options', false));
$option2 = unserialize(get_option('sfsi_section2_options', false));
$counts = sfsi_getCounts();
/* fetch counts for admin sections */
/* check for email icon display */
$email_image = "email.png";
if ($option2['sfsi_rss_icons'] == "sfsi") {
    $email_image = "sf_arow_icn.png";
}
$hide = "display:none;";
?>
<!-- Section 4 "Do you want to display "counts" next to your icons?" main div Start -->
<div class="tab4">
  <p>It’s a psychological fact that people like to follow other people (as explained well in Robert Cialdini’s book “<a href="http://www.amazon.com/Influence-Psychology-Persuasion-Revised-Edition/dp/006124189X" target="_blank" class="lit_txt">Influence</a>”), so when they see that your site has already a good number of Facebook likes, it’s more likely that they will subscribe/like/share your site than if it had 0. </p>
  <p>Therefore, you can select to display the count next to your icons, which will look like this:</p>
	<!-- sample icons --> 
	<ul class="like_icon">
        <li class="rss_section"><a href="#" title="RSS"><img src="<?php 
echo SFSI_PLUGURL;
?>
images/rss.png" alt="RSS" /></a><span>12k</span></li>
        <li class="email_section"><a href="#" title="Email"><img src="<?php 
echo SFSI_PLUGURL;
?>
images/<?php 
echo $email_image;
?>
" alt="Email" class="icon_img" /></a><span>12k</span></li>
function sfsi_options_updater4()
{
    $sfsi_display_counts = isset($_POST["sfsi_display_counts"]) ? $_POST["sfsi_display_counts"] : 'no';
    $sfsi_email_countsDisplay = isset($_POST["sfsi_email_countsDisplay"]) ? $_POST["sfsi_email_countsDisplay"] : 'no';
    $sfsi_email_countsFrom = isset($_POST["sfsi_email_countsFrom"]) ? $_POST["sfsi_email_countsFrom"] : 'manual';
    $sfsi_email_manualCounts = isset($_POST["sfsi_email_manualCounts"]) ? trim($_POST["sfsi_email_manualCounts"]) : '';
    $sfsi_rss_countsDisplay = isset($_POST["sfsi_rss_countsDisplay"]) ? $_POST["sfsi_rss_countsDisplay"] : 'no';
    $sfsi_rss_manualCounts = isset($_POST["sfsi_rss_manualCounts"]) ? trim($_POST["sfsi_rss_manualCounts"]) : '';
    $sfsi_facebook_countsDisplay = isset($_POST["sfsi_facebook_countsDisplay"]) ? $_POST["sfsi_facebook_countsDisplay"] : 'no';
    $sfsi_facebook_countsFrom = isset($_POST["sfsi_facebook_countsFrom"]) ? $_POST["sfsi_facebook_countsFrom"] : 'manual';
    $sfsi_facebook_manualCounts = isset($_POST["sfsi_facebook_manualCounts"]) ? trim($_POST["sfsi_facebook_manualCounts"]) : '';
    $sfsi_facebook_PageLink = isset($_POST["sfsi_facebook_PageLink"]) ? trim($_POST["sfsi_facebook_PageLink"]) : '';
    $sfsi_twitter_countsDisplay = isset($_POST["sfsi_twitter_countsDisplay"]) ? $_POST["sfsi_twitter_countsDisplay"] : 'no';
    $sfsi_twitter_countsFrom = isset($_POST["sfsi_twitter_countsFrom"]) ? $_POST["sfsi_twitter_countsFrom"] : 'manual';
    $sfsi_twitter_manualCounts = isset($_POST["sfsi_twitter_manualCounts"]) ? trim($_POST["sfsi_twitter_manualCounts"]) : '';
    $tw_consumer_key = isset($_POST["tw_consumer_key"]) ? trim($_POST["tw_consumer_key"]) : '';
    $tw_consumer_secret = isset($_POST["tw_consumer_secret"]) ? trim($_POST["tw_consumer_secret"]) : '';
    $tw_oauth_access_token = isset($_POST["tw_oauth_access_token"]) ? trim($_POST["tw_oauth_access_token"]) : '';
    $tw_oauth_access_token_secret = isset($_POST["tw_oauth_access_token_secret"]) ? trim($_POST["tw_oauth_access_token_secret"]) : '';
    $sfsi_google_countsDisplay = isset($_POST["sfsi_google_countsDisplay"]) ? $_POST["sfsi_google_countsDisplay"] : 'no';
    $sfsi_google_countsFrom = isset($_POST["sfsi_google_countsFrom"]) ? $_POST["sfsi_google_countsFrom"] : 'manual';
    $sfsi_google_manualCounts = isset($_POST["sfsi_google_manualCounts"]) ? trim($_POST["sfsi_google_manualCounts"]) : '';
    $sfsi_google_api_key = isset($_POST["sfsi_google_api_key"]) ? trim($_POST["sfsi_google_api_key"]) : '';
    $sfsi_linkedIn_countsDisplay = isset($_POST["sfsi_linkedIn_countsDisplay"]) ? $_POST["sfsi_linkedIn_countsDisplay"] : 'no';
    $sfsi_linkedIn_countsFrom = isset($_POST["sfsi_linkedIn_countsFrom"]) ? $_POST["sfsi_linkedIn_countsFrom"] : 'manual';
    $sfsi_linkedIn_manualCounts = isset($_POST["sfsi_linkedIn_manualCounts"]) ? trim($_POST["sfsi_linkedIn_manualCounts"]) : '';
    $ln_company = isset($_POST["ln_company"]) ? trim($_POST["ln_company"]) : '';
    $ln_api_key = isset($_POST["ln_api_key"]) ? trim($_POST["ln_api_key"]) : '';
    $ln_secret_key = isset($_POST["ln_secret_key"]) ? trim($_POST["ln_secret_key"]) : '';
    $ln_oAuth_user_token = isset($_POST["ln_oAuth_user_token"]) ? trim($_POST["ln_oAuth_user_token"]) : '';
    $sfsi_youtube_countsDisplay = isset($_POST["sfsi_youtube_countsDisplay"]) ? $_POST["sfsi_youtube_countsDisplay"] : 'no';
    $sfsi_youtube_countsFrom = isset($_POST["sfsi_youtube_countsFrom"]) ? $_POST["sfsi_youtube_countsFrom"] : 'manual';
    $sfsi_youtube_manualCounts = isset($_POST["sfsi_youtube_manualCounts"]) ? $_POST["sfsi_youtube_manualCounts"] : '';
    $sfsi_youtube_user = isset($_POST["sfsi_youtube_user"]) ? trim($_POST["sfsi_youtube_user"]) : '';
    $sfsi_pinterest_countsDisplay = isset($_POST["sfsi_pinterest_countsDisplay"]) ? $_POST["sfsi_pinterest_countsDisplay"] : 'no';
    $sfsi_pinterest_countsFrom = isset($_POST["sfsi_pinterest_countsFrom"]) ? $_POST["sfsi_pinterest_countsFrom"] : 'manual';
    $sfsi_pinterest_manualCounts = isset($_POST["sfsi_pinterest_manualCounts"]) ? trim($_POST["sfsi_pinterest_manualCounts"]) : '';
    $sfsi_pinterest_user = isset($_POST["sfsi_pinterest_user"]) ? trim($_POST["sfsi_pinterest_user"]) : '';
    $sfsi_pinterest_board = isset($_POST["sfsi_pinterest_board"]) ? trim($_POST["sfsi_pinterest_board"]) : '';
    $sfsi_instagram_countsDisplay = isset($_POST["sfsi_instagram_countsDisplay"]) ? $_POST["sfsi_instagram_countsDisplay"] : 'no';
    $sfsi_instagram_countsFrom = isset($_POST["sfsi_instagram_countsFrom"]) ? $_POST["sfsi_instagram_countsFrom"] : 'manual';
    $sfsi_instagram_manualCounts = isset($_POST["sfsi_instagram_manualCounts"]) ? trim($_POST["sfsi_instagram_manualCounts"]) : '';
    $sfsi_instagram_User = isset($_POST["sfsi_instagram_User"]) ? $_POST["sfsi_instagram_User"] : '';
    $sfsi_shares_countsDisplay = isset($_POST["sfsi_shares_countsDisplay"]) ? $_POST["sfsi_shares_countsDisplay"] : 'no';
    $sfsi_shares_countsFrom = isset($_POST["sfsi_shares_countsFrom"]) ? $_POST["sfsi_shares_countsFrom"] : 'manual';
    $sfsi_shares_manualCounts = isset($_POST["sfsi_shares_manualCounts"]) ? trim($_POST["sfsi_shares_manualCounts"]) : '';
    $sfsi_facebookPage_url = isset($_POST["sfsi_facebookPage_url"]) ? trim($_POST["sfsi_facebookPage_url"]) : '';
    $up_option4 = array('sfsi_display_counts' => $sfsi_display_counts, 'sfsi_email_countsDisplay' => $sfsi_email_countsDisplay, 'sfsi_email_countsFrom' => $sfsi_email_countsFrom, 'sfsi_email_manualCounts' => $sfsi_email_manualCounts, 'sfsi_rss_countsDisplay' => $sfsi_rss_countsDisplay, 'sfsi_rss_manualCounts' => $sfsi_rss_manualCounts, 'sfsi_facebook_countsDisplay' => $sfsi_facebook_countsDisplay, 'sfsi_facebook_countsFrom' => $sfsi_facebook_countsFrom, 'sfsi_facebook_manualCounts' => $sfsi_facebook_manualCounts, 'sfsi_twitter_countsDisplay' => $sfsi_twitter_countsDisplay, 'sfsi_twitter_countsFrom' => $sfsi_twitter_countsFrom, 'sfsi_twitter_manualCounts' => $sfsi_twitter_manualCounts, 'tw_consumer_key' => $tw_consumer_key, 'tw_consumer_secret' => $tw_consumer_secret, 'tw_oauth_access_token' => $tw_oauth_access_token, 'tw_oauth_access_token_secret' => $tw_oauth_access_token_secret, 'sfsi_google_countsDisplay' => $sfsi_google_countsDisplay, 'sfsi_google_countsFrom' => $sfsi_google_countsFrom, 'sfsi_google_manualCounts' => $sfsi_google_manualCounts, 'sfsi_google_api_key' => $sfsi_google_api_key, 'ln_company' => $ln_company, 'ln_api_key' => $ln_api_key, 'ln_secret_key' => $ln_secret_key, 'ln_oAuth_user_token' => $ln_oAuth_user_token, 'sfsi_linkedIn_countsDisplay' => $sfsi_linkedIn_countsDisplay, 'sfsi_linkedIn_countsFrom' => $sfsi_linkedIn_countsFrom, 'sfsi_linkedIn_manualCounts' => $sfsi_linkedIn_manualCounts, 'sfsi_youtube_countsDisplay' => $sfsi_youtube_countsDisplay, 'sfsi_youtube_countsFrom' => $sfsi_youtube_countsFrom, 'sfsi_youtube_manualCounts' => $sfsi_youtube_manualCounts, 'sfsi_youtube_user' => $sfsi_youtube_user, 'sfsi_pinterest_countsDisplay' => $sfsi_pinterest_countsDisplay, 'sfsi_pinterest_countsFrom' => $sfsi_pinterest_countsFrom, 'sfsi_pinterest_manualCounts' => $sfsi_pinterest_manualCounts, 'sfsi_pinterest_user' => $sfsi_pinterest_user, 'sfsi_pinterest_board' => $sfsi_pinterest_board, 'sfsi_instagram_countsFrom' => $sfsi_instagram_countsFrom, 'sfsi_instagram_countsDisplay' => $sfsi_instagram_countsDisplay, 'sfsi_instagram_manualCounts' => $sfsi_instagram_manualCounts, 'sfsi_instagram_User' => $sfsi_instagram_User, 'sfsi_shares_countsDisplay' => $sfsi_shares_countsDisplay, 'sfsi_shares_countsFrom' => $sfsi_shares_countsFrom, 'sfsi_shares_manualCounts' => $sfsi_shares_manualCounts);
    update_option('sfsi_section4_options', serialize($up_option4));
    //$option2=unserialize(get_option('sfsi_section2_options',false));
    //$option2['sfsi_facebookPage_url']=$sfsi_facebook_PageLink;
    //update_option('sfsi_section2_options',serialize($option2));
    $new_counts = sfsi_getCounts();
    header('Content-Type: application/json');
    echo json_encode(array("res" => "success", 'counts' => $new_counts));
    exit;
}
function sfsi_options_updater4()
{
    if (!wp_verify_nonce($_POST['nonce'], "update_step4")) {
        echo json_encode(array("wrong_nonce"));
        exit;
    }
    $sfsi_display_counts = isset($_POST["sfsi_display_counts"]) ? $_POST["sfsi_display_counts"] : 'no';
    $sfsi_email_countsDisplay = isset($_POST["sfsi_email_countsDisplay"]) ? $_POST["sfsi_email_countsDisplay"] : 'no';
    $sfsi_email_countsFrom = isset($_POST["sfsi_email_countsFrom"]) ? $_POST["sfsi_email_countsFrom"] : 'manual';
    $sfsi_email_manualCounts = isset($_POST["sfsi_email_manualCounts"]) ? trim($_POST["sfsi_email_manualCounts"]) : '';
    $sfsi_rss_countsDisplay = isset($_POST["sfsi_rss_countsDisplay"]) ? $_POST["sfsi_rss_countsDisplay"] : 'no';
    $sfsi_rss_manualCounts = isset($_POST["sfsi_rss_manualCounts"]) ? trim($_POST["sfsi_rss_manualCounts"]) : '';
    $sfsi_facebook_countsDisplay = isset($_POST["sfsi_facebook_countsDisplay"]) ? $_POST["sfsi_facebook_countsDisplay"] : 'no';
    $sfsi_facebook_countsFrom = isset($_POST["sfsi_facebook_countsFrom"]) ? $_POST["sfsi_facebook_countsFrom"] : 'manual';
    $sfsi_facebook_mypageCounts = isset($_POST["sfsi_facebook_mypageCounts"]) ? trim($_POST["sfsi_facebook_mypageCounts"]) : '';
    $sfsi_facebook_manualCounts = isset($_POST["sfsi_facebook_manualCounts"]) ? trim($_POST["sfsi_facebook_manualCounts"]) : '';
    $sfsi_facebook_PageLink = isset($_POST["sfsi_facebook_PageLink"]) ? trim($_POST["sfsi_facebook_PageLink"]) : '';
    $sfsi_twitter_countsDisplay = isset($_POST["sfsi_twitter_countsDisplay"]) ? $_POST["sfsi_twitter_countsDisplay"] : 'no';
    $sfsi_twitter_countsFrom = isset($_POST["sfsi_twitter_countsFrom"]) ? $_POST["sfsi_twitter_countsFrom"] : 'manual';
    $sfsi_twitter_manualCounts = isset($_POST["sfsi_twitter_manualCounts"]) ? trim($_POST["sfsi_twitter_manualCounts"]) : '';
    $tw_consumer_key = isset($_POST["tw_consumer_key"]) ? trim($_POST["tw_consumer_key"]) : '';
    $tw_consumer_secret = isset($_POST["tw_consumer_secret"]) ? trim($_POST["tw_consumer_secret"]) : '';
    $tw_oauth_access_token = isset($_POST["tw_oauth_access_token"]) ? trim($_POST["tw_oauth_access_token"]) : '';
    $tw_oauth_access_token_secret = isset($_POST["tw_oauth_access_token_secret"]) ? trim($_POST["tw_oauth_access_token_secret"]) : '';
    $sfsi_google_countsDisplay = isset($_POST["sfsi_google_countsDisplay"]) ? $_POST["sfsi_google_countsDisplay"] : 'no';
    $sfsi_google_countsFrom = isset($_POST["sfsi_google_countsFrom"]) ? $_POST["sfsi_google_countsFrom"] : 'manual';
    $sfsi_google_manualCounts = isset($_POST["sfsi_google_manualCounts"]) ? trim($_POST["sfsi_google_manualCounts"]) : '';
    $sfsi_google_api_key = isset($_POST["sfsi_google_api_key"]) ? trim($_POST["sfsi_google_api_key"]) : '';
    $sfsi_linkedIn_countsDisplay = isset($_POST["sfsi_linkedIn_countsDisplay"]) ? $_POST["sfsi_linkedIn_countsDisplay"] : 'no';
    $sfsi_linkedIn_countsFrom = isset($_POST["sfsi_linkedIn_countsFrom"]) ? $_POST["sfsi_linkedIn_countsFrom"] : 'manual';
    $sfsi_linkedIn_manualCounts = isset($_POST["sfsi_linkedIn_manualCounts"]) ? trim($_POST["sfsi_linkedIn_manualCounts"]) : '';
    $ln_company = isset($_POST["ln_company"]) ? trim($_POST["ln_company"]) : '';
    $ln_api_key = isset($_POST["ln_api_key"]) ? trim($_POST["ln_api_key"]) : '';
    $ln_secret_key = isset($_POST["ln_secret_key"]) ? trim($_POST["ln_secret_key"]) : '';
    $ln_oAuth_user_token = isset($_POST["ln_oAuth_user_token"]) ? trim($_POST["ln_oAuth_user_token"]) : '';
    $sfsi_youtube_countsDisplay = isset($_POST["sfsi_youtube_countsDisplay"]) ? $_POST["sfsi_youtube_countsDisplay"] : 'no';
    $sfsi_youtube_countsFrom = isset($_POST["sfsi_youtube_countsFrom"]) ? $_POST["sfsi_youtube_countsFrom"] : 'manual';
    $sfsi_youtube_manualCounts = isset($_POST["sfsi_youtube_manualCounts"]) ? $_POST["sfsi_youtube_manualCounts"] : '';
    $sfsi_youtube_user = isset($_POST["sfsi_youtube_user"]) ? trim($_POST["sfsi_youtube_user"]) : '';
    $sfsi_youtube_channelId = isset($_POST["sfsi_youtube_channelId"]) ? trim($_POST["sfsi_youtube_channelId"]) : '';
    $sfsi_pinterest_countsDisplay = isset($_POST["sfsi_pinterest_countsDisplay"]) ? $_POST["sfsi_pinterest_countsDisplay"] : 'no';
    $sfsi_pinterest_countsFrom = isset($_POST["sfsi_pinterest_countsFrom"]) ? $_POST["sfsi_pinterest_countsFrom"] : 'manual';
    $sfsi_pinterest_manualCounts = isset($_POST["sfsi_pinterest_manualCounts"]) ? trim($_POST["sfsi_pinterest_manualCounts"]) : '';
    $sfsi_pinterest_user = isset($_POST["sfsi_pinterest_user"]) ? trim($_POST["sfsi_pinterest_user"]) : '';
    $sfsi_pinterest_board = isset($_POST["sfsi_pinterest_board"]) ? trim($_POST["sfsi_pinterest_board"]) : '';
    $sfsi_instagram_countsDisplay = isset($_POST["sfsi_instagram_countsDisplay"]) ? $_POST["sfsi_instagram_countsDisplay"] : 'no';
    $sfsi_instagram_countsFrom = isset($_POST["sfsi_instagram_countsFrom"]) ? $_POST["sfsi_instagram_countsFrom"] : 'manual';
    $sfsi_instagram_manualCounts = isset($_POST["sfsi_instagram_manualCounts"]) ? trim($_POST["sfsi_instagram_manualCounts"]) : '';
    $sfsi_instagram_User = isset($_POST["sfsi_instagram_User"]) ? $_POST["sfsi_instagram_User"] : '';
    $sfsi_shares_countsDisplay = isset($_POST["sfsi_shares_countsDisplay"]) ? $_POST["sfsi_shares_countsDisplay"] : 'no';
    $sfsi_shares_countsFrom = isset($_POST["sfsi_shares_countsFrom"]) ? $_POST["sfsi_shares_countsFrom"] : 'manual';
    $sfsi_shares_manualCounts = isset($_POST["sfsi_shares_manualCounts"]) ? trim($_POST["sfsi_shares_manualCounts"]) : '';
    $sfsi_facebookPage_url = isset($_POST["sfsi_facebookPage_url"]) ? trim($_POST["sfsi_facebookPage_url"]) : '';
    $up_option4 = array('sfsi_display_counts' => sanitize_text_field($sfsi_display_counts), 'sfsi_email_countsDisplay' => sanitize_text_field($sfsi_email_countsDisplay), 'sfsi_email_countsFrom' => sanitize_text_field($sfsi_email_countsFrom), 'sfsi_email_manualCounts' => intval($sfsi_email_manualCounts), 'sfsi_rss_countsDisplay' => sanitize_text_field($sfsi_rss_countsDisplay), 'sfsi_rss_manualCounts' => intval($sfsi_rss_manualCounts), 'sfsi_facebook_countsDisplay' => sanitize_text_field($sfsi_facebook_countsDisplay), 'sfsi_facebook_countsFrom' => sanitize_text_field($sfsi_facebook_countsFrom), 'sfsi_facebook_mypageCounts' => sfsi_sanitize_field($sfsi_facebook_mypageCounts), 'sfsi_facebook_manualCounts' => intval($sfsi_facebook_manualCounts), 'sfsi_twitter_countsDisplay' => sanitize_text_field($sfsi_twitter_countsDisplay), 'sfsi_twitter_countsFrom' => sanitize_text_field($sfsi_twitter_countsFrom), 'sfsi_twitter_manualCounts' => intval($sfsi_twitter_manualCounts), 'tw_consumer_key' => sfsi_sanitize_field($tw_consumer_key), 'tw_consumer_secret' => sfsi_sanitize_field($tw_consumer_secret), 'tw_oauth_access_token' => sfsi_sanitize_field($tw_oauth_access_token), 'tw_oauth_access_token_secret' => sfsi_sanitize_field($tw_oauth_access_token_secret), 'sfsi_google_countsDisplay' => sanitize_text_field($sfsi_google_countsDisplay), 'sfsi_google_countsFrom' => sanitize_text_field($sfsi_google_countsFrom), 'sfsi_google_manualCounts' => intval($sfsi_google_manualCounts), 'sfsi_google_api_key' => sfsi_sanitize_field($sfsi_google_api_key), 'sfsi_linkedIn_countsDisplay' => sanitize_text_field($sfsi_linkedIn_countsDisplay), 'sfsi_linkedIn_countsFrom' => sanitize_text_field($sfsi_linkedIn_countsFrom), 'sfsi_linkedIn_manualCounts' => intval($sfsi_linkedIn_manualCounts), 'sfsi_youtube_countsDisplay' => sanitize_text_field($sfsi_youtube_countsDisplay), 'sfsi_youtube_countsFrom' => sanitize_text_field($sfsi_youtube_countsFrom), 'sfsi_youtube_manualCounts' => intval($sfsi_youtube_manualCounts), 'sfsi_youtube_user' => sfsi_sanitize_field($sfsi_youtube_user), 'sfsi_youtube_channelId' => sfsi_sanitize_field($sfsi_youtube_channelId), 'sfsi_pinterest_countsDisplay' => sanitize_text_field($sfsi_pinterest_countsDisplay), 'sfsi_pinterest_countsFrom' => sanitize_text_field($sfsi_pinterest_countsFrom), 'sfsi_pinterest_manualCounts' => intval($sfsi_pinterest_manualCounts), 'sfsi_instagram_countsFrom' => sanitize_text_field($sfsi_instagram_countsFrom), 'sfsi_instagram_countsDisplay' => sanitize_text_field($sfsi_instagram_countsDisplay), 'sfsi_instagram_manualCounts' => intval($sfsi_instagram_manualCounts), 'sfsi_instagram_User' => sanitize_text_field($sfsi_instagram_User), 'sfsi_shares_countsDisplay' => sanitize_text_field($sfsi_shares_countsDisplay), 'sfsi_shares_countsFrom' => sanitize_text_field($sfsi_shares_countsFrom), 'sfsi_shares_manualCounts' => intval($sfsi_shares_manualCounts));
    update_option('sfsi_section4_options', serialize($up_option4));
    $new_counts = sfsi_getCounts();
    header('Content-Type: application/json');
    echo json_encode(array("res" => "success", 'counts' => $new_counts));
    exit;
}