Skip to content

Instantly share code, notes, and snippets.

@Odyno
Last active December 24, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Odyno/6753662 to your computer and use it in GitHub Desktop.
Save Odyno/6753662 to your computer and use it in GitHub Desktop.
Wordpress Follow_Me_Tabs plugin patch
<?php
/*
Plugin Name: Follow me Tabs
Plugin URI: http://follow.code4site.com
Description: Plugin for displaying "Follow me Tabs" on different positions on the browser screen
Author: Igor Ivanov
Version: 1.0
Author URI: http://follow.code4site.com
*/
add_action('wp_footer', 'mp_footer');
add_action('admin_menu', 'followmetab_admin_actions');
add_action('wp_enqueue_scripts', 'my_scripts_method');
//include widget code
include('followme_widget.php');
//include css and javascript
function my_scripts_method()
{
wp_enqueue_script('custom-script', WP_PLUGIN_URL . '/follow-me-tabs/js/inc.js', array('jquery'));
wp_enqueue_style( 'prefix-style', WP_PLUGIN_URL . '/follow-me-tabs/css/style.css' );
}
//footer code
function mp_footer()
{
global $networks_array, $path_to_images;
$data = get_option('follow_me_tabs_133');
if(count($data) > 0 && $data['in_position'] != 'hidden')
{
//get style, position and size of the tabs from database
$style = $data['in_style'];
$position = $data['in_position'];
$size = $data['in_size'];
//make sure they are valid
if(!in_array($style, array('1','2','3','4'))) $style = '1';
if(!in_array($position, array('left','right'))) $position = 'left';
if(!in_array($size, array('40','50'))) $size = '40';
echo '<div class="tabs_fm_s_'.$style.'_'.$size.' tabs_'.$position.'_'.$style.'_'.$size.'">';
if($style == '2') echo '<div class="tabs_inner_fm_s_'.$style.'_'.$size.' tabs_'.$position.'_fm_s">';
foreach ($data['networks'] as $network=>$network_params)
{
if($style == '2')
$add_img = '<img src="'.$path_to_images.'s2/'.$networks_array[$network]['icon'].'.png" alt="" width="'.$size.'" />';
else
$add_img = '';
$link_class = $position.'_'.$style.'_'.$size.'_'.$networks_array[$network]['icon'];
if($style == '3' || $style == '4')
$link_class = 'tabs_fm_s_a_'.$size.' i_'.$style.'_'.$size.'_'.$networks_array[$network]['icon'];
if($network_params['value'] != '' && $network_params['active'] == 1)
echo '<a href="'.$network_params['value'].'" class="'.$link_class.'" target="_blank" title="">'.$add_img.'</a>';
}
if($style == '2') echo '</div>';
echo '</div>';
}
}
//menu link in Settings admin menu
function followmetab_admin_actions()
{
add_options_page("Follow Me Tabs", "Follow Me Tabs", 1, "follow_me_tabs_133", "followmetabs_admin");
}
//open admin page
function followmetabs_admin()
{
global $networks_array;
include('followmetab_admin.php');
}
//path to plugin image folder
$path_to_images = WP_PLUGIN_URL . '/follow-me-tabs/img/';
//networks array
$networks_array = array(
'Facebook'=>array(
'description'=>'Ex: http://facebook.com/<b>username</b> or <br />http://facebook.com/profile.php?id=<b>profileID</b>',
'icon'=>'facebook',
'value'=>'',
'active'=>'',
'link'=> 'http://facebook.com/-ID-'
),
'Google_Plus'=>array(
'description'=>'Ex: https://plus.google.com/u/1/<b>userID</b>',
'icon'=>'plus',
'value'=>'',
'active'=>'',
'link'=>'https://plus.google.com/u/1/-ID-'
),
'LinkedIn'=>array(
'description'=>'Ex: http://www.linkedin.com/in/<b>username</b>',
'icon'=>'linkedin',
'value'=>'',
'active'=>'',
'link'=>'http://www.linkedin.com/in/-ID-'
),
'Twitter'=>array(
'description'=>'Ex: http://www.twitter.com/<b>username</b>',
'icon'=>'twitter',
'value'=>'',
'active'=>'',
'link'=>'https://twitter.com/-ID-'
),
'Youtube'=>array(
'description'=>'Ex: http://www.youtube.com/<b>username</b>',
'icon'=>'youtube',
'value'=>'',
'active'=>'',
'link'=>'http://www.youtube.com/-ID-'
),
'Blogger'=>array(
'description'=>'Ex: http://www.<b>username</b>.blogspot.com',
'icon'=>'blogger',
'value'=>'',
'active'=>'',
'link'=>'http://www.-ID-.blogspot.com'
),
'Skype_Name'=>array(
'description'=>'Ex: skype:<b>SkypeName</b>?chat',
'icon'=>'skype',
'value'=>'',
'active'=>'',
'link'=>'skype:-ID-?chat'
),
'MySpace'=>array(
'description'=>'Ex: http://www.myspace.com/<b>userID</b>',
'icon'=>'myspace',
'value'=>'',
'active'=>'',
'link'=>'http://www.myspace.com/-ID-'
),
'Pinterest'=>array(
'description'=>'Ex: http://pinterest.com/<b>username</b>/',
'icon'=>'pinterest',
'value'=>'',
'active'=>'',
'link'=>'http://pinterest.com/-ID-'
),
'RSS_Feed'=>array(
'description'=>'Ex: url from your rss feed',
'icon'=>'rssfeed',
'value'=>'',
'active'=>'',
'link'=>'-ID-'
),
'Last_fm'=>array(
'description'=>'Ex: http://www.last.fm/user/<b>username</b>',
'icon'=>'lastfm',
'value'=>'',
'active'=>'',
'link'=>'http://www.last.fm/user/-ID-'
),
'Deviant_Art'=>array(
'description'=>'Ex: http://<b>username</b>.deviantart.com/',
'icon'=>'deviantart',
'value'=>'',
'active'=>'',
'link'=>'http://-ID-.deviantart.com/'
),
);
?>
<?php
add_action( 'widgets_init', 'follow_me_tabs_widget' );
add_shortcode( 'follow_me_icons', 'follow_me_icons_content_processor' );
function follow_me_tabs_widget()
{
register_widget( 'FollowMeTabs_Widget' );
}
function follow_me_icons_content_processor($atts)
{
extract( shortcode_atts( array(
'size' => 'small',
'type' => 'zoom'
), $atts ) );
return follow_me_icons_build($size, $type);
}
function follow_me_icons_build($size, $style, $widget_text = '', $widget_list = array())
{
global $networks_array, $path_to_images;
$content = '';
if($style == 'zoom') $style = 2;
if($style == 'color') $style = 3;
if($style == 'grey') $style = 4;
if($size == 'small') $size = 40;
if($size == 'large') $size = 50;
if(!in_array($style, array('2','3','4'))) $style = '2';
if(!in_array($size, array('40','50'))) $size = '40';
$data = get_option('follow_me_tabs_133');
if(count($data) > 0 )
{
if($widget_text != '') $content .= $widget_text;
$main_class = ($style == '2') ? 'widget_fm_zoom' : 'widget_fm_color';
$content .= '<div class="widget_fm_'.$size.' '.$main_class.'">';
if($style == '2')
{
if(count($widget_list) > 0)
$min_width = count($widget_list) * ($size + 10);
else
{
$cnt = 0;
foreach ($data['networks'] as $network=>$network_params)
if($network_params['value'] != '' && isset($network_params['active']) && $network_params['active'] == "1")
$cnt++;
$min_width = $cnt * ($size + 10);
}
$content .= '<div class="widget_inner_fm_'.$size.'" style="min-width: '.$min_width.'px;">';
}
foreach ($data['networks'] as $network=>$network_params)
{
if(count($widget_list) > 0 && !in_array($network, $widget_list)) continue;
if($style == '2')
$add_img = '<img src="'.$path_to_images.'s2/'.$networks_array[$network]['icon'].'.png" alt="" width="'.$size.'" />';
else
$add_img = '';
$link_class = '';
if($style == '3' || $style == '4')
$link_class = 'tabs_fm_s_a_'.$size.' i_'.$style.'_'.$size.'_'.$networks_array[$network]['icon'];
$link_follower=str_replace("-ID-", $network_params['value'], $networks_array[$network]['link']);
if($network_params['value'] != '' && isset($network_params['active']) && $network_params['active'] == "1")
$content .= '<a href="'.$link_follower.'" class="'.$link_class.'" target="_blank" title="">'.$add_img.'</a>';
}
if($style == '2') $content .= '</div>';
$content .= '</div>';
}
return $content;
}
/**
* Widget class.
* This class handles everything that needs to be handled with the widget:
* the settings, form, display, and update.
*/
class FollowMeTabs_Widget extends WP_Widget
{
/**
* Widget setup.
*/
function FollowMeTabs_Widget()
{
/* Widget settings. */
$widget_ops = array(
'classname' => 'FollowMe',
'description' => __('"Fallow Me" buttons as Widget', 'FollowMe')
);
/* Widget control settings. */
$control_ops = array(
'width' => 400,
'height' => 400,
'id_base' => 'follow_me_tabs_widget' );
/* Create the widget. */
$this->WP_Widget(
'follow_me_tabs_widget',
__('Follow Me Widget', 'FollowMe'),
$widget_ops,
$control_ops
);
}
/**
* How to display the widget on the screen.
*/
function widget( $args, $instance )
{
extract( $args );
$defaults = array('w_network' => array(), 'w_network_style'=>'2', 'w_network_size'=>40, 'w_network_text'=>'');
$instance = wp_parse_args( (array) $instance, $defaults );
$title = ($instance['w_network_text'] != '') ? $args['before_title'] . $instance['w_network_text'] . $args['after_title'] : '';
echo $args['before_widget'];
echo follow_me_icons_build($instance['w_network_size'], $instance['w_network_style'], $title, $instance['w_network']);
echo $args['after_widget'];
}
/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance )
{
$instance = $new_instance;
/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['w_network'] = isset($_POST['w_network']) ? $_POST['w_network'] : array();
$instance['w_network_style'] = isset($_POST['w_network_style']) ? $_POST['w_network_style'] : '2';
$instance['w_network_size'] = isset($_POST['w_network_size']) ? $_POST['w_network_size'] : '40';
$instance['w_network_text'] = isset($_POST['w_network_text']) ? $_POST['w_network_text'] : '';
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
*/
function form( $instance )
{
global $networks_array,$path_to_images;
/* Set up some default widget settings. */
$defaults = array('w_network' => array(), 'w_network_style'=>'2', 'w_network_size'=>40, 'w_network_text'=>'');
$instance = wp_parse_args( (array) $instance, $defaults );
$data = get_option('follow_me_tabs_133');
$networks = isset($data['networks']) ? $data['networks'] : array();
if(count($networks) > 0)
{
echo '<p>Please check the network that you want to include in your widget (Here are listed only active networks with valid network URL set in Settings->Follow Me Tabs page)</p>';
echo '<div style="width:400px;display:block;">';
foreach ($data['networks'] as $network=>$network_params)
{
if($network_params['value'] != '' && isset($network_params['active']) && $network_params['active'] == "1")
{
$checked = in_array($network, $instance['w_network']) ? ' checked="checked" ' : '';
?>
<div style="width:130px;float:left;">
<div style="display:inline;margin-bottom:10px;vertical-align: top;">
<input type="checkbox" name="w_network[]" value="<?php echo $network?>" <?php echo $checked?>/>
</div>
<div style="display:inline;">
<img src="<?php echo $path_to_images?>s2/<?php echo $networks_array[$network]['icon']?>.png" alt="" width="45" />
</div>
</div>
<?
}
}
?>
<div style="clear:both;"></div>
<br />Widget Title (optional):<br />
<input type="text" name="w_network_text" value="<?php echo $instance['w_network_text']?>" style="width: 370px;" />
<br />Style:<br />
<select name="w_network_style">
<option value="2" <?php if($instance['w_network_style'] == '2') echo 'selected';?>>Zoom Icons</option>
<option value="3" <?php if($instance['w_network_style'] == '3') echo 'selected';?>>Color Up-Down Icons</option>
<option value="4" <?php if($instance['w_network_style'] == '4') echo 'selected';?>>Grey Up-Down Icons</option>
</select>
<br />Size:<br />
<select name="w_network_size">
<option value="40" <?php if($instance['w_network_size'] == '40') echo 'selected';?>>Small</option>
<option value="50" <?php if($instance['w_network_size'] == '50') echo 'selected';?>>Large</option>
</select>
<p>If you select zoom style, you need to have wider space in selected widget area!</p>
</div>
<?
}
else
{
echo 'Please go in Settings->Follow me Tabs and set up your networks first!';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment