Example #1
0
function kc_social_share($source)
{
    //GET ARRAY OF STORED VALUES
    $option = twitter_facebook_share_get_options_stored();
    if (empty($option['bkcolor_value'])) {
        $option['bkcolor_value'] = '#F0F4F9';
    }
    $border = '';
    if ($option['border'] == 'flat') {
        $border = 'border:1px solid #808080;';
    } else {
        if ($option['border'] == 'round') {
            $border = 'border:1px solid #808080; border-radius:5px 5px 5px 5px; box-shadow:2px 2px 5px rgba(0,0,0,0.3);';
        }
    }
    if ($option['bkcolor'] == true) {
        $bkcolor = 'background-color:' . $option['bkcolor_value'] . ';';
    } else {
        $bkcolor = '';
    }
    $post_link = get_permalink();
    $post_title = get_the_title();
    if ($option['position'] == 'left' && (!is_single() && !is_page())) {
        if ($source != 'manual' || $source != 'shortcode') {
            $option['position'] = 'above';
        }
    }
    if ($option['position'] == 'left') {
        $output = '<div id="leftcontainerBox" style="' . $border . $bkcolor . 'position:' . $option['float_position'] . '; top:' . $option['bottom_space'] . '; left:' . $option['left_space'] . ';">';
        if ($option['active_buttons']['facebook_like'] == true) {
            $output .= '
			<div class="buttons">
			<iframe src="http://www.facebook.com/plugins/like.php?href=' . urlencode($post_link) . '&amp;layout=box_count&amp;show_faces=false&amp;action=like&amp;font=verdana&amp;colorscheme=light" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:60px;" allowTransparency="true"></iframe>
			</div>';
        }
        if ($option['active_buttons']['twitter'] == true) {
            if ($option['twitter_id'] != '') {
                $output .= '
			<div class="buttons">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $post_link . '"  data-text="' . $post_title . '" data-count="vertical" data-via="' . $option['twitter_id'] . '">Tweet</a>
			</div>';
            } else {
                $output .= '
			<div class="buttons">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $post_link . '"  data-text="' . $post_title . '" data-count="vertical">Tweet</a>
			</div>';
            }
        }
        if ($option['active_buttons']['Google_plusone'] == true) {
            $output .= '
			<div class="buttons">
			<g:plusone size="tall" href="' . $post_link . '"></g:plusone>
			</div>';
        }
        if ($option['active_buttons']['stumbleupon'] == true) {
            $output .= '
			<div class="buttons"><script src="http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=' . $post_link . '"></script></div>';
        }
        if ($option['active_buttons']['linkedin'] == true) {
            $output .= '<div class="buttons" style="padding-left:0px;"><script type="in/share" data-url="' . $post_link . '" data-counter="top"></script></div>';
        }
        $output .= '</div><div style="clear:both"></div>';
        return $output;
    }
    if ($option['position'] == 'below' || $option['position'] == 'above' || $option['position'] == 'both') {
        $output = '<div class="bottomcontainerBox" style="' . $border . $bkcolor . '">';
        if ($option['active_buttons']['facebook_like'] == true) {
            $output .= '
			<div style="float:left; width:' . $option['facebook_like_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=' . urlencode($post_link) . '&amp;layout=button_count&amp;show_faces=false&amp;width=' . $option['facebook_like_width'] . '&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=' . $option['facebook_like_width'] . 'px; height:21px;" allowTransparency="true"></iframe></div>';
        }
        if ($option['active_buttons']['Google_plusone'] == true) {
            $data_count = $option['google_count'] ? '' : 'count="false"';
            $output .= '
			<div style="float:left; width:' . $option['google_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="' . $post_link . '"' . $data_count . '></g:plusone>
			</div>';
        }
        if ($option['active_buttons']['twitter'] == true) {
            $data_count = $option['twitter_count'] ? 'horizontal' : 'none';
            if ($option['twitter_id'] != '') {
                $output .= '
			<div style="float:left; width:' . $option['twitter_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $post_link . '"  data-text="' . $post_title . '" data-count="' . $data_count . '" data-via="' . $option['twitter_id'] . '">Tweet</a>
			</div>';
            } else {
                $output .= '
			<div style="float:left; width:' . $option['twitter_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $post_link . '"  data-text="' . $post_title . '" data-count="' . $data_count . '">Tweet</a>
			</div>';
            }
        }
        if ($option['active_buttons']['linkedin'] == true) {
            $counter = $option['linkedin_count'] ? 'right' : '';
            $output .= '<div style="float:left; width:' . $option['linkedin_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="' . $post_link . '" data-counter="' . $counter . '"></script></div>';
        }
        if ($option['active_buttons']['stumbleupon'] == true) {
            $output .= '			
			<div style="float:left; width:' . $option['stumbleupon_width'] . 'px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=' . $post_link . '"></script></div>';
        }
        $output .= '			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>';
        return $output;
    }
}
Example #2
0
function kc_twitter_facebook_admin_page()
{
    $option_name = 'twitter_facebook_share';
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $active_buttons = array('facebook_like' => 'Facebook like', 'twitter' => 'Twitter', 'stumbleupon' => 'Stumbleupon', 'Google_plusone' => 'Google PlusOne', 'linkedin' => 'LinkedIn');
    $show_in = array('posts' => 'Single posts', 'pages' => 'Pages', 'home_page' => 'Home page', 'tags' => 'Tags', 'categories' => 'Categories', 'authors' => 'Author archives', 'search' => 'Search results', 'date_arch' => 'Archives');
    $out = '';
    if (isset($_POST['twitter_facebook_share_position'])) {
        $option = array();
        $option['auto'] = (isset($_POST['twitter_facebook_share_auto_display']) and $_POST['twitter_facebook_share_auto_display'] == 'on') ? true : false;
        foreach (array_keys($active_buttons) as $item) {
            $option['active_buttons'][$item] = (isset($_POST['twitter_facebook_share_active_' . $item]) and $_POST['twitter_facebook_share_active_' . $item] == 'on') ? true : false;
        }
        foreach (array_keys($show_in) as $item) {
            $option['show_in'][$item] = (isset($_POST['twitter_facebook_share_show_' . $item]) and $_POST['twitter_facebook_share_show_' . $item] == 'on') ? true : false;
        }
        $option['position'] = esc_html($_POST['twitter_facebook_share_position']);
        $option['border'] = esc_html($_POST['twitter_facebook_share_border']);
        $option['bkcolor'] = (isset($_POST['twitter_facebook_share_background_color']) and $_POST['twitter_facebook_share_background_color'] == 'on') ? true : false;
        $option['bkcolor_value'] = esc_html($_POST['twitter_facebook_share_bkcolor_value']);
        $option['jsload'] = (isset($_POST['twitter_facebook_share_javascript_load']) and $_POST['twitter_facebook_share_javascript_load'] == 'on') ? true : false;
        $option['twitter_id'] = esc_html($_POST['twitter_facebook_share_twitter_id']);
        $option['left_space'] = esc_html($_POST['twitter_facebook_share_left_space']);
        $option['bottom_space'] = esc_html($_POST['twitter_facebook_share_bottom_space']);
        $option['float_position'] = esc_html($_POST['twitter_facebook_share_float_position']);
        $option['twitter_count'] = (isset($_POST['twitter_facebook_share_twitter_count']) and $_POST['twitter_facebook_share_twitter_count'] == 'on') ? true : false;
        $option['google_count'] = (isset($_POST['twitter_facebook_share_google_count']) and $_POST['twitter_facebook_share_google_count'] == 'on') ? true : false;
        $option['linkedin_count'] = (isset($_POST['twitter_facebook_share_linkedin_count']) and $_POST['twitter_facebook_share_linkedin_count'] == 'on') ? true : false;
        $option['google_width'] = esc_html($_POST['twitter_facebook_share_google_width']);
        $option['facebook_like_width'] = esc_html($_POST['twitter_facebook_share_facebook_like_width']);
        $option['twitter_width'] = esc_html($_POST['twitter_facebook_share_twitter_width']);
        $option['linkedin_width'] = esc_html($_POST['twitter_facebook_share_linkedin_width']);
        $option['stumbleupon_width'] = esc_html($_POST['twitter_facebook_share_stumbleupon_width']);
        update_option($option_name, $option);
        // Put a settings updated message on the screen
        $out .= '<div class="updated"><p><strong>' . __('Settings saved.', 'menu-test') . '</strong></p></div>';
    }
    //GET ARRAY OF STORED VALUES
    $option = twitter_facebook_share_get_options_stored();
    $sel_above = $option['position'] == 'above' ? 'selected="selected"' : '';
    $sel_below = $option['position'] == 'below' ? 'selected="selected"' : '';
    $sel_both = $option['position'] == 'both' ? 'selected="selected"' : '';
    $sel_left = $option['position'] == 'left' ? 'selected="selected"' : '';
    $sel_flat = $option['border'] == 'flat' ? 'selected="selected"' : '';
    $sel_round = $option['border'] == 'round' ? 'selected="selected"' : '';
    $sel_none = $option['border'] == 'none' ? 'selected="selected"' : '';
    $sel_fixed = $option['float_position'] == 'fixed' ? 'selected="selected"' : '';
    $sel_absolute = $option['float_position'] == 'absolute' ? 'selected="selected"' : '';
    $bkcolor = $option['bkcolor'] ? 'checked="checked"' : '';
    $jsload = $option['jsload'] ? 'checked="checked"' : '';
    $auto = $option['auto'] ? 'checked="checked"' : '';
    $google_count = $option['google_count'] ? 'checked="checked"' : '';
    $twitter_count = $option['twitter_count'] ? 'checked="checked"' : '';
    $linkedin_count = $option['linkedin_count'] ? 'checked="checked"' : '';
    $out .= '
	<div class="wrap">

	<h2>' . __('Facebook and Twitter share buttons', 'menu-test') . '</h2>
	<div id="poststuff" style="padding-top:10px; position:relative;">
		<div style="float:left; width:74%; padding-right:1%;">
	<form name="form1" method="post" action="">
	<div class="postbox">
	<h3>' . __("General options", 'menu-test') . '</h3>
	<div class="inside">
	<table>
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Auto Display", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
		<input type="checkbox" name="twitter_facebook_share_auto_display" ' . $auto . ' />
		<span class="description">' . __("Enable Auto display of Social Share buttons at specified postion", 'menu-test') . '</span>
	</td></tr>
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Code for Manual Display", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<code>&lt;?php if(function_exists(&#39;kc_add_social_share&#39;)) kc_add_social_share(); ?&gt;</code>
	</td></tr>

	<tr><td valign="top" style="width:130px;">' . __("Active share buttons", 'menu-test') . ':</td>
	<td style="padding-bottom:30px;">';
    foreach ($active_buttons as $name => $text) {
        $checked = $option['active_buttons'][$name] ? 'checked="checked"' : '';
        $out .= '<div style="width:150px; float:left;">
				<input type="checkbox" name="twitter_facebook_share_active_' . $name . '" ' . $checked . ' /> ' . __($text, 'menu-test') . ' &nbsp;&nbsp;</div>';
    }
    $out .= '</td></tr>
			<tr><td valign="top" style="width:130px;">' . __("Show buttons in these pages", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">';
    foreach ($show_in as $name => $text) {
        $checked = $option['show_in'][$name] ? 'checked="checked"' : '';
        $out .= '<div style="width:150px; float:left;">
						<input type="checkbox" name="twitter_facebook_share_show_' . $name . '" ' . $checked . ' /> ' . __($text, 'menu-test') . ' &nbsp;&nbsp;</div>';
    }
    $out .= '</td></tr>';
    $out .= '<tr><td style="padding-bottom:20px;" valign="top">' . __("Note", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<span class="description">' . __("Left Floating is available only for single post and Static pages. By Default the bar will be displayed above the post.", 'menu-test') . '</span>';
    $out .= '</td></tr>	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Position", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;"><select name="twitter_facebook_share_position">
		<option value="above" ' . $sel_above . ' > ' . __('Above the post', 'menu-test') . '</option>
		<option value="below" ' . $sel_below . ' > ' . __('Below the post', 'menu-test') . '</option>
		<option value="both"  ' . $sel_both . '  > ' . __('Above and Below the post', 'menu-test') . '</option>
		<option value="left"  ' . $sel_left . '  > ' . __('Left Side of the post', 'menu-test') . '</option>
		</select>
	</td></tr>
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Border Style", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;"><select name="twitter_facebook_share_border">
		<option value="flat"  ' . $sel_flat . ' > ' . __('Flat Border', 'menu-test') . '</option>
		<option value="round" ' . $sel_round . ' > ' . __('Round Border', 'menu-test') . '</option>
		<option value="none"  ' . $sel_none . '  > ' . __('No Border', 'menu-test') . '</option>
		</select>
	</td></tr>
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Show Background Color", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
		<input type="checkbox" name="twitter_facebook_share_background_color" ' . $bkcolor . ' />
	</td></tr>
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Background Color", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<input type="text" name="twitter_facebook_share_bkcolor_value" value="' . $option['bkcolor_value'] . '" size="10">  
		 <span class="description">' . __("Default Color wont disappoint you", 'menu-test') . '</span>
	</td></tr> 
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Load Javascript in Footer", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
		<input type="checkbox" name="twitter_facebook_share_javascript_load" ' . $jsload . ' />
		<span class="description">' . __("(Recommended, else loaded in header)", 'menu-test') . '</span>
	</td></tr>
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Your Twitter ID", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<input type="text" name="twitter_facebook_share_twitter_id" value="' . $option['twitter_id'] . '" size="30">  
		 <span class="description">' . __("Specify your twitter id without @", 'menu-test') . '</span>
	</td></tr> 
	</table>
	</div>
	</div>
	
	<div class="postbox">
	<h3>' . __("Left Side Floating Specific Options", 'menu-test') . '</h3>
	<div class="inside">
	<table>
		
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Left Side Spacing", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<input type="text" name="twitter_facebook_share_left_space" value="' . $option['left_space'] . '" size="10">  
		 <span class="description">' . __("Spacing from Left Side of Margin", 'menu-test') . '</span>
	</td></tr> 
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Top Spacing", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;">
	<input type="text" name="twitter_facebook_share_bottom_space" value="' . $option['bottom_space'] . '" size="10">  
		 <span class="description">' . __("Spacing from Top of the page", 'menu-test') . '</span>
	</td></tr> 
	
	<tr><td style="padding-bottom:20px;" valign="top">' . __("Float Bar Position", 'menu-test') . ':</td>
	<td style="padding-bottom:20px;"><select name="twitter_facebook_share_float_position">
		<option value="fixed" ' . $sel_fixed . ' > ' . __('Fixed Position', 'menu-test') . '</option>
		<option value="absolute" ' . $sel_absolute . ' > ' . __('Absolute Position', 'menu-test') . '</option>
		</select>
	</td></tr>
	</table>
	</div>
	</div>
	
	<div class="postbox">
	<h3>' . __("Adjust Width and Count Display", 'menu-test') . '</h3>
	<div class="inside">
		<table>
		<tr><td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("Facebook Button width", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="text" name="twitter_facebook_share_facebook_like_width" value="' . stripslashes($option['facebook_like_width']) . '" size="5">px<br />
			</td>
			<td style="padding-bottom:20px; padding-left:50px; padding-right:10px;" valign="top">' . __("Google +1 Button width", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="text" name="twitter_facebook_share_google_width" value="' . stripslashes($option['google_width']) . '" size="5">px<br />
			</td>
			<td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("Stumbleupon Button width", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="text" name="twitter_facebook_share_stumbleupon_width" value="' . stripslashes($option['stumbleupon_width']) . '" size="10"> px <br />
			</td>	
		</tr>
		<tr><td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("Twitter Button width", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="text" name="twitter_facebook_share_twitter_width" value="' . stripslashes($option['twitter_width']) . '" size="5"> px <br />
			</td>
			<td style="padding-bottom:20px; padding-left:50px; padding-right:10px;" valign="top">' . __("Linkedin Button width", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="text" name="twitter_facebook_share_linkedin_width" value="' . stripslashes($option['linkedin_width']) . '" size="5"> px <br />
			</td>	
		</tr>
		<tr><td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("Google +1 counter", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="checkbox" name="twitter_facebook_share_google_count" ' . $google_count . ' />
			</td>
			<td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("LinkedIn counter", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="checkbox" name="twitter_facebook_share_linkedin_count" ' . $linkedin_count . ' />
			</td>	
		</tr>
		<tr><td style="padding-bottom:20px; padding-right:10px;" valign="top">' . __("Twitter counter", 'menu-test') . ':</td>
			<td style="padding-bottom:20px;">
				<input type="checkbox" name="twitter_facebook_share_twitter_count" ' . $twitter_count . ' />
			</td></tr>
		</table>
	</div>
	</div>
	
	<tr><td valign="top" colspan="2">
	<p class="submit">
		<input type="submit" name="Submit" class="button-primary" value="' . esc_attr('Save Changes') . '" />
	</p>
	</td></tr>
	</form>
	</div>
	
	<div style="float:right; width:25%;">
	<div class="postbox">
	<h3>' . __("Support The Author", 'menu-test') . '</h3>
	<div class="inside">
	<table>
	<tr><td  align="justify">
	<p >If you liked the plugin and was useful to your site then please support to keep this project up and running. Maintenance and enhancement do cost. Show your appreciation and love.</p> </td></tr>
	<tr>
	<td align="center">
	<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
	<input type="hidden" name="cmd" value="_s-xclick">
	<input type="hidden" name="hosted_button_id" value="86FHBFVUYN45J">
	<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
	<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
	</form>
	</td>
	</tr>
	</table>
	</div>
	</div>
	<div class="postbox">
	<h3>' . __("Additional Info", 'menu-test') . '</h3>
	<div class="inside">
	<table>
	<tr><td  align="justify">
	<ul>
	<li>Shortcode <strong>[tfg_social_share]</strong> to add the social share bar to specific pages.</li> 
	<li>Custom field "<strong>disable_social_share</strong>" with value "yes" to exclude specific post or pages.</li>
	</td></tr>
	</tr>
	</table>
	</div>
	</div>

	</div>
	';
    echo $out;
}
require_once 'tf_display.php';
if (!function_exists('is_admin')) {
    header('Status: 403 Forbidden');
    header('HTTP/1.1 403 Forbidden');
    exit;
}
/* Runs when plugin is activated */
register_activation_hook(__FILE__, 'kc_twitter_facebook_install');
/* Runs on plugin deactivation*/
register_deactivation_hook(__FILE__, 'kc_twitter_facebook_remove');
function kc_twitter_facebook_install()
{
    /* Do Nothing */
}
function kc_twitter_facebook_remove()
{
    /* Deletes the database field */
    delete_option('twitter_facebook_share');
}
if (is_admin()) {
    add_action('admin_menu', 'kc_twitter_facebook_admin_menu');
} else {
    add_action('init', 'twitter_facebook_share_init');
    add_shortcode('tfg_social_share', 'tfg_social_share_shortcode');
    add_action('wp_head', 'fb_like_thumbnails');
    $option = twitter_facebook_share_get_options_stored();
    if ($option['auto'] == true) {
        add_filter('the_content', 'kc_twitter_facebook_contents');
        add_filter('the_excerpt', 'kc_twitter_facebook_excerpt');
    }
}