Guest User

Sharebar

a guest
Jan 11th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.29 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Sharebar
  4. Plugin URI: http://devgrow.com/sharebar-wordpress-plugin/
  5. 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: <a href="http://devgrow.com/sharebar-wordpress-plugin/">Sharebar Plugin Home</a>
  6. Version: 1.2.4
  7. Author: Monjurul Dolon
  8. Author URI: http://mdolon.com/
  9. License: GPL2
  10. */
  11. /* Copyright 2010 Monjurul Dolon (email : [email protected])
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License, version 2, as
  15. published by the Free Software Foundation.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. $sharebar_options = array("auto_posts","auto_pages","horizontal","width","position","credit","leftoffset","rightoffset","swidth","twitter_username","sbg","sborder");
  27.  
  28. function sharebar_install(){
  29. global $wpdb;
  30. $table = $wpdb->prefix."sharebar";
  31. if($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) {
  32. $structure = "CREATE TABLE $table (
  33. id mediumint(9) NOT NULL AUTO_INCREMENT,
  34. position mediumint(9) NOT NULL,
  35. enabled int(1) NOT NULL,
  36. name VARCHAR(80) NOT NULL,
  37. big text NOT NULL,
  38. small text NULL,
  39. UNIQUE KEY id (id)
  40. );";
  41. $wpdb->query($structure);
  42. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  43. VALUES('1','1','digg', '<script type=\"text/javascript\">(function() { var s = document.createElement(\'SCRIPT\'), s1 = document.getElementsByTagName(\'SCRIPT\')[0]; s.type = \'text/javascript\'; s.async = true; s.src = \'http://widgets.digg.com/buttons.js\'; s1.parentNode.insertBefore(s, s1); })(); </script><a class=\"DiggThisButton DiggMedium\"></a>', '<script type=\"text/javascript\">(function() { var s = document.createElement(\'SCRIPT\'), s1 = document.getElementsByTagName(\'SCRIPT\')[0]; s.type = \'text/javascript\'; s.async = true; s.src = \'http://widgets.digg.com/buttons.js\'; s1.parentNode.insertBefore(s, s1); })(); </script><a class=\"DiggThisButton DiggCompact\"></a>')");
  44. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  45. VALUES('1','2','twitter', '<a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-count=\"vertical\" data-via=\"[twitter]\">Tweet</a><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>', '<a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-count=\"horizontal\" data-via=\"[twitter]\">Tweet</a><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>')");
  46. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  47. VALUES('0','3','facebook', '<iframe src=\"http://www.facebook.com/plugins/like.php?href=[url]&layout=box_count&show_faces=false&width=60&action=like&colorscheme=light&height=45\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:45px; height:60px;\" allowTransparency=\"true\"></iframe>', '<iframe src=\"http://www.facebook.com/plugins/like.php?href=[url]&layout=button_count&show_faces=false&width=85&action=like&colorscheme=light&height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:85px; height:21px;\" allowTransparency=\"true\"></iframe>')");
  48. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  49. VALUES('1','4','sharethis', '<script type=\"text/javascript\" src=\"http://w.sharethis.com/button/buttons.js\"></script><span class=\"st_facebook_vcount\" displayText=\"Share\"></span><span class=\"st_email\" displayText=\"Email\"></span><span class=\"st_sharethis\" displayText=\"Share\"></span>', '<span class=\"st_facebook_hcount\" displayText=\"Share\"></span><span class=\"st_email\" displayText=\"Email\"></span><span class=\"st_sharethis\" displayText=\"Share\"></span>')");
  50. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  51. VALUES('0','5','buzz', '<a title=\"Post to Google Buzz\" class=\"google-buzz-button\" href=\"http://www.google.com/buzz/post\" data-button-style=\"normal-count\"></a><script type=\"text/javascript\" src=\"http://www.google.com/buzz/api/button.js\"></script>', '<a title=\"Post to Google Buzz\" class=\"google-buzz-button\" href=\"http://www.google.com/buzz/post\" data-button-style=\"small-count\"></a><script type=\"text/javascript\" src=\"http://www.google.com/buzz/api/button.js\"></script>')");
  52. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  53. VALUES('0','6','reddit', '<script type=\"text/javascript\" src=\"http://reddit.com/static/button/button2.js\"></script>', '<script type=\"text/javascript\" src=\"http://reddit.com/static/button/button1.js\"></script>')");
  54. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  55. VALUES('0','7','dzone', '<script language=\"javascript\" src=\"http://widgets.dzone.com/links/widgets/zoneit.js\"></script>', '<script language=\"javascript\" src=\"http://widgets.dzone.com/links/widgets/zoneit.js\"></script>')");
  56. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  57. VALUES('0','8','stumbleupon', '<script src=\"http://www.stumbleupon.com/hostedbadge.php?s=5\"></script>', '<script src=\"http://www.stumbleupon.com/hostedbadge.php?s=2\"></script>')");
  58. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  59. VALUES('0','9','yahoo', '<script type=\"text/javascript\" src=\"http://d.yimg.com/ds/badge2.js\" badgetype=\"square\">[url]</script>', '<script type=\"text/javascript\" src=\"http://d.yimg.com/ds/badge2.js\" badgetype=\"small-votes\">[url]</script>')");
  60. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  61. VALUES('0','10','designfloat', '<script type=\"text/javascript\">submit_url = \'[url]\';</script><script type=\"text/javascript\" src=\"http://www.designfloat.com/evb2/button.php\"></script>', '<script type=\"text/javascript\">submit_url = \'[url]\';</script><script type=\"text/javascript\" src=\"http://www.designfloat.com/evb/button.php\"></script>')");
  62. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  63. VALUES('0','11','email', '<a href=\"mailto:?subject=[url]\" class=\"sharebar-button email\">Email</a>', '<a href=\"mailto:?subject=[url]\" class=\"sharebar-button email\">Email</a>')");
  64. add_option('sharebar_auto_posts', 1);
  65. add_option('sharebar_auto_pages', 1);
  66. add_option('sharebar_horizontal', 1);
  67. add_option('sharebar_credit', 1);
  68. add_option('sharebar_minwidth','1000');
  69. add_option('sharebar_position','left');
  70. add_option('sharebar_leftoffset','20');
  71. add_option('sharebar_rightoffset','10');
  72. add_option('sharebar_swidth','65');
  73. add_option('sharebar_twitter_username','ThinkDevGrow');
  74. add_option('sharebar_bg','#ffffff');
  75. add_option('sharebar_border','#cccccc');
  76. }
  77. }
  78.  
  79. function sharebar_reset(){
  80. global $wpdb;
  81. $table = $wpdb->prefix."sharebar";
  82. $wpdb->query("DROP TABLE IF EXISTS $table");
  83. sharebar_install();
  84. }
  85.  
  86. function sharebar_menu(){
  87. global $wpdb, $sharebar_options;
  88. foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option);
  89. include 'sharebar-admin.php';
  90. }
  91.  
  92. function sharebar_settings($settings){
  93. global $sharebar_options;
  94. foreach($sharebar_options as $option) update_option('sharebar_'.$option,$settings[$option]);
  95. }
  96.  
  97.  
  98. function sharebar_auto($content){
  99. if((get_option('sharebar_auto_posts') && is_single()) || (get_option('sharebar_auto_pages') && is_page())){ $str = sharebar(false); $str .= sharebar_horizontal(false); }
  100. $newcontent = $str.$content;
  101. return $newcontent;
  102. }
  103.  
  104. function sharebar($print = true){
  105. global $wpdb, $post;
  106. $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true);
  107. $sbg = get_option('sharebar_sbg');
  108. $sborder = get_option('sharebar_sborder');
  109. if(empty($sharebar_hide)) {
  110. $credit = get_option('sharebar_credit');
  111. $str = '<ul id="sharebar" style="background:#'.$sbg.';border-color:#'.$sborder.';">';
  112. $results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC"); $str .= "\n";
  113. foreach($results as $result){ $str .= '<li>'.sharebar_filter($result->big).'</li>'; }
  114. if($credit) $str .= '<li class="credit"><a href="http://devgrow.com/sharebar" target="_blank">Sharebar</a></li>';
  115. $str .= '</ul>';
  116. if($print) echo $str; else return $str;
  117. }
  118. }
  119.  
  120. function sharebar_horizontal($print = true){
  121. if(get_option('sharebar_horizontal')){
  122. global $wpdb;
  123. $str = '<ul id="sharebarx">';
  124. $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC")); $str .= "\n";
  125. foreach($results as $result) { $str .= '<li>'.sharebar_filter($result->small).'</li>'; }
  126. $str .= '</ul>';
  127. if($print) echo $str; else return $str;
  128. }
  129. }
  130.  
  131. function sharebar_button($name, $size = 'big'){
  132. global $wpdb;
  133. $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE name='$name'"));
  134. if($size == 'big') echo stripslashes($item->big); else echo stripslashes($item->small);
  135. }
  136.  
  137. function sharebar_update_button($id, $uptask){
  138. global $wpdb;
  139. if($uptask == 'enable')
  140. $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='1' WHERE id='%d'", $id));
  141. elseif($uptask == 'disable')
  142. $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='0' WHERE id='%d'", $id));
  143. elseif($uptask == 'delete')
  144. $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."sharebar WHERE id=%d LIMIT 1", $id));
  145. }
  146.  
  147. function sharebar_init(){
  148. if(!is_admin()) wp_enqueue_script('sharebar', get_bloginfo('wpurl').'/wp-content/plugins/sharebar/js/sharebar.js',array('jquery'));
  149. }
  150.  
  151. function sharebar_header(){
  152. global $sharebar_options;
  153. foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option);
  154. if(function_exists('wp_enqueue_script') && (is_single() || is_page())) {
  155. echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/css/sharebar.css" type="text/css" media="screen" />';
  156. if($horizontal) $hori = 'true'; else $hori = 'false';
  157. if(!$width) $width = 1000;
  158. echo "\n"; ?><script type="text/javascript">jQuery(document).ready(function($) { $('.sharebar').sharebar({horizontal:'<?php echo $hori; ?>',swidth:'<?php echo $swidth; ?>',minwidth:<?php echo $width; ?>,position:'<?php echo $position; ?>',leftOffset:<?php echo $leftoffset; ?>,rightOffset:<?php echo $rightoffset; ?>}); });</script><?php echo "\n"; ?><!-- Sharebar Plugin by Monjurul Dolon (http://mdolon.com/) - more info at: http://devgrow.com/sharebar-wordpress-plugin --><?php echo "\n"; ?><?php
  159. }
  160. }
  161.  
  162. function sharebar_filter($input){
  163. global $post;
  164. $code = array('[title]','[url]','[author]','[twitter]');
  165. $values = array($post->post_title,get_permalink(),get_the_author(),get_option('sharebar_twitter_username'));
  166. return str_replace($code,$values,$input);
  167. }
  168.  
  169. function sharebar_admin_actions(){
  170. if(current_user_can('manage_options')) add_options_page("Sharebar", "Sharebar", 1, "Sharebar", "sharebar_menu");
  171. }
  172.  
  173. function sharebar_custom_boxes() {
  174. add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'post', 'side', 'low');
  175. add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'page', 'side', 'low');
  176. }
  177.  
  178. function sharebar_post_options(){
  179. global $post;
  180. $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true); ?>
  181. <p>
  182. <input name="sharebar_hide" id="sharebar_hide" type="checkbox" <?php checked(true, $sharebar_hide, true) ?> />
  183. <label for="sharebar_hide">Disable Sharebar on this post?</label>
  184. </p>
  185. <?php
  186. }
  187.  
  188. function sharebar_save_post_options($post_id) {
  189. if (!isset($_POST['sharebar_hide']) || empty($_POST['sharebar_hide'])) {
  190. delete_post_meta($post_id, 'sharebar_hide');
  191. return;
  192. }
  193. $post = get_post($post_id);
  194. if (!$post || $post->post_type == 'revision') return;
  195. update_post_meta($post_id, 'sharebar_hide', true);
  196. }
  197.  
  198. function sharebar_admin_head(){
  199. echo '
  200. <link rel="stylesheet" media="screen" type="text/css" href="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/css/colorpicker.css" />
  201. <script type="text/javascript" src="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/js/colorpicker.js"></script>
  202. <script type="text/javascript">
  203. jQuery(document).ready(function($) {
  204. var ids = ["sbg","sborder"];
  205. $.each(ids, function() {
  206. var id = this;
  207. $("#"+this).ColorPicker({
  208. onSubmit: function(hsb, hex, rgb, el) {
  209. $(el).val(hex);
  210. $(el).ColorPickerHide();
  211. },
  212. onBeforeShow: function () {
  213. $(this).ColorPickerSetColor(this.value);
  214. },
  215. onChange: function(hsb, hex, rgb, el) {
  216. $("#"+id).val(hex);
  217. }
  218. });
  219. });
  220. });
  221. </script>';
  222. }
  223.  
  224. function cleanInput($input) {
  225.  
  226. $search = array(
  227. '@<script[^>]*?>.*?</script>@si', // Strip out javascript
  228. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  229. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  230. '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
  231. );
  232.  
  233. $output = preg_replace($search, '', $input);
  234. return $output;
  235. }
  236.  
  237. function sanitize($input) {
  238. if (is_array($input)) {
  239. foreach($input as $var=>$val) {
  240. $output[$var] = sanitize($val);
  241. }
  242. }
  243. else {
  244. if (get_magic_quotes_gpc()) {
  245. $input = stripslashes($input);
  246. }
  247. $input = cleanInput($input);
  248. $output = mysql_real_escape_string($input);
  249. }
  250. return $output;
  251. }
  252.  
  253.  
  254. add_filter('the_content', 'sharebar_auto');
  255. add_action('init', 'sharebar_init');
  256. add_action('wp_head', 'sharebar_header');
  257. add_action('admin_head', 'sharebar_admin_head');
  258. add_action('activate_sharebar/sharebar.php', 'sharebar_install');
  259. add_action('admin_menu', 'sharebar_admin_actions');
  260. add_action('add_meta_boxes', 'sharebar_custom_boxes');
  261. add_action('draft_post', 'sharebar_save_post_options');
  262. add_action('publish_post', 'sharebar_save_post_options');
  263. add_action('save_post', 'sharebar_save_post_options');
  264.  
  265. ?>
Add Comment
Please, Sign In to add comment