PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/sharebar/sharebar.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 269 lines | 216 code | 26 blank | 27 comment | 36 complexity | 8fb4806f80c6a29952a30da11c786e49 MD5 | raw file
  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.5
  7. Author: Monjurul Dolon
  8. Author URI: http://mdolon.com/
  9. License: GPL2
  10. */
  11. /* Copyright 2010 Monjurul Dolon (email : md@devgrow.com)
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License, version 2, as
  14. published by the Free Software Foundation.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. $sharebar_options = array("auto_posts","auto_pages","horizontal","width","position","credit","leftoffset","rightoffset","swidth","twitter_username","sbg","sborder");
  24. function sharebar_install(){
  25. global $wpdb;
  26. $table = $wpdb->prefix."sharebar";
  27. if($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) {
  28. $structure = "CREATE TABLE $table (
  29. id mediumint(9) NOT NULL AUTO_INCREMENT,
  30. position mediumint(9) NOT NULL,
  31. enabled int(1) NOT NULL,
  32. name VARCHAR(80) NOT NULL,
  33. big text NOT NULL,
  34. small text NULL,
  35. UNIQUE KEY id (id)
  36. );";
  37. $wpdb->query($structure);
  38. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  39. 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>')");
  40. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  41. 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>')");
  42. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  43. 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>')");
  44. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  45. 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>')");
  46. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  47. 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>')");
  48. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  49. 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>')");
  50. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  51. 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>')");
  52. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  53. 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>')");
  54. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  55. 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>')");
  56. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  57. 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>')");
  58. $wpdb->query("INSERT INTO $table(enabled, position,name, big, small)
  59. 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>')");
  60. add_option('sharebar_auto_posts', 1);
  61. add_option('sharebar_auto_pages', 1);
  62. add_option('sharebar_horizontal', 1);
  63. add_option('sharebar_credit', 0);
  64. add_option('sharebar_minwidth','1000');
  65. add_option('sharebar_position','left');
  66. add_option('sharebar_leftoffset','20');
  67. add_option('sharebar_rightoffset','10');
  68. add_option('sharebar_swidth','65');
  69. add_option('sharebar_twitter_username','ThinkDevGrow');
  70. add_option('sharebar_bg','#ffffff');
  71. add_option('sharebar_border','#cccccc');
  72. }
  73. }
  74. function sharebar_reset(){
  75. global $wpdb;
  76. $table = $wpdb->prefix."sharebar";
  77. $wpdb->query("DROP TABLE IF EXISTS $table");
  78. sharebar_install();
  79. }
  80. function sharebar_menu(){
  81. global $wpdb, $sharebar_options;
  82. foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option);
  83. include 'sharebar-admin.php';
  84. }
  85. function sharebar_settings($settings){
  86. global $sharebar_options;
  87. foreach($sharebar_options as $option) update_option('sharebar_'.$option,$settings[$option]);
  88. }
  89. function sharebar_auto($content){
  90. if((get_option('sharebar_auto_posts') && is_single()) || (get_option('sharebar_auto_pages') && is_page())){ $str = sharebar(false); $str .= sharebar_horizontal(false); }
  91. $newcontent = $str.$content;
  92. return $newcontent;
  93. }
  94. function sharebar($print = true){
  95. global $wpdb, $post;
  96. $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true);
  97. $sbg = get_option('sharebar_sbg');
  98. $sborder = get_option('sharebar_sborder');
  99. if(empty($sharebar_hide)) {
  100. $credit = get_option('sharebar_credit');
  101. $str = '<ul id="sharebar" style="background:#'.$sbg.';border-color:#'.$sborder.';">';
  102. $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC", null)); $str .= "\n";
  103. foreach($results as $result){ $str .= '<li>'.sharebar_filter($result->big).'</li>'; }
  104. if($credit) $str .= '<li class="credit"><a href="http://devgrow.com/sharebar" target="_blank">Sharebar</a></li>';
  105. $str .= '</ul>';
  106. if($print) echo $str; else return $str;
  107. }
  108. }
  109. function sharebar_horizontal($print = true){
  110. if(get_option('sharebar_horizontal')){
  111. global $wpdb;
  112. $str = '<ul id="sharebarx">';
  113. $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC", null)); $str .= "\n";
  114. foreach($results as $result) { $str .= '<li>'.sharebar_filter($result->small).'</li>'; }
  115. $str .= '</ul>';
  116. if($print) echo $str; else return $str;
  117. }
  118. }
  119. function sharebar_button($name, $size = 'big'){
  120. global $wpdb;
  121. $item = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE name='$name'"));
  122. if($size == 'big') return stripslashes($item->big); else return stripslashes($item->small);
  123. }
  124. function sharebar_update_button($id, $uptask){
  125. global $wpdb;
  126. if($uptask == 'enable')
  127. $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='1' WHERE id='%d'", $id));
  128. elseif($uptask == 'disable')
  129. $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."sharebar SET enabled='0' WHERE id='%d'", $id));
  130. elseif($uptask == 'delete')
  131. $wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."sharebar WHERE id=%d LIMIT 1", $id));
  132. }
  133. function sharebar_init(){
  134. if(!is_admin() & !is_front_page()) {
  135. //wp_enqueue_script('sharebar', get_bloginfo('wpurl').'/wp-content/plugins/sharebar/js/sharebar.js',array('jquery'), '', true);
  136. //wp_enqueue_script('buttons', site_url().'/wp-content/themes/twentytwelve-child/js/buttons.js',array('jquery'), '', true);
  137. }
  138. }
  139. function sharebar_header(){
  140. global $sharebar_options;
  141. foreach($sharebar_options as $option) $$option = get_option('sharebar_'.$option);
  142. if(function_exists('wp_enqueue_script') && (is_single() || is_page())) {
  143. echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/css/sharebar.css" type="text/css" media="screen" />';
  144. if($horizontal) $hori = 'true'; else $hori = 'false';
  145. if(!$width) $width = 1000;
  146. echo "\n"; ?><script type="text/javascript">jQuery(document).ready(function($) { $('.zdgdsfgdf').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
  147. }
  148. }
  149. function sharebar_filter($input){
  150. global $post;
  151. $code = array('[title]','[url]','[author]','[twitter]');
  152. $values = array($post->post_title,get_permalink(),get_the_author(),get_option('sharebar_twitter_username'));
  153. return str_replace($code,$values,$input);
  154. }
  155. function sharebar_admin_actions(){
  156. if(current_user_can('manage_options')) add_options_page("Sharebar", "Sharebar", 1, "Sharebar", "sharebar_menu");
  157. }
  158. function sharebar_custom_boxes() {
  159. add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'post', 'side', 'low');
  160. add_meta_box( 'Sharebar', 'Sharebar Settings', 'sharebar_post_options', 'page', 'side', 'low');
  161. }
  162. function sharebar_post_options(){
  163. global $post;
  164. $sharebar_hide = get_post_meta($post->ID, 'sharebar_hide', true); ?>
  165. <p>
  166. <input name="sharebar_hide" id="sharebar_hide" type="checkbox" <?php checked(true, $sharebar_hide, true) ?> />
  167. <label for="sharebar_hide">Disable Sharebar on this post?</label>
  168. </p>
  169. <?php
  170. }
  171. function sharebar_save_post_options($post_id) {
  172. if (!isset($_POST['sharebar_hide']) || empty($_POST['sharebar_hide'])) {
  173. delete_post_meta($post_id, 'sharebar_hide');
  174. return;
  175. }
  176. $post = get_post($post_id);
  177. if (!$post || $post->post_type == 'revision') return;
  178. update_post_meta($post_id, 'sharebar_hide', true);
  179. }
  180. function sharebar_admin_head(){
  181. echo '
  182. <link rel="stylesheet" media="screen" type="text/css" href="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/css/colorpicker.css" />
  183. <script type="text/javascript" src="'.get_bloginfo('wpurl').'/wp-content/plugins/sharebar/js/colorpicker.js"></script>
  184. <script type="text/javascript">
  185. jQuery(document).ready(function($) {
  186. var ids = ["sbg","sborder"];
  187. $.each(ids, function() {
  188. var id = this;
  189. $("#"+this).ColorPicker({
  190. onSubmit: function(hsb, hex, rgb, el) {
  191. $(el).val(hex);
  192. $(el).ColorPickerHide();
  193. },
  194. onBeforeShow: function () {
  195. $(this).ColorPickerSetColor(this.value);
  196. },
  197. onChange: function(hsb, hex, rgb, el) {
  198. $("#"+id).val(hex);
  199. }
  200. });
  201. });
  202. });
  203. </script>';
  204. }
  205. function cleanInput($input) {
  206. $search = array(
  207. '@<script[^>]*?>.*?</script>@si', // Strip out javascript
  208. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  209. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  210. '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
  211. );
  212. $output = preg_replace($search, '', $input);
  213. return $output;
  214. }
  215. function sanitize($input) {
  216. if (is_array($input)) {
  217. foreach($input as $var=>$val) {
  218. $output[$var] = sanitize($val);
  219. }
  220. }
  221. else {
  222. if (get_magic_quotes_gpc()) {
  223. $input = stripslashes($input);
  224. }
  225. $input = cleanInput($input);
  226. $output = mysql_real_escape_string($input);
  227. }
  228. return $output;
  229. }
  230. add_filter('the_content', 'sharebar_auto');
  231. add_action('init', 'sharebar_init');
  232. //add_action('wp_head', 'sharebar_header');
  233. add_action('admin_head', 'sharebar_admin_head');
  234. add_action('activate_sharebar/sharebar.php', 'sharebar_install');
  235. add_action('admin_menu', 'sharebar_admin_actions');
  236. add_action('add_meta_boxes', 'sharebar_custom_boxes');
  237. add_action('draft_post', 'sharebar_save_post_options');
  238. add_action('publish_post', 'sharebar_save_post_options');
  239. add_action('save_post', 'sharebar_save_post_options');
  240. ?>