diff --git a/sharebar-admin.php b/sharebar-admin.php index 5fbdf4b..faa3a60 100644 --- a/sharebar-admin.php +++ b/sharebar-admin.php @@ -1,210 +1,354 @@ get_row("SELECT * FROM ".$wpdb->prefix."sharebar WHERE id=$id"); - - if($do == 'update') $wpdb->query("UPDATE ".$wpdb->prefix."sharebar SET position='".$_POST['position']."', name='".$_POST['name']."', big='".$_POST['big']."', small='".$_POST['small']."' WHERE id='$id'"); - elseif($do == 'add') $wpdb->query("INSERT INTO ".$wpdb->prefix."sharebar (position, name, big, small) VALUES('".$_POST['position']."','".$_POST['name']."', '".$_POST['big']."', '".$_POST['small']."')"); - elseif($do == 'delete') $wpdb->query("DELETE FROM ".$wpdb->prefix."sharebar WHERE id=$id LIMIT 1"); - elseif($do == 'reset') sharebar_reset(); - elseif($do == 'settings'){ - $auto = $_POST['auto'] ? 1:0; $horizontal = $_POST['horizontal'] ? 1:0; - $width = $_POST['width']; $position = $_POST['position']; - $leftoffset = $_POST['leftoffset']; $rightoffset = $_POST['rightoffset']; - sharebar_settings($auto, $horizontal, $width, $position, $leftoffset, $rightoffset); - } - - if($pos == 'moveup') $wpdb->query("UPDATE ".$wpdb->prefix."sharebar SET position=position-1 WHERE id='$id'"); - if($pos == 'movedown') $wpdb->query("UPDATE ".$wpdb->prefix."sharebar SET position=position+1 WHERE id='$id'"); - if($pos) $status = "Position Updated!"; +/* Copyright 2010 Monji Dolon (email : md@devgrow.com) + Author Homepage: http://mdolon.com/ Author Blog: http://devgrow.com/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +if(!function_exists('sharebar') || !is_admin()) { + echo "You are not authorized to access this file."; + exit(); +} +$id = sanitize($_GET['id'] ? $_GET['id'] : $_POST['id']); +$pos = sanitize($_GET['pos'] ? $_GET['pos'] : $_POST['pos']); +$status = sanitize($_GET['status'] ? $_GET['status'] : $_POST['status']); +$task = sanitize($_GET['t'] ? $_GET['t'] : $_POST['t']); +$do = sanitize($_POST['do']); + +if($id) $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE id=%d", $id)); + +if($do == 'update') $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='%d', position='%d', name='%s', big='". $_POST['big'] ."', small='". $_POST['small'] ."' WHERE id='%d'", sanitize($_POST['enabled']), sanitize($_POST['position']), sanitize($_POST['name']), $id)); +elseif($do == 'add') $wpdb->query($wpdb->prepare("INSERT INTO ".$wpdb->prefix."sharebar (position, name, big, small) VALUES('%d','%s', '". $_POST['big'] ."', '". $_POST['small'] ."')", sanitize($_POST['position']), sanitize($_POST['name']))); +elseif($do == 'delete') $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."sharebar WHERE id=%d LIMIT 1", $id)); +elseif($do == 'reset') sharebar_reset(); +elseif($do == 'settings'){ + $binaries = array("auto_posts","auto_pages","horizontal","credit"); + foreach($binaries as $binary) $_POST[$binary] = $_POST[$binary] ? 1:0; + $_POST['width'] = $_POST['width'] ? $_POST['width']:1000; + sharebar_settings($_POST); + foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option); +}elseif($do == 'update-all'){ + $buttons = $_POST['buttons']; + $uptask = $_POST['update-task']; + if($buttons){ + foreach ($buttons as $button) + sharebar_update_button($button,$uptask); + $status = "Buttons have been ".$uptask."d"; + }else + $status = "No buttons selected."; +} +if($task == "linkback"){ + if($credit){ + $current = "disabled"; + update_option('sharebar_credit','0'); + }else{ + $current = "enabled"; + update_option('sharebar_credit','1'); + } + $status = 'Linkback '.$current; + $credit = get_option('sharebar_credit'); +} + +if($pos == 'moveup') $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET position=position-1 WHERE id='%d'", $id)); +if($pos == 'movedown') $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET position=position+1 WHERE id='%d'", $id)); +if($pos) $status = "Position Updated!"; ?> +
-
- -

Custom Sharebar

- -

- - - -

Button

-

You can use HTML, Javascript or inline CSS for the button code. Additionally, the following variables are automatically extracted from the post and can be used in your code: [url], [title], and [author].

- '; - echo "".$item->name.":"; - echo "".$item->big.""; - echo "".$item->small.""; - echo ''; - } - ?> -
-

- - -

-

- - -

-

- - -

-

- - -

- " /> - - ." /> - " class="alignleft" /> -
- Cancel - - - -

Delete Button?

- '; - echo "".$item->name.":"; - echo "".$item->big.""; - echo "".$item->small.""; - echo ''; - ?> -

Are you sure you want to delete this button?

-
- - - - -
- Cancel - - - -

Reset Buttons?

-

Are you sure you want to reset ALL share buttons? This cannot be undone and you will lose any customizations - all buttons will be reset to defaults.

-
- - - -
- Cancel - - - -

Sharebar Settings

-
-

- />
- If this option is disabled, you must manually add the horizontal and vertical bar code to your template(s). -

-

- /> -

-

- - -

-

- -

-

- -

-

- -

- - - -
- Cancel - - - -

Sharebar adds a dynamic and fully customizable vertical box to the left of a blog post that contains links/buttons to popular social networking sites.

-

Big Buttons are used in the vertical Sharebar to the left of the post, while the Small Buttons are used in the horizontal Sharebar that appears under the post title (by default) if the width of the page is less than px.

- Auto mode is ON, so the buttons are added automatically.

"; - else{ - echo "

Auto mode is OFF, so you must manually add the following code for the horizontal and vertical bars:

"; - echo "
Vertical (next to post) Sharebar: "; - echo "<?php sharebar(); ?>
"; - echo "Horizontal Sharebar: "; - echo "<?php sharebar_horizontal(); ?>
"; - } - ?> -

You can also call an individual button in any template by using the following code (where size is either big or small): - <?php sharebar_button('name','size'); ?>

-

Active Buttons:

- Add New Button - - - - get_results("SELECT * FROM ".$wpdb->prefix."sharebar ORDER BY position, id ASC"); echo "\n"; - foreach($results as $result){ - echo "\t\t\n"; - } ?> - -
NamePositionBig ButtonSmall ButtonActions
".$result->name."".$result->position."".$result->big."".$result->small."id."'>Edit | id."'>Delete
- Reset Buttons - - - -
\ No newline at end of file +
+ +

Custom Sharebar

+ +

+
By Monji of DevGrow and the (amazing) SumoMe WP Plugin
Home - Settings +
+

+ + + +

Button

+

You can use HTML, Javascript or inline CSS for the button code. Additionally, the following variables are automatically extracted from the post and can be used in your code: [url], [title], and [author].

+

If you have set your Twitter username in the settings, that will also be available using [twitter].

+ '; + echo "".$item->name.":"; + echo "".$item->big.""; + echo "".$item->small.""; + echo ''; + } + if($item->enabled) $enabled = " checked='true'"; + ?> +
+

+ + +

+

+ + +

+

+ + /> +

+
+

+ + +

+

+ + +

+ " /> + + ." /> + " class="alignleft button-primary" /> +
+ Cancel + + + +

Delete Button?

+ '; + echo "".$item->name.":"; + echo "".$item->big.""; + echo "".$item->small.""; + echo ''; + ?> +

Are you sure you want to delete this button?

+
+ + + + +
+ Cancel + + + +

Reset Buttons?

+

Are you sure you want to reset ALL share buttons? This cannot be undone and you will lose any customizations - all buttons will be reset to defaults.

+
+ + + +
+ Cancel + + + +

Sharebar Settings

+
+

Add Sharebar

+

The following settings allow you to automatically add the Sharebars to your posts and pages. If you would like to add them manually, make sure that both are unchecked and paste the PHP code into your template instead.

+

+ /> +

+

+ /> +

+

Display Options

+

+ /> +

+

+ /> +

+

+ + +

+

+ +

+

+ +

+

+ +

+

Customize

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+ + + +
+ Cancel + + + +

Donate

+

Sharebar is created by and maintained by just one person - @mdolon. If you like the plugin, please consider donating a buck or two by clicking the button below:

+

+

+ + + + + + + + + +
+

+ + + +
Update: Sharebar recommends SumoMe for even more powerful sharing tools!
+
+

Sharebar adds a dynamic and fully customizable vertical box to the left of a blog post that contains links/buttons to popular social networking sites.

+

Big Buttons are used in the vertical Sharebar to the left of the post, while the Small Buttons are used in the horizontal Sharebar that appears under the post title (by default) if the width of the page is less than px.

+ Auto mode is ON - Sharebar will be automatically added to "; + if($auto_posts) $amsg .= "posts"; + if($auto_posts && $auto_pages) $amsg .= " and "; + if($auto_pages) $amsg .= "pages"; + $amsg .= "."; + }else + $amsg .= "

Auto mode is OFF, so you must manually add the following code for the horizontal and vertical bars:

+
Vertical (next to post) Sharebar: + <?php sharebar(); ?>
+ Horizontal Sharebar: + <?php sharebar_horizontal(); ?>
"; + echo $amsg; + ?> +

You can also call an individual button in any template by using the following code (where size is either big or small):

+

<?php sharebar_button('name','size'); ?>

+
+
+

Support Us

+

If you like Sharebar and find it useful, please consider showing your support by:

+ + +
+
+ +
+ Reset ButtonsAdd New Button +
+

Available Buttons:

+ +
+ + + + get_results("SELECT * FROM ".$wpdb->prefix."sharebar ORDER BY position, id ASC"); echo "\n"; + foreach($results as $result){ + if(!$result->enabled){ + $dis = " class='disabled'"; + $name = ''.$result->name.''; + }else{ + $dis = ""; + $name = $result->name; + } + echo "\t\t\n"; + } ?> + +
AllNamePositionBig ButtonSmall ButtonActions
".$name."".$result->position."".$result->big."".$result->small."id."'>Edit | id."'>Delete
+
+

+ + + + +

+
+
+

grey = disabled / white = enabled

+
+
+ + + diff --git a/sharebar.php b/sharebar.php index 9b9744a..e9d7348 100644 --- a/sharebar.php +++ b/sharebar.php @@ -2,16 +2,16 @@ /* Plugin Name: Sharebar Plugin URI: http://devgrow.com/sharebar-wordpress-plugin/ -Description: Adds a dynamic bar with sharing icons (Facebook, Twitter, etc.) that changes based on browser size and page location. More info and demo at: Sharebar Plugin Home -Version: 1.0.1 -Author: Monjurul Dolon +Description: Adds a dynamic bar with sharing icons (Facebook, Twitter, etc.) that changes based on browser size and page location. +Version: 1.4.1 +Author: Monji Dolon Author URI: http://mdolon.com/ License: GPL2 */ /* Copyright 2010 Monjurul Dolon (email : md@devgrow.com) This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as + it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, @@ -23,135 +23,248 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +$sharebar_options = array("auto_posts","auto_pages","horizontal","width","position","credit","leftoffset","rightoffset","swidth","twitter_username","sbg","sborder"); function sharebar_install(){ global $wpdb; $table = $wpdb->prefix."sharebar"; - if($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { - $structure = "CREATE TABLE $table ( - id mediumint(9) NOT NULL AUTO_INCREMENT, - position mediumint(9) NOT NULL, - name VARCHAR(80) NOT NULL, - big text NOT NULL, - small text NULL, - UNIQUE KEY id (id) + if($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { + $structure = "CREATE TABLE $table ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + position mediumint(9) NOT NULL, + enabled int(1) NOT NULL, + name VARCHAR(80) NOT NULL, + big text NOT NULL, + small text NULL, + UNIQUE KEY id (id) );"; - $wpdb->query($structure); - $wpdb->query("INSERT INTO $table(position,name, big, small) - VALUES('1','tweetmeme', '', '')"); - $wpdb->query("INSERT INTO $table(position,name, big, small) - VALUES('2','facebook', 'Share', 'Share')"); - $wpdb->query("INSERT INTO $table(position,name, big, small) - VALUES('3','buzz', '', '')"); - $wpdb->query("INSERT INTO $table(position,name, big, small) - VALUES('4','digg', '', '')"); - $wpdb->query("INSERT INTO $table(position,name, big, small) - VALUES('5','email', 'Email', 'Email')"); - add_option('sharebar_auto', 1); - add_option('sharebar_horizontal', 1); - add_option('sharebar_minwidth','1000'); - add_option('sharebar_position','left'); - add_option('sharebar_leftoffset','20'); - add_option('sharebar_rightoffset','10'); - } + + $wpdb->query($structure); + + $facebook = "
"; + $facebook_small = "
"; + $twitter = "Tweet"; + $twitter_small = "Tweet"; + $reddit = ""; + $reddit_small = ""; + $stumbleupon = ""; + $stumbleupon_small = ""; + $pinterest = " + + "; + $pinterest_small = " + + "; + $email = "Email"; + $email_small = "Email"; + + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('1','1','facebook', '$facebook', '$facebook_small')"); + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('1','2','twitter', '$twitter', '$twitter_small')"); + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('0','3','pinterest', '$pinterest', '$pinterest_small')"); + + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('0','4','reddit', '$reddit', '$reddit_small')"); + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('0','5','stumbleupon', '$stumbleupon', '$stumbleupon_small')"); + $wpdb->query("INSERT INTO $table(enabled, position, name, big, small) VALUES ('1','6','email', '$email', '$email_small')"); + + add_option('sharebar_auto_posts', 1); + add_option('sharebar_auto_pages', 1); + add_option('sharebar_horizontal', 1); + add_option('sharebar_credit', 0); + add_option('sharebar_minwidth','1000'); + add_option('sharebar_position','left'); + add_option('sharebar_leftoffset','20'); + add_option('sharebar_rightoffset','10'); + add_option('sharebar_swidth','65'); + add_option('sharebar_twitter_username','ThinkDevGrow'); + add_option('sharebar_bg','#ffffff'); + add_option('sharebar_border','#cccccc'); + } } function sharebar_reset(){ - global $wpdb; - $table = $wpdb->prefix."sharebar"; - $wpdb->query("DROP TABLE IF EXISTS $table"); - sharebar_install(); + global $wpdb; + $table = $wpdb->prefix."sharebar"; + $wpdb->query("DROP TABLE IF EXISTS $table"); + sharebar_install(); } function sharebar_menu(){ - global $wpdb; - - $auto = get_option('sharebar_auto'); $horizontal = get_option('sharebar_horizontal'); - $width = get_option('sharebar_minwidth'); $position = get_option('sharebar_position'); - $leftoffset = get_option('sharebar_leftoffset'); $rightoffset = get_option('sharebar_rightoffset'); - + global $wpdb, $sharebar_options; + foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option); include 'sharebar-admin.php'; } -function sharebar_settings($auto, $horizontal, $width, $position, $leftoffset, $rightoffset){ - update_option('sharebar_auto',$auto); update_option('sharebar_horizontal',$horizontal); - update_option('sharebar_minwidth',$width); update_option('sharebar_position',$position); - update_option('sharebar_leftoffset',$leftoffset); update_option('sharebar_rightoffset',$rightoffset); +function sharebar_settings($settings){ + global $sharebar_options; + foreach($sharebar_options as $option) update_option('sharebar_'.$option,$settings[$option]); } function sharebar_auto($content){ - if(get_option('sharebar_auto') && (is_single() || is_page())){ $str = sharebar(false); $str .= sharebar_horizontal(false); } - $newcontent = $str.$content; - return $newcontent; + if((get_option('sharebar_auto_posts') && is_single()) || (get_option('sharebar_auto_pages') && is_page())){ $str = sharebar(false); $str .= sharebar_horizontal(false); } + $newcontent = $str.$content; + return $newcontent; } function sharebar($print = true){ - global $wpdb; - $str = ''; - if($print) echo $str; else return $str; + global $wpdb, $post; + $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true); + $sbg = get_option('sharebar_sbg'); + $sborder = get_option('sharebar_sborder'); + if(empty($sharebar_hide)) { + $credit = get_option('sharebar_credit'); + $str = ''; + if($print) echo $str; else return $str; + } } function sharebar_horizontal($print = true){ - if(get_option('sharebar_horizontal')){ - global $wpdb; - $str = ''; - if($print) echo $str; else return $str; - } + if(get_option('sharebar_horizontal')){ + global $wpdb; + $str = ''; + if($print) echo $str; else return $str; + } } function sharebar_button($name, $size = 'big'){ - global $wpdb; - $item = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."sharebar WHERE name='$name'"); - if($size == 'big') echo $item->big; else echo $item->small; + global $wpdb; + $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE name='$name'")); + if($size == 'big') echo stripslashes($item->big); else echo stripslashes($item->small); } -function sharebar_header(){ +function sharebar_update_button($id, $uptask){ + global $wpdb; + if($uptask == 'enable') + $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='1' WHERE id='%d'", $id)); + elseif($uptask == 'disable') + $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='0' WHERE id='%d'", $id)); + elseif($uptask == 'delete') + $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."sharebar WHERE id=%d LIMIT 1", $id)); +} - if(function_exists('wp_enqueue_script') && (is_single() || is_page())) { - wp_enqueue_script('jquery'); - wp_enqueue_script('sharebar', get_bloginfo('wpurl').'/wp-content/plugins/sharebar/js/sharebar.js',array(),false,true); - echo ''; - } +function sharebar_scripts() { + wp_enqueue_script('sharebar', plugins_url('js/sharebar.js', __FILE__ ), array('jquery')); + wp_enqueue_style('sharebar', plugins_url('css/sharebar.css', __FILE__ )); } -function sharebar_footer(){ - $auto = get_option('sharebar_auto'); $horizontal = get_option('sharebar_horizontal'); - $width = get_option('sharebar_minwidth'); $position = get_option('sharebar_position'); - $leftoffset = get_option('sharebar_leftoffset'); $rightoffset = get_option('sharebar_rightoffset'); - if(function_exists('wp_enqueue_script') && (is_single() || is_page())) { - if($horizontal) $hori = 'true'; else $hori = 'false'; - ?> - - - post_title,get_permalink(),get_the_author()); - return str_replace($code,$values,$input); + global $post; + $code = array('[title]','[url]','[author]','[twitter]'); + $values = array($post->post_title,get_permalink(),get_the_author(),get_option('sharebar_twitter_username')); + return str_replace($code,$values,$input); } - + function sharebar_admin_actions(){ - add_options_page("Sharebar", "Sharebar", 1, "Sharebar", "sharebar_menu"); + if(current_user_can('manage_options')) add_options_page("Sharebar", "Sharebar", 1, "Sharebar", "sharebar_menu"); +} + +function sharebar_custom_boxes() { + add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'post', 'side', 'low'); + add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'page', 'side', 'low'); +} + +function sharebar_post_options(){ + global $post; + $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true); ?> +

+ /> + +

+ post_type == 'revision') return; + update_post_meta($post_id, 'sharebar_hide', true); +} + +function sharebar_admin_head(){ + echo ' + + + '; +} + +function cleanInput($input) { + + $search = array( + '@]*?>.*?@si', // Strip out javascript + '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags + '@]*?>.*?@siU', // Strip style tags properly + '@@' // Strip multi-line comments + ); + + $output = preg_replace($search, '', $input); + return $output; +} + +function sanitize($input) { + if (is_array($input)) { + foreach($input as $var=>$val) { + $output[$var] = sanitize($val); + } + } + else { + if (get_magic_quotes_gpc()) { + $input = stripslashes($input); + } + $input = cleanInput($input); + $output = esc_sql($input); + } + return $output; } add_filter('the_content', 'sharebar_auto'); -add_action('wp_head', sharebar_header, 1); -add_action('wp_footer', sharebar_footer, 1); +add_action('wp_enqueue_scripts', 'sharebar_scripts'); +add_action('wp_head', 'sharebar_header'); +add_action('admin_head', 'sharebar_admin_head'); add_action('activate_sharebar/sharebar.php', 'sharebar_install'); add_action('admin_menu', 'sharebar_admin_actions'); +add_action('add_meta_boxes', 'sharebar_custom_boxes'); +add_action('draft_post', 'sharebar_save_post_options'); +add_action('publish_post', 'sharebar_save_post_options'); +add_action('save_post', 'sharebar_save_post_options'); -?> \ No newline at end of file +?>