From 7e6ad5bbd97debdf473e09e953bddc00a12d9c8d Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 11:38:43 +0800 Subject: [PATCH 1/8] Add Admin Metabox for Love Button --- lib/admin.php | 19 +++++++ lib/sharrre/README.md | 120 +++++++++++++++++++++--------------------- 2 files changed, 79 insertions(+), 60 deletions(-) diff --git a/lib/admin.php b/lib/admin.php index 5666bc5..978ec6d 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -54,6 +54,7 @@ function __construct() { 'pinterest' => 1, 'linkedin' => 1, 'stumbleupon' => 1, + 'love' => 1, ) ); @@ -235,6 +236,7 @@ function metaboxes() { add_meta_box( 'genesis_simple_share_pinterest', __( 'Pinterest', 'genesis-simple-share' ), array( $this, 'pinterest' ), $this->pagehook, 'main' ); add_meta_box( 'genesis_simple_share_linkedin', __( 'Linkedin', 'genesis-simple-share' ), array( $this, 'linkedin' ), $this->pagehook, 'main' ); add_meta_box( 'genesis_simple_share_stumbleupon', __( 'StumbleUpon', 'genesis-simple-share' ), array( $this, 'stumbleupon' ), $this->pagehook, 'main' ); + add_meta_box( 'genesis_simple_share_love', __( 'Love', 'genesis-simple-share' ), array( $this, 'love' ), $this->pagehook, 'main' ); @@ -409,6 +411,23 @@ function linkedin() { $this->checkbox( $id , __( 'Use this button?', 'genesis-simple-share' ) ); } + + /** + * Create Love settings metabox output + * + * + * @since 0.1.0 + * + */ + function love() { + + $id = 'love'; + + $this->checkbox( $id , __( 'Use this button?', 'genesis-simple-share' ) ); + + //echo $this->sort_text; + + } /** * Outputs select field to select position for the icon diff --git a/lib/sharrre/README.md b/lib/sharrre/README.md index 60fdb7f..13884dd 100644 --- a/lib/sharrre/README.md +++ b/lib/sharrre/README.md @@ -1,60 +1,60 @@ -jQuery Sharrre Plugin -=== - -Make your sharing widget! -Sharrre is a jQuery plugin that allows you to create nice widgets sharing for Facebook, Twitter, Google Plus (with PHP script) and more. -More information on [Sharrre] (http://sharrre.com/#demos) - -Usage -=== - - $('#sharrre').sharrre({ - share: { - googlePlus: true, - facebook: true, - twitter: true - }, - url: 'http://sharrre.com' - }); - -Example -=== - -
- $(document).ready(function(){ - $('#demo1').sharrre({ - share: { - googlePlus: true, - facebook: true, - twitter: true, - delicious: true - }, - buttons: { - googlePlus: {size: 'tall'}, - facebook: {layout: 'box_count'}, - twitter: {count: 'vertical'}, - delicious: {size: 'tall'} - }, - hover: function(api, options){ - $(api.element).find('.buttons').show(); - }, - hide: function(api, options){ - $(api.element).find('.buttons').hide(); - } - }); - }); - - See example on [official website] (http://sharrre.com/#demos) - - -Dependencies -=== - -jQuery 1.7 - -Author -=== - -- [Julien Hany](http://hany.fr) -- [Twitter (@_JulienH)](http://twitter.com/_JulienH) -- [Google+](http://plus.google.com/111637545317893682325) +jQuery Sharrre Plugin +=== + +Make your sharing widget! +Sharrre is a jQuery plugin that allows you to create nice widgets sharing for Facebook, Twitter, Google Plus (with PHP script) and more. +More information on [Sharrre] (http://sharrre.com/#demos) + +Usage +=== + + $('#sharrre').sharrre({ + share: { + googlePlus: true, + facebook: true, + twitter: true + }, + url: 'http://sharrre.com' + }); + +Example +=== + +
+ $(document).ready(function(){ + $('#demo1').sharrre({ + share: { + googlePlus: true, + facebook: true, + twitter: true, + delicious: true + }, + buttons: { + googlePlus: {size: 'tall'}, + facebook: {layout: 'box_count'}, + twitter: {count: 'vertical'}, + delicious: {size: 'tall'} + }, + hover: function(api, options){ + $(api.element).find('.buttons').show(); + }, + hide: function(api, options){ + $(api.element).find('.buttons').hide(); + } + }); + }); + + See example on [official website] (http://sharrre.com/#demos) + + +Dependencies +=== + +jQuery 1.7 + +Author +=== + +- [Julien Hany](http://hany.fr) +- [Twitter (@_JulienH)](http://twitter.com/_JulienH) +- [Google+](http://plus.google.com/111637545317893682325) From a99c580932bfef461b99991ce47fbc1b50839436 Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 11:40:10 +0800 Subject: [PATCH 2/8] Love Metabox Styling --- lib/css/admin.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/css/admin.css b/lib/css/admin.css index 6a779ed..c873c1c 100644 --- a/lib/css/admin.css +++ b/lib/css/admin.css @@ -70,10 +70,12 @@ .genesis_page_genesis_simple_share_settings #genesis_simple_share_pinterest h3.hndle { background: #cb2127; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_linkedin h3.hndle { background: #035a87; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_stumbleupon h3.hndle { background: #eb4923; } +.genesis_page_genesis_simple_share_settings #genesis_simple_share_love h3.hndle { background: #ae1319; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_twitter h3.hndle:before { content: '\f202'; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_facebook h3.hndle:before { content: '\f204'; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_google_plus h3.hndle:before { content: '\f218'; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_pinterest h3.hndle:before { content: '\f209'; } .genesis_page_genesis_simple_share_settings #genesis_simple_share_linkedin h3.hndle:before { content: '\f207'; } -.genesis_page_genesis_simple_share_settings #genesis_simple_share_stumbleupon h3.hndle:before { content: '\f223'; } \ No newline at end of file +.genesis_page_genesis_simple_share_settings #genesis_simple_share_stumbleupon h3.hndle:before { content: '\f223'; } +.genesis_page_genesis_simple_share_settings #genesis_simple_share_love h3.hndle:before { content: '\f461'; } \ No newline at end of file From 380aa2a022cfc052f4d6489f1a2724f7a67abdcd Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 12:01:32 +0800 Subject: [PATCH 3/8] Add Love Button Preview --- lib/admin-icon-preview.php | 11 ++++++++++- lib/admin.php | 2 +- lib/front-end.php | 11 ++++++++++- lib/sharrre/jquery.sharrre.js | 22 ++++++++++++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/admin-icon-preview.php b/lib/admin-icon-preview.php index aee39d3..24cfc21 100644 --- a/lib/admin-icon-preview.php +++ b/lib/admin-icon-preview.php @@ -37,7 +37,7 @@ class Gensis_Simple_Share_Preview { function __construct() { $icons = get_option( 'genesis_simple_share_sort', array( - 'main' => 'genesis_simple_share_google_plus,genesis_simple_share_facebook,genesis_simple_share_twitter,genesis_simple_share_pinterest,genesis_simple_share_linkedin,genesis_simple_share_stumbleupon' + 'main' => 'genesis_simple_share_google_plus,genesis_simple_share_facebook,genesis_simple_share_twitter,genesis_simple_share_pinterest,genesis_simple_share_linkedin,genesis_simple_share_stumbleupon,genesis_simple_share_love' ) ); $icons = explode( ',', $icons['main'] ); @@ -70,6 +70,10 @@ function __construct() { case 'genesis_simple_share_stumbleupon': $icon_sort[] = 'stumbleupon'; break; + + case 'genesis_simple_share_love': + $icon_sort[] = 'love'; + break; } } @@ -171,6 +175,11 @@ function get_icon_output( $location, $icons = array() ){ $data_title = 'Pin'; break; + + case 'love' : + + $data_title = __('Love', 'genesis'); + break; default: diff --git a/lib/admin.php b/lib/admin.php index 978ec6d..46f628c 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -147,7 +147,7 @@ function scripts() { //use wp_enqueue_script() and wp_enqueue_style() to load scripts and styles wp_enqueue_script( 'genesis-simple-share-plugin-js', - plugins_url( 'sharrre/jquery.sharrre.min.js', __FILE__ ), + plugins_url( 'sharrre/jquery.sharrre.js', __FILE__ ), array( 'jquery' ), '0.1.0' ); diff --git a/lib/front-end.php b/lib/front-end.php index cc06ed9..bb0894e 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -39,7 +39,7 @@ class Gensis_Simple_Share_Front_End { function __construct() { $icons = get_option( 'genesis_simple_share_sort', array( - 'main' => 'genesis_simple_share_google_plus,genesis_simple_share_facebook,genesis_simple_share_twitter,genesis_simple_share_pinterest,genesis_simple_share_linkedin,genesis_simple_share_stumbleupon' + 'main' => 'genesis_simple_share_google_plus,genesis_simple_share_facebook,genesis_simple_share_twitter,genesis_simple_share_pinterest,genesis_simple_share_linkedin,genesis_simple_share_stumbleupon,genesis_simple_share_love' ) ); $icons = explode( ',', $icons['main'] ); @@ -73,6 +73,10 @@ function __construct() { $icon_sort[] = 'stumbleupon'; break; + case 'genesis_simple_share_love': + $icon_sort[] = 'love'; + break; + } } @@ -419,6 +423,11 @@ function get_icon_output( $location, $icons = array(), $force_show = false ){ $data_title = 'Pin'; break; + case 'love' : + + $data_title = __('Love', 'genesis'); + break; + default: $data_title = 'Share'; diff --git a/lib/sharrre/jquery.sharrre.js b/lib/sharrre/jquery.sharrre.js index e853855..95f4b5a 100644 --- a/lib/sharrre/jquery.sharrre.js +++ b/lib/sharrre/jquery.sharrre.js @@ -20,7 +20,8 @@ delicious: false, stumbleupon: false, linkedin: false, - pinterest: false + pinterest: false, + love: false }, shareTotal: 0, template: '', @@ -92,6 +93,12 @@ media: '', description: '', layout: 'horizontal' + }, + love: { ////pinterest.com/about/goodies/ + url: '', //if you need to personalize url button + media: '', + description: '', + layout: 'horizontal' } } }, @@ -111,7 +118,8 @@ //stumbleupon: "//www.stumbleupon.com/services/1.01/badge.getinfo?url={url}&format=jsonp&callback=?", stumbleupon: "", linkedin: "//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", - pinterest: "//api.pinterest.com/v1/urls/count.json?url={url}&callback=?" + pinterest: "//api.pinterest.com/v1/urls/count.json?url={url}&callback=?", + love: "#", }, /* Load share buttons asynchronously ================================================== */ @@ -260,6 +268,16 @@ li.src = '//assets.pinterest.com/js/pinit.js'; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); })(); + }, + love : function(self){ + var sett = self.options.buttons.pinterest; + $(self.element).find('.buttons').append(''); + + // (function() { + // var li = document.createElement('script');li.type = 'text/javascript';li.async = true; + // li.src = '//assets.pinterest.com/js/pinit.js'; + // var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); + // })(); } }, /* Tracking for Google Analytics From f487fa0494d9df70d4148287118e5c5781eec721 Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 12:26:07 +0800 Subject: [PATCH 4/8] Show Love Icon on Frontend --- lib/admin.php | 7 +++++++ lib/css/share.css | 13 +++++++++++++ lib/front-end.php | 19 ++++++++++++++----- lib/sharrre/jquery.sharrre.js | 16 +++++++--------- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/lib/admin.php b/lib/admin.php index 46f628c..6f541a3 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -175,6 +175,13 @@ function scripts() { array(), '0.1.0' ); + + $front_end = array( + 'nonce' => wp_create_nonce( 'genesis_love' ), + 'ajaxurl' => admin_url('admin-ajax.php'), + 'love_text' => apply_filters('genesis_simple_love_text', __('Love', 'genesis') ) + ); + wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $front_end ); } diff --git a/lib/css/share.css b/lib/css/share.css index fc38bc6..c8cf4a3 100755 --- a/lib/css/share.css +++ b/lib/css/share.css @@ -220,6 +220,7 @@ .pinterest .share:before { content: '\f209'; } .linkedin .share:before { content: '\f207'; } .stumbleupon .share:before { content: '\f223'; } +.love .share:before { content: '\f461'; } .share-small .pinterest .share:before { font-size: 12px; @@ -316,6 +317,10 @@ .share-filled .stumbleupon .count, .share-filled .stumbleupon .count:hover { color: #eb4923; border: 1px solid #eb4923; } +.share-filled .love .share { background: #ae1319; } +.share-filled .love .count, +.share-filled .love .count:hover { color: #ae1319; border: 1px solid #ae1319; } + .share-filled .twitter:hover .count { background: #09b0ed !important; } .share-filled .facebook:hover .count { background: #3d5a98 !important; } .share-filled .googlePlus:hover .count { background: #dd4c39 !important; } @@ -323,6 +328,7 @@ .share-filled .youtube:hover .count { background: #cc181e !important; } .share-filled .pinterest:hover .count { background: #cb2127 !important; } .share-filled .stumbleupon:hover .count { background: #eb4923 !important; } +.share-filled .love:hover .count { background: #ae1319 !important; } .share-filled .sharrre:hover .count { color: #fff; @@ -357,6 +363,10 @@ .share-outlined .stumbleupon .count, .share-outlined .stumbleupon .count:hover { border: 1px solid #eb4923; color: #eb4923; } +.share-outlined .love .share, +.share-outlined .love .count, +.share-outlined .love .count:hover { border: 1px solid #ae1319; color: #ae1319; } + .share-outlined.share-small .share, .share-outlined.share-medium .share { border-right: none !important; } @@ -386,6 +396,9 @@ .share-outlined .stumbleupon:hover .share, .share-outlined .stumbleupon:hover .count { background: #eb4923; } +.share-outlined .love:hover .share, +.share-outlined .love:hover .count { background: #ae1319; color: #fff; } + .share-outlined .sharrre:hover .count, .share-outlined .sharrre:hover .share { color: #fff; diff --git a/lib/front-end.php b/lib/front-end.php index bb0894e..afe445d 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -106,7 +106,7 @@ function load_scripts() { //use wp_enqueue_script() and wp_enqueue_style() to load scripts and styles wp_register_script( 'genesis-simple-share-plugin-js', - $url . 'sharrre/jquery.sharrre.min.js', + $url . 'sharrre/jquery.sharrre.js', array( 'jquery' ), '0.1.0' ); @@ -143,6 +143,13 @@ function load_scripts() { wp_enqueue_script( 'genesis-simple-share-waypoint-js' ); } + $atts = array( + 'nonce' => wp_create_nonce( 'genesis_love' ), + 'ajaxurl' => admin_url('admin-ajax.php'), + 'love_text' => apply_filters('genesis_simple_love_text', __('Love', 'genesis') ) + ); + wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $atts ); + } /** @@ -434,13 +441,14 @@ function get_icon_output( $location, $icons = array(), $force_show = false ){ } - $buttons[] = sprintf( '
', + $buttons[] = sprintf( '
', $icon, $div_id, get_permalink( $id ), wp_get_shortlink( $id ), $description, - $data_title + $data_title, + $id ); } @@ -485,14 +493,15 @@ function get_hide_icon_output( $location, $icons = array() ){ $div_id = 'share-'. $location .'-' . $id; - $div = sprintf( '', + $div = sprintf( '', $location, $this->appearance, $this->size, $div_id, get_permalink( $id ), wp_get_shortlink( $id ), - the_title_attribute( array( 'echo' => false ) ) + the_title_attribute( array( 'echo' => false ) ), + $id ); $shares = array(); diff --git a/lib/sharrre/jquery.sharrre.js b/lib/sharrre/jquery.sharrre.js index 95f4b5a..19a561d 100644 --- a/lib/sharrre/jquery.sharrre.js +++ b/lib/sharrre/jquery.sharrre.js @@ -119,7 +119,7 @@ stumbleupon: "", linkedin: "//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", pinterest: "//api.pinterest.com/v1/urls/count.json?url={url}&callback=?", - love: "#", + love: simple_love.ajaxurl, }, /* Load share buttons asynchronously ================================================== */ @@ -271,13 +271,7 @@ }, love : function(self){ var sett = self.options.buttons.pinterest; - $(self.element).find('.buttons').append(''); - - // (function() { - // var li = document.createElement('script');li.type = 'text/javascript';li.async = true; - // li.src = '//assets.pinterest.com/js/pinit.js'; - // var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li, s); - // })(); + $(self.element).find('.buttons').append(''); } }, /* Tracking for Google Analytics @@ -359,6 +353,9 @@ }, pinterest: function(opt){ window.open('//pinterest.com/pin/create/button/?url='+encodeURIComponent((opt.buttons.pinterest.url !== '' ? opt.buttons.pinterest.url : opt.url))+'&media='+encodeURIComponent(opt.buttons.pinterest.media)+'&description='+opt.buttons.pinterest.description, 'pinterest', 'toolbar=no,width=700,height=300'); + }, + love: function(opt){ + } }; @@ -646,7 +643,8 @@ delicious: {site: 'delicious', action: 'add'}, stumbleupon: {site: 'stumbleupon', action: 'add'}, linkedin: {site: 'linkedin', action: 'share'}, - pinterest: {site: 'pinterest', action: 'pin'} + pinterest: {site: 'pinterest', action: 'pin'}, + love: {site: 'love', action: 'love'} }; _gaq.push(['_trackSocial', tracking[site].site, tracking[site].action]); } From 50a65e219ba58a14b4c40e9177241331b8fdc3cf Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 13:33:00 +0800 Subject: [PATCH 5/8] JS Changes --- lib/ajax.php | 67 +++++++++++++++++++++++++++++++++++ lib/front-end.php | 10 +++--- lib/sharrre/jquery.sharrre.js | 25 ++++++++++--- plugin.php | 6 +++- 4 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 lib/ajax.php diff --git a/lib/ajax.php b/lib/ajax.php new file mode 100644 index 0000000..d94b97a --- /dev/null +++ b/lib/ajax.php @@ -0,0 +1,67 @@ +This plugin requires Genesis Simple Share. Thanks! +Version: 1.0 +Author: phpbits +Author URI: http://codecanyon.net/user/phpbits/portfolio?ref=phpbits +License: GPL2 +*/ +if(!class_exists('PHPBITS_GenesisSimpleLove')): + class PHPBITS_GenesisSimpleLove{ + function __construct(){ + add_action("wp_ajax_genesis_simple_love", array( $this, "ajax_love" )); + add_action("wp_ajax_nopriv_genesis_simple_love", array( $this, "ajax_love" )); + } + + function ajax_love() { + $result = array(); + + $nonce = $_REQUEST['nonce']; + $post_id = url_to_postid( $_REQUEST['data_url'] );; + $loved = array(); + + if ( !wp_verify_nonce( $nonce, "genesis_love")) { + exit("You don't have any power here!"); + } + + $handle = ''; + if(isset($_COOKIE['genesis_simple_love'])){ + $loved = @unserialize(base64_decode($_COOKIE['genesis_simple_love'])); + } + + //get love + if(isset($_REQUEST['data']) && 'getCount' == $_REQUEST['data']){ + echo '{"url":"'. $_REQUEST['data_url'] .'","count":"'. (int) get_post_meta($post_id, '_genesis_simple_love_', true) .'"}'; + die(); + } + + //save love + if ( is_array($loved) && !in_array( $post_id, $loved ) ){ + $loved[] = $post_id; + $post_loved = (int) get_post_meta($post_id, '_genesis_simple_love_', true); + $post_loved++; + update_post_meta($post_id, '_genesis_simple_love_', $post_loved); + + $_COOKIE['genesis_simple_love'] = base64_encode(serialize($loved)); + setcookie('genesis_simple_love', $_COOKIE['genesis_simple_love'] , time()+(10*365*24*60*60),'/'); + + $result['type'] = 'success'; + $result['message'] = apply_filters('genesis_simple_love_message', __('Thank You for loving this!', 'genesis-simple-love') ); + $result['count'] = $post_loved; + $result['id'] = $post_id; + }else{ + $post_loved = (int) get_post_meta($post_id, '_genesis_simple_love_', true); + $result['type'] = 'error'; + $result['message'] = apply_filters('genesis_simple_loved', __('You already loved this. Thanks!', 'genesis-simple-love') ); + $result['count'] = $post_loved; + $result['id'] = $post_id; + } + + echo $result = json_encode($result); + die(); + } + } + new PHPBITS_GenesisSimpleLove(); +endif; \ No newline at end of file diff --git a/lib/front-end.php b/lib/front-end.php index afe445d..c0a8527 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -441,14 +441,13 @@ function get_icon_output( $location, $icons = array(), $force_show = false ){ } - $buttons[] = sprintf( '
', + $buttons[] = sprintf( '
', $icon, $div_id, get_permalink( $id ), wp_get_shortlink( $id ), $description, - $data_title, - $id + $data_title ); } @@ -493,15 +492,14 @@ function get_hide_icon_output( $location, $icons = array() ){ $div_id = 'share-'. $location .'-' . $id; - $div = sprintf( '', + $div = sprintf( '', $location, $this->appearance, $this->size, $div_id, get_permalink( $id ), wp_get_shortlink( $id ), - the_title_attribute( array( 'echo' => false ) ), - $id + the_title_attribute( array( 'echo' => false ) ) ); $shares = array(); diff --git a/lib/sharrre/jquery.sharrre.js b/lib/sharrre/jquery.sharrre.js index 19a561d..c66fdc6 100644 --- a/lib/sharrre/jquery.sharrre.js +++ b/lib/sharrre/jquery.sharrre.js @@ -119,7 +119,7 @@ stumbleupon: "", linkedin: "//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?", pinterest: "//api.pinterest.com/v1/urls/count.json?url={url}&callback=?", - love: simple_love.ajaxurl, + love: simple_love.ajaxurl + '?action=genesis_simple_love&data=getCount&nonce=' + simple_love.nonce +'&data_url={url}', }, /* Load share buttons asynchronously ================================================== */ @@ -270,8 +270,8 @@ })(); }, love : function(self){ - var sett = self.options.buttons.pinterest; - $(self.element).find('.buttons').append(''); + var sett = self.options.buttons.love; + $(self.element).find('.buttons').append(''); } }, /* Tracking for Google Analytics @@ -325,6 +325,9 @@ }, pinterest: function(){ //if somenone find a solution, mail me ! + }, + love: function(){ + //if somenone find a solution, mail me ! } }, /* Popup for each social network @@ -355,7 +358,19 @@ window.open('//pinterest.com/pin/create/button/?url='+encodeURIComponent((opt.buttons.pinterest.url !== '' ? opt.buttons.pinterest.url : opt.url))+'&media='+encodeURIComponent(opt.buttons.pinterest.media)+'&description='+opt.buttons.pinterest.description, 'pinterest', 'toolbar=no,width=700,height=300'); }, love: function(opt){ - + $.ajax({ + type : "post", + dataType : "json", + url : simple_love.ajaxurl, + data : {action: "genesis_simple_love", data_url : opt.url, nonce: simple_love.nonce}, + success: function(response){ + if(response.type == 'error'){ + // console.log( response.id ); + $('#love-before-' + response.id + ' .count , #love-after-2' + response.id + ' .count').html( response.count ); + } + alert(response.message); + } + }); } }; @@ -476,7 +491,7 @@ if(this.options.buttons[name].urlCount === true && this.options.buttons[name].url !== ''){ url = urlJson[name].replace('{url}', this.options.buttons[name].url); } - //console.log('name : ' + name + ' - url : '+url); //debug + // console.log('name : ' + name + ' - url : '+url); //debug if(url != '' && self.options.urlCurl !== ''){ //urlCurl = '' if you don't want to used PHP script but used social button $.getJSON(url, function(json){ if( null != json ){ diff --git a/plugin.php b/plugin.php index 674199d..e2b713e 100644 --- a/plugin.php +++ b/plugin.php @@ -22,6 +22,7 @@ define( 'GENESIS_SIMPLE_SHARE_LIB', dirname( __FILE__ ) . '/lib/' ); add_action( 'genesis_init', 'genesis_simple_share_init', 99 ); + /** * Loads plugin text domain and required files. Uses genesis_init to ensure Genesis functions are available * @@ -39,9 +40,12 @@ function genesis_simple_share_init() { require_once( GENESIS_SIMPLE_SHARE_LIB . 'admin.php' ); require_once( GENESIS_SIMPLE_SHARE_LIB . 'post-meta.php' ); } - else + else{ require_once( GENESIS_SIMPLE_SHARE_LIB . 'front-end.php' ); + } //require_once( GENESIS_SIMPLE_SHArE_LIB . 'functions.php' ); } + +require_once( GENESIS_SIMPLE_SHARE_LIB . 'ajax.php' ); From fd0731cf886cb8fb34740e03f290fe47b02b0ae4 Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 15:30:06 +0800 Subject: [PATCH 6/8] Minify JS --- lib/admin.php | 6 ++--- lib/front-end.php | 2 +- lib/sharrre/jquery.sharrre.min.js | 43 +------------------------------ 3 files changed, 5 insertions(+), 46 deletions(-) diff --git a/lib/admin.php b/lib/admin.php index 6f541a3..586f3ab 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -147,7 +147,7 @@ function scripts() { //use wp_enqueue_script() and wp_enqueue_style() to load scripts and styles wp_enqueue_script( 'genesis-simple-share-plugin-js', - plugins_url( 'sharrre/jquery.sharrre.js', __FILE__ ), + plugins_url( 'sharrre/jquery.sharrre.min.js', __FILE__ ), array( 'jquery' ), '0.1.0' ); @@ -176,12 +176,12 @@ function scripts() { '0.1.0' ); - $front_end = array( + $atts = array( 'nonce' => wp_create_nonce( 'genesis_love' ), 'ajaxurl' => admin_url('admin-ajax.php'), 'love_text' => apply_filters('genesis_simple_love_text', __('Love', 'genesis') ) ); - wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $front_end ); + wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $atts ); } diff --git a/lib/front-end.php b/lib/front-end.php index c0a8527..1f47f31 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -106,7 +106,7 @@ function load_scripts() { //use wp_enqueue_script() and wp_enqueue_style() to load scripts and styles wp_register_script( 'genesis-simple-share-plugin-js', - $url . 'sharrre/jquery.sharrre.js', + $url . 'sharrre/jquery.sharrre.min.js', array( 'jquery' ), '0.1.0' ); diff --git a/lib/sharrre/jquery.sharrre.min.js b/lib/sharrre/jquery.sharrre.min.js index 1c38d99..9319b26 100644 --- a/lib/sharrre/jquery.sharrre.min.js +++ b/lib/sharrre/jquery.sharrre.min.js @@ -1,42 +1 @@ -;(function($,window,document,undefined){var pluginName='sharrre',defaults={className:'sharrre',share:{googlePlus:false,facebook:false,twitter:false,digg:false,delicious:false,stumbleupon:false,linkedin:false,pinterest:false},shareTotal:0,template:'',title:'',url:document.location.href,text:document.title,urlCurl:'sharrre.php',count:{},total:0,shorterTotal:true,enableHover:true,enableCounter:true,enableTracking:false,hover:function(){},hide:function(){},click:function(){},render:function(){},buttons:{googlePlus:{url:'',urlCount:false,size:'medium',lang:'en-US',annotation:''},facebook:{url:'',urlCount:false,action:'like',layout:'button_count',width:'',send:'false',faces:'false',colorscheme:'',font:'',lang:'en_US'},twitter:{url:'',urlCount:false,count:'horizontal',hashtags:'',via:'',related:'',lang:'en'},digg:{url:'',urlCount:false,type:'DiggCompact'},delicious:{url:'',urlCount:false,size:'medium'},stumbleupon:{url:'',urlCount:false,layout:'1'},linkedin:{url:'',urlCount:false,counter:''},pinterest:{url:'',media:'',description:'',layout:'horizontal'}}},urlJson={googlePlus:"",facebook:"https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",twitter:"//cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",digg:"//services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",delicious:'//feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?',stumbleupon:"",linkedin:"//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",pinterest:"//api.pinterest.com/v1/urls/count.json?url={url}&callback=?"},loadButton={googlePlus:function(self){var sett=self.options.buttons.googlePlus;$(self.element).find('.buttons').append('
');window.___gcfg={lang:self.options.buttons.googlePlus.lang};var loading=0;if(typeof gapi==='undefined'&&loading==0){loading=1;(function(){var po=document.createElement('script');po.type='text/javascript';po.async=true;po.src='//apis.google.com/js/plusone.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);})();} -else{gapi.plusone.go();}},facebook:function(self){var sett=self.options.buttons.facebook;$(self.element).find('.buttons').append('');var loading=0;if(typeof FB==='undefined'&&loading==0){loading=1;(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id)){return;} -js=d.createElement(s);js.id=id;js.src='//connect.facebook.net/'+sett.lang+'/all.js#xfbml=1';fjs.parentNode.insertBefore(js,fjs);}(document,'script','facebook-jssdk'));} -else{FB.XFBML.parse();}},twitter:function(self){var sett=self.options.buttons.twitter;$(self.element).find('.buttons').append('');var loading=0;if(typeof twttr==='undefined'&&loading==0){loading=1;(function(){var twitterScriptTag=document.createElement('script');twitterScriptTag.type='text/javascript';twitterScriptTag.async=true;twitterScriptTag.src='//platform.twitter.com/widgets.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(twitterScriptTag,s);})();} -else{$.ajax({url:'//platform.twitter.com/widgets.js',dataType:'script',cache:true});}},digg:function(self){var sett=self.options.buttons.digg;$(self.element).find('.buttons').append('
');var loading=0;if(typeof __DBW==='undefined'&&loading==0){loading=1;(function(){var s=document.createElement('SCRIPT'),s1=document.getElementsByTagName('SCRIPT')[0];s.type='text/javascript';s.async=true;s.src='//widgets.digg.com/buttons.js';s1.parentNode.insertBefore(s,s1);})();}},delicious:function(self){if(self.options.buttons.delicious.size=='tall'){var css='width:50px;',cssCount='height:35px;width:50px;font-size:15px;line-height:35px;',cssShare='height:18px;line-height:18px;margin-top:3px;';} -else{var css='width:93px;',cssCount='float:right;padding:0 3px;height:20px;width:26px;line-height:20px;',cssShare='float:left;height:20px;line-height:20px;';} -var count=self.shorterTotal(self.options.count.delicious);if(typeof count==="undefined"){count=0;} -$(self.element).find('.buttons').append('
'+'
'+count+'
'+'
'+'Delicious Add
');$(self.element).find('.delicious').on('click',function(){self.openPopup('delicious');});},stumbleupon:function(self){var sett=self.options.buttons.stumbleupon;$(self.element).find('.buttons').append('
');var loading=0;if(typeof STMBLPN==='undefined'&&loading==0){loading=1;(function(){var li=document.createElement('script');li.type='text/javascript';li.async=true;li.src='//platform.stumbleupon.com/1/widgets.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li,s);})();s=window.setTimeout(function(){if(typeof STMBLPN!=='undefined'){STMBLPN.processWidgets();clearInterval(s);}},500);} -else{STMBLPN.processWidgets();}},linkedin:function(self){var sett=self.options.buttons.linkedin;$(self.element).find('.buttons').append('
');var loading=0;if(typeof window.IN==='undefined'&&loading==0){loading=1;(function(){var li=document.createElement('script');li.type='text/javascript';li.async=true;li.src='//platform.linkedin.com/in.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li,s);})();} -else{window.IN.init();}},pinterest:function(self){var sett=self.options.buttons.pinterest;$(self.element).find('.buttons').append('');(function(){var li=document.createElement('script');li.type='text/javascript';li.async=true;li.src='//assets.pinterest.com/js/pinit.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li,s);})();}},tracking={googlePlus:function(){},facebook:function(){fb=window.setInterval(function(){if(typeof FB!=='undefined'){FB.Event.subscribe('edge.create',function(targetUrl){_gaq.push(['_trackSocial','facebook','like',targetUrl]);});FB.Event.subscribe('edge.remove',function(targetUrl){_gaq.push(['_trackSocial','facebook','unlike',targetUrl]);});FB.Event.subscribe('message.send',function(targetUrl){_gaq.push(['_trackSocial','facebook','send',targetUrl]);});clearInterval(fb);}},1000);},twitter:function(){tw=window.setInterval(function(){if(typeof twttr!=='undefined'){twttr.events.bind('tweet',function(event){if(event){_gaq.push(['_trackSocial','twitter','tweet']);}});clearInterval(tw);}},1000);},digg:function(){},delicious:function(){},stumbleupon:function(){},linkedin:function(){function LinkedInShare(){_gaq.push(['_trackSocial','linkedin','share']);}},pinterest:function(){}},popup={googlePlus:function(opt){window.open("https://plus.google.com/share?hl="+opt.buttons.googlePlus.lang+"&url="+encodeURIComponent((opt.buttons.googlePlus.url!==''?opt.buttons.googlePlus.url:opt.url)),"","toolbar=0, status=0, width=900, height=500");},facebook:function(opt){window.open("//www.facebook.com/sharer/sharer.php?u="+encodeURIComponent((opt.buttons.facebook.url!==''?opt.buttons.facebook.url:opt.url))+"&t="+opt.text+"","","toolbar=0, status=0, width=900, height=500");},twitter:function(opt){window.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(opt.text)+"&url="+encodeURIComponent((opt.buttons.twitter.url!==''?opt.buttons.twitter.url:opt.url))+(opt.buttons.twitter.via!==''?'&via='+opt.buttons.twitter.via:''),"","toolbar=0, status=0, width=650, height=360");},digg:function(opt){window.open("//digg.com/tools/diggthis/submit?url="+encodeURIComponent((opt.buttons.digg.url!==''?opt.buttons.digg.url:opt.url))+"&title="+opt.text+"&related=true&style=true","","toolbar=0, status=0, width=650, height=360");},delicious:function(opt){window.open('//www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent((opt.buttons.delicious.url!==''?opt.buttons.delicious.url:opt.url))+'&title='+opt.text,'delicious','toolbar=no,width=550,height=550');},stumbleupon:function(opt){window.open('//www.stumbleupon.com/badge/?url='+encodeURIComponent((opt.buttons.delicious.url!==''?opt.buttons.delicious.url:opt.url)),'stumbleupon','toolbar=no,width=550,height=550');},linkedin:function(opt){window.open('https://www.linkedin.com/cws/share?url='+encodeURIComponent((opt.buttons.delicious.url!==''?opt.buttons.delicious.url:opt.url))+'&token=&isFramed=true','linkedin','toolbar=no,width=550,height=550');},pinterest:function(opt){window.open('//pinterest.com/pin/create/button/?url='+encodeURIComponent((opt.buttons.pinterest.url!==''?opt.buttons.pinterest.url:opt.url))+'&media='+encodeURIComponent(opt.buttons.pinterest.media)+'&description='+opt.buttons.pinterest.description,'pinterest','toolbar=no,width=700,height=300');}};function Plugin(element,options){this.element=element;this.options=$.extend(true,{},defaults,options);this.options.share=options.share;this._defaults=defaults;this._name=pluginName;this.init();};Plugin.prototype.init=function(){var self=this;if(this.options.urlCurl!==''){urlJson.googlePlus=this.options.urlCurl+'?url={url}&type=googlePlus';urlJson.stumbleupon=this.options.urlCurl+'?url={url}&type=stumbleupon';} -$(this.element).addClass(this.options.className);if(typeof $(this.element).data('title')!=='undefined'){this.options.title=$(this.element).attr('data-title');} -if(typeof $(this.element).data('url')!=='undefined'){this.options.url=$(this.element).data('url');} -if(typeof $(this.element).data('urlalt')!=='undefined'){this.options.urlalt=$(this.element).data('urlalt');} -if(typeof $(this.element).data('text')!=='undefined'){this.options.text=$(this.element).data('text');} -$.each(this.options.share,function(name,val){if(val===true){self.options.shareTotal++;}});if(self.options.enableCounter===true){$.each(this.options.share,function(name,val){if(val===true){try{self.getSocialJson(name);self.getSocialJson(getSocialAltJson);}catch(e){}}});} -else if(self.options.template!==''){this.options.render(this,this.options);} -else{this.loadButtons();} -$(this.element).hover(function(){if($(this).find('.buttons').length===0&&self.options.enableHover===true){self.loadButtons();} -self.options.hover(self,self.options);},function(){self.options.hide(self,self.options);});$(this.element).click(function(){self.options.click(self,self.options);return false;});};Plugin.prototype.loadButtons=function(){var self=this;$(this.element).append('
');$.each(self.options.share,function(name,val){if(val==true){loadButton[name](self);if(self.options.enableTracking===true){tracking[name]();}}});};Plugin.prototype.getSocialJson=function(name){var self=this,count=0,url=urlJson[name].replace('{url}',encodeURIComponent(this.options.url));if('twitter'==name){self.options.hideCount=1;self.renderer();self.options.count[name]=0;self.rendererPerso();}else{self.options.hideCount=0;if(this.options.buttons[name].urlCount===true&&this.options.buttons[name].url!==''){url=urlJson[name].replace('{url}',this.options.buttons[name].url);} -if(url!=''&&self.options.urlCurl!==''){$.getJSON(url,function(json){if(null!=json){if(typeof json.count!=="undefined"){var temp=json.count+'';temp=temp.replace('\u00c2\u00a0','');count+=parseInt(temp,10);} -else if(json.data&&json.data.length>0&&typeof json.data[0].total_count!=="undefined"){count+=parseInt(json.data[0].total_count,10);} -else if(typeof json[0]!=="undefined"){count+=parseInt(json[0].total_posts,10);} -else if(typeof json[0]!=="undefined"){} -self.options.count[name]=count;self.options.total+=count;self.renderer();self.rendererPerso();} -else{self.renderer();self.options.count[name]=0;self.rendererPerso();}}).fail(function(){self.options.hideCount=1;self.renderer();self.options.count[name]=0;self.rendererPerso();});} -else{self.renderer();self.options.count[name]=0;self.rendererPerso();}}};Plugin.prototype.getSocialAltJson=function(name){var self=this,count=0,url=urlJson[name].replace('{url}',encodeURIComponent(this.options.urlalt));self.options.hideCount=0;if(this.options.buttons[name].urlCount===true&&this.options.buttons[name].url!==''){url=urlJson[name].replace('{url}',this.options.buttons[name].url);} -if(url!=''&&self.options.urlCurl!==''){$.getJSON(url,function(json){if(null!=json){if(typeof json.count!=="undefined"){var temp=json.count+'';temp=temp.replace('\u00c2\u00a0','');count+=parseInt(temp,10);} -else if(json.data&&json.data.length>0&&typeof json.data[0].total_count!=="undefined"){count+=parseInt(json.data[0].total_count,10);} -else if(typeof json[0]!=="undefined"){count+=parseInt(json[0].total_posts,10);} -else if(typeof json[0]!=="undefined"){} -self.options.count[name]+=count;self.options.total+=count;self.renderer();self.rendererPerso();} -else{self.renderer();self.rendererPerso();}}).fail(function(){self.renderer();self.rendererPerso();});} -else{self.renderer();self.rendererPerso();}};Plugin.prototype.rendererPerso=function(){var shareCount=0;for(e in this.options.count){shareCount++;} -if(shareCount===this.options.shareTotal){this.options.render(this,this.options);}};Plugin.prototype.renderer=function(){var total=this.options.total,template=this.options.template -hideCount=this.options.hideCount;if(hideCount){$(this.element).html('
'+ -(this.options.title!==''?'':'')+'
');} -else{if(this.options.shorterTotal===true){total=this.shorterTotal(total);} -if(template!==''){template=template.replace('{total}',total);$(this.element).html(template);} -else{$(this.element).html('
'+total+''+ -(this.options.title!==''?'':'')+'
');}}};Plugin.prototype.shorterTotal=function(num){if(num>=1e6){num=(num/1e6).toFixed(2)+"M"}else if(num>=1e3){num=(num/1e3).toFixed(1)+"k"} -return num;};Plugin.prototype.openPopup=function(site){popup[site](this.options);if(this.options.enableTracking===true){var tracking={googlePlus:{site:'Google',action:'+1'},facebook:{site:'facebook',action:'like'},twitter:{site:'twitter',action:'tweet'},digg:{site:'digg',action:'add'},delicious:{site:'delicious',action:'add'},stumbleupon:{site:'stumbleupon',action:'add'},linkedin:{site:'linkedin',action:'share'},pinterest:{site:'pinterest',action:'pin'}};_gaq.push(['_trackSocial',tracking[site].site,tracking[site].action]);}};Plugin.prototype.simulateClick=function(){var html=$(this.element).html();$(this.element).html(html.replace(this.options.total,this.options.total+1));};Plugin.prototype.update=function(url,text){if(url!==''){this.options.url=url;} -if(text!==''){this.options.text=text;}};$.fn[pluginName]=function(options){var args=arguments;if(options===undefined||typeof options==='object'){return this.each(function(){if(!$.data(this,'plugin_'+pluginName)){$.data(this,'plugin_'+pluginName,new Plugin(this,options));}});}else if(typeof options==='string'&&options[0]!=='_'&&options!=='init'){return this.each(function(){var instance=$.data(this,'plugin_'+pluginName);if(instance instanceof Plugin&&typeof instance[options]==='function'){instance[options].apply(instance,Array.prototype.slice.call(args,1));}});}};})(jQuery,window,document); +!function(t,o,n,i){function a(e,o){this.element=e,this.options=t.extend(!0,{},l,o),this.options.share=o.share,this._defaults=l,this._name=r,this.init()}var r="sharrre",l={className:"sharrre",share:{googlePlus:!1,facebook:!1,twitter:!1,digg:!1,delicious:!1,stumbleupon:!1,linkedin:!1,pinterest:!1,love:!1},shareTotal:0,template:"",title:"",url:n.location.href,text:n.title,urlCurl:"sharrre.php",count:{},total:0,shorterTotal:!0,enableHover:!0,enableCounter:!0,enableTracking:!1,hover:function(){},hide:function(){},click:function(){},render:function(){},buttons:{googlePlus:{url:"",urlCount:!1,size:"medium",lang:"en-US",annotation:""},facebook:{url:"",urlCount:!1,action:"like",layout:"button_count",width:"",send:"false",faces:"false",colorscheme:"",font:"",lang:"en_US"},twitter:{url:"",urlCount:!1,count:"horizontal",hashtags:"",via:"",related:"",lang:"en"},digg:{url:"",urlCount:!1,type:"DiggCompact"},delicious:{url:"",urlCount:!1,size:"medium"},stumbleupon:{url:"",urlCount:!1,layout:"1"},linkedin:{url:"",urlCount:!1,counter:""},pinterest:{url:"",media:"",description:"",layout:"horizontal"},love:{url:"",media:"",description:"",layout:"horizontal"}}},u={googlePlus:"",facebook:"https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",twitter:"//cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",digg:"//services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",delicious:"//feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?",stumbleupon:"",linkedin:"//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",pinterest:"//api.pinterest.com/v1/urls/count.json?url={url}&callback=?",love:simple_love.ajaxurl+"?action=genesis_simple_love&data=getCount&nonce="+simple_love.nonce+"&data_url={url}"},c={googlePlus:function(e){var i=e.options.buttons.googlePlus;t(e.element).find(".buttons").append('
'),o.___gcfg={lang:e.options.buttons.googlePlus.lang};var s=0;"undefined"==typeof gapi&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//apis.google.com/js/plusone.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):gapi.plusone.go()},facebook:function(e){var o=e.options.buttons.facebook;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof FB&&0==i?(i=1,function(t,e,n){var i,s=t.getElementsByTagName(e)[0];t.getElementById(n)||(i=t.createElement(e),i.id=n,i.src="//connect.facebook.net/"+o.lang+"/all.js#xfbml=1",s.parentNode.insertBefore(i,s))}(n,"script","facebook-jssdk")):FB.XFBML.parse()},twitter:function(e){var o=e.options.buttons.twitter;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof twttr&&0==i?(i=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.twitter.com/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):t.ajax({url:"//platform.twitter.com/widgets.js",dataType:"script",cache:!0})},digg:function(e){var o=e.options.buttons.digg;t(e.element).find(".buttons").append('
');var i=0;"undefined"==typeof __DBW&&0==i&&(i=1,function(){var t=n.createElement("SCRIPT"),e=n.getElementsByTagName("SCRIPT")[0];t.type="text/javascript",t.async=!0,t.src="//widgets.digg.com/buttons.js",e.parentNode.insertBefore(t,e)}())},delicious:function(e){if("tall"==e.options.buttons.delicious.size)var o="width:50px;",n="height:35px;width:50px;font-size:15px;line-height:35px;",i="height:18px;line-height:18px;margin-top:3px;";else var o="width:93px;",n="float:right;padding:0 3px;height:20px;width:26px;line-height:20px;",i="float:left;height:20px;line-height:20px;";var s=e.shorterTotal(e.options.count.delicious);"undefined"==typeof s&&(s=0),t(e.element).find(".buttons").append('
'+s+'
Delicious Add
'),t(e.element).find(".delicious").on("click",function(){e.openPopup("delicious")})},stumbleupon:function(e){var i=e.options.buttons.stumbleupon;t(e.element).find(".buttons").append('
');var a=0;"undefined"==typeof STMBLPN&&0==a?(a=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.stumbleupon.com/1/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}(),s=o.setTimeout(function(){"undefined"!=typeof STMBLPN&&(STMBLPN.processWidgets(),clearInterval(s))},500)):STMBLPN.processWidgets()},linkedin:function(e){var i=e.options.buttons.linkedin;t(e.element).find(".buttons").append('
');var s=0;"undefined"==typeof o.IN&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.linkedin.com/in.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):o.IN.init()},pinterest:function(e){var o=e.options.buttons.pinterest;t(e.element).find(".buttons").append(''),function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//assets.pinterest.com/js/pinit.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()},love:function(e){var o=e.options.buttons.love;t(e.element).find(".buttons").append('")}},p={googlePlus:function(){},facebook:function(){fb=o.setInterval(function(){"undefined"!=typeof FB&&(FB.Event.subscribe("edge.create",function(t){_gaq.push(["_trackSocial","facebook","like",t])}),FB.Event.subscribe("edge.remove",function(t){_gaq.push(["_trackSocial","facebook","unlike",t])}),FB.Event.subscribe("message.send",function(t){_gaq.push(["_trackSocial","facebook","send",t])}),clearInterval(fb))},1e3)},twitter:function(){tw=o.setInterval(function(){"undefined"!=typeof twttr&&(twttr.events.bind("tweet",function(t){t&&_gaq.push(["_trackSocial","twitter","tweet"])}),clearInterval(tw))},1e3)},digg:function(){},delicious:function(){},stumbleupon:function(){},linkedin:function(){},pinterest:function(){},love:function(){}},d={googlePlus:function(t){o.open("https://plus.google.com/share?hl="+t.buttons.googlePlus.lang+"&url="+encodeURIComponent(""!==t.buttons.googlePlus.url?t.buttons.googlePlus.url:t.url),"","toolbar=0, status=0, width=900, height=500")},facebook:function(t){o.open("//www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(""!==t.buttons.facebook.url?t.buttons.facebook.url:t.url)+"&t="+t.text,"","toolbar=0, status=0, width=900, height=500")},twitter:function(t){o.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(t.text)+"&url="+encodeURIComponent(""!==t.buttons.twitter.url?t.buttons.twitter.url:t.url)+(""!==t.buttons.twitter.via?"&via="+t.buttons.twitter.via:""),"","toolbar=0, status=0, width=650, height=360")},digg:function(t){o.open("//digg.com/tools/diggthis/submit?url="+encodeURIComponent(""!==t.buttons.digg.url?t.buttons.digg.url:t.url)+"&title="+t.text+"&related=true&style=true","","toolbar=0, status=0, width=650, height=360")},delicious:function(t){o.open("//www.delicious.com/save?v=5&noui&jump=close&url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&title="+t.text,"delicious","toolbar=no,width=550,height=550")},stumbleupon:function(t){o.open("//www.stumbleupon.com/badge/?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url),"stumbleupon","toolbar=no,width=550,height=550")},linkedin:function(t){o.open("https://www.linkedin.com/cws/share?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&token=&isFramed=true","linkedin","toolbar=no,width=550,height=550")},pinterest:function(t){o.open("//pinterest.com/pin/create/button/?url="+encodeURIComponent(""!==t.buttons.pinterest.url?t.buttons.pinterest.url:t.url)+"&media="+encodeURIComponent(t.buttons.pinterest.media)+"&description="+t.buttons.pinterest.description,"pinterest","toolbar=no,width=700,height=300")},love:function(e){t.ajax({type:"post",dataType:"json",url:simple_love.ajaxurl,data:{action:"genesis_simple_love",data_url:e.url,nonce:simple_love.nonce},success:function(e){"error"==e.type&&t("#love-before-"+e.id+" .count , #love-after-2"+e.id+" .count").html(e.count),alert(e.message)}})}};a.prototype.init=function(){var e=this;""!==this.options.urlCurl&&(u.googlePlus=this.options.urlCurl+"?url={url}&type=googlePlus",u.stumbleupon=this.options.urlCurl+"?url={url}&type=stumbleupon"),t(this.element).addClass(this.options.className),"undefined"!=typeof t(this.element).data("title")&&(this.options.title=t(this.element).attr("data-title")),"undefined"!=typeof t(this.element).data("url")&&(this.options.url=t(this.element).data("url")),"undefined"!=typeof t(this.element).data("urlalt")&&(this.options.urlalt=t(this.element).data("urlalt")),"undefined"!=typeof t(this.element).data("text")&&(this.options.text=t(this.element).data("text")),t.each(this.options.share,function(t,o){o===!0&&e.options.shareTotal++}),e.options.enableCounter===!0?t.each(this.options.share,function(t,o){if(o===!0)try{e.getSocialJson(t),e.getSocialJson(getSocialAltJson)}catch(n){}}):""!==e.options.template?this.options.render(this,this.options):this.loadButtons(),t(this.element).hover(function(){0===t(this).find(".buttons").length&&e.options.enableHover===!0&&e.loadButtons(),e.options.hover(e,e.options)},function(){e.options.hide(e,e.options)}),t(this.element).click(function(){return e.options.click(e,e.options),!1})},a.prototype.loadButtons=function(){var e=this;t(this.element).append('
'),t.each(e.options.share,function(t,o){1==o&&(c[t](e),e.options.enableTracking===!0&&p[t]())})},a.prototype.getSocialJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.url));"twitter"==e?(o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()):(o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.options.count[e]=0,o.rendererPerso()}).fail(function(){o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()}):(o.renderer(),o.options.count[e]=0,o.rendererPerso()))},a.prototype.getSocialAltJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.urlalt));o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]+=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.rendererPerso()}).fail(function(){o.renderer(),o.rendererPerso()}):(o.renderer(),o.rendererPerso())},a.prototype.rendererPerso=function(){var t=0;for(e in this.options.count)t++;t===this.options.shareTotal&&this.options.render(this,this.options)},a.prototype.renderer=function(){var e=this.options.total,o=this.options.template;hideCount=this.options.hideCount,hideCount?t(this.element).html('
'+(""!==this.options.title?'":"")+"
"):(this.options.shorterTotal===!0&&(e=this.shorterTotal(e)),""!==o?(o=o.replace("{total}",e),t(this.element).html(o)):t(this.element).html('
'+e+""+(""!==this.options.title?'":"")+"
"))},a.prototype.shorterTotal=function(t){return t>=1e6?t=(t/1e6).toFixed(2)+"M":t>=1e3&&(t=(t/1e3).toFixed(1)+"k"),t},a.prototype.openPopup=function(t){if(d[t](this.options),this.options.enableTracking===!0){var e={googlePlus:{site:"Google",action:"+1"},facebook:{site:"facebook",action:"like"},twitter:{site:"twitter",action:"tweet"},digg:{site:"digg",action:"add"},delicious:{site:"delicious",action:"add"},stumbleupon:{site:"stumbleupon",action:"add"},linkedin:{site:"linkedin",action:"share"},pinterest:{site:"pinterest",action:"pin"},love:{site:"love",action:"love"}};_gaq.push(["_trackSocial",e[t].site,e[t].action])}},a.prototype.simulateClick=function(){var e=t(this.element).html();t(this.element).html(e.replace(this.options.total,this.options.total+1))},a.prototype.update=function(t,e){""!==t&&(this.options.url=t),""!==e&&(this.options.text=e)},t.fn[r]=function(e){var o=arguments;return e===i||"object"==typeof e?this.each(function(){t.data(this,"plugin_"+r)||t.data(this,"plugin_"+r,new a(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?this.each(function(){var n=t.data(this,"plugin_"+r);n instanceof a&&"function"==typeof n[e]&&n[e].apply(n,Array.prototype.slice.call(o,1))}):void 0}}(jQuery,window,document); \ No newline at end of file From 77eeec27b844d9dc865cfb0a73bb26e176f7d1d3 Mon Sep 17 00:00:00 2001 From: phpbits Date: Wed, 14 Oct 2015 15:34:42 +0800 Subject: [PATCH 7/8] Fix Count Update onClick --- lib/sharrre/jquery.sharrre.js | 5 +---- lib/sharrre/jquery.sharrre.min.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/sharrre/jquery.sharrre.js b/lib/sharrre/jquery.sharrre.js index c66fdc6..af2f236 100644 --- a/lib/sharrre/jquery.sharrre.js +++ b/lib/sharrre/jquery.sharrre.js @@ -364,10 +364,7 @@ url : simple_love.ajaxurl, data : {action: "genesis_simple_love", data_url : opt.url, nonce: simple_love.nonce}, success: function(response){ - if(response.type == 'error'){ - // console.log( response.id ); - $('#love-before-' + response.id + ' .count , #love-after-2' + response.id + ' .count').html( response.count ); - } + $('#love-before-' + response.id + ' .count , #love-after-' + response.id + ' .count').html( response.count ); alert(response.message); } }); diff --git a/lib/sharrre/jquery.sharrre.min.js b/lib/sharrre/jquery.sharrre.min.js index 9319b26..03f9a1b 100644 --- a/lib/sharrre/jquery.sharrre.min.js +++ b/lib/sharrre/jquery.sharrre.min.js @@ -1 +1 @@ -!function(t,o,n,i){function a(e,o){this.element=e,this.options=t.extend(!0,{},l,o),this.options.share=o.share,this._defaults=l,this._name=r,this.init()}var r="sharrre",l={className:"sharrre",share:{googlePlus:!1,facebook:!1,twitter:!1,digg:!1,delicious:!1,stumbleupon:!1,linkedin:!1,pinterest:!1,love:!1},shareTotal:0,template:"",title:"",url:n.location.href,text:n.title,urlCurl:"sharrre.php",count:{},total:0,shorterTotal:!0,enableHover:!0,enableCounter:!0,enableTracking:!1,hover:function(){},hide:function(){},click:function(){},render:function(){},buttons:{googlePlus:{url:"",urlCount:!1,size:"medium",lang:"en-US",annotation:""},facebook:{url:"",urlCount:!1,action:"like",layout:"button_count",width:"",send:"false",faces:"false",colorscheme:"",font:"",lang:"en_US"},twitter:{url:"",urlCount:!1,count:"horizontal",hashtags:"",via:"",related:"",lang:"en"},digg:{url:"",urlCount:!1,type:"DiggCompact"},delicious:{url:"",urlCount:!1,size:"medium"},stumbleupon:{url:"",urlCount:!1,layout:"1"},linkedin:{url:"",urlCount:!1,counter:""},pinterest:{url:"",media:"",description:"",layout:"horizontal"},love:{url:"",media:"",description:"",layout:"horizontal"}}},u={googlePlus:"",facebook:"https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",twitter:"//cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",digg:"//services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",delicious:"//feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?",stumbleupon:"",linkedin:"//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",pinterest:"//api.pinterest.com/v1/urls/count.json?url={url}&callback=?",love:simple_love.ajaxurl+"?action=genesis_simple_love&data=getCount&nonce="+simple_love.nonce+"&data_url={url}"},c={googlePlus:function(e){var i=e.options.buttons.googlePlus;t(e.element).find(".buttons").append('
'),o.___gcfg={lang:e.options.buttons.googlePlus.lang};var s=0;"undefined"==typeof gapi&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//apis.google.com/js/plusone.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):gapi.plusone.go()},facebook:function(e){var o=e.options.buttons.facebook;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof FB&&0==i?(i=1,function(t,e,n){var i,s=t.getElementsByTagName(e)[0];t.getElementById(n)||(i=t.createElement(e),i.id=n,i.src="//connect.facebook.net/"+o.lang+"/all.js#xfbml=1",s.parentNode.insertBefore(i,s))}(n,"script","facebook-jssdk")):FB.XFBML.parse()},twitter:function(e){var o=e.options.buttons.twitter;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof twttr&&0==i?(i=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.twitter.com/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):t.ajax({url:"//platform.twitter.com/widgets.js",dataType:"script",cache:!0})},digg:function(e){var o=e.options.buttons.digg;t(e.element).find(".buttons").append('
');var i=0;"undefined"==typeof __DBW&&0==i&&(i=1,function(){var t=n.createElement("SCRIPT"),e=n.getElementsByTagName("SCRIPT")[0];t.type="text/javascript",t.async=!0,t.src="//widgets.digg.com/buttons.js",e.parentNode.insertBefore(t,e)}())},delicious:function(e){if("tall"==e.options.buttons.delicious.size)var o="width:50px;",n="height:35px;width:50px;font-size:15px;line-height:35px;",i="height:18px;line-height:18px;margin-top:3px;";else var o="width:93px;",n="float:right;padding:0 3px;height:20px;width:26px;line-height:20px;",i="float:left;height:20px;line-height:20px;";var s=e.shorterTotal(e.options.count.delicious);"undefined"==typeof s&&(s=0),t(e.element).find(".buttons").append('
'+s+'
Delicious Add
'),t(e.element).find(".delicious").on("click",function(){e.openPopup("delicious")})},stumbleupon:function(e){var i=e.options.buttons.stumbleupon;t(e.element).find(".buttons").append('
');var a=0;"undefined"==typeof STMBLPN&&0==a?(a=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.stumbleupon.com/1/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}(),s=o.setTimeout(function(){"undefined"!=typeof STMBLPN&&(STMBLPN.processWidgets(),clearInterval(s))},500)):STMBLPN.processWidgets()},linkedin:function(e){var i=e.options.buttons.linkedin;t(e.element).find(".buttons").append('
');var s=0;"undefined"==typeof o.IN&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.linkedin.com/in.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):o.IN.init()},pinterest:function(e){var o=e.options.buttons.pinterest;t(e.element).find(".buttons").append(''),function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//assets.pinterest.com/js/pinit.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()},love:function(e){var o=e.options.buttons.love;t(e.element).find(".buttons").append('")}},p={googlePlus:function(){},facebook:function(){fb=o.setInterval(function(){"undefined"!=typeof FB&&(FB.Event.subscribe("edge.create",function(t){_gaq.push(["_trackSocial","facebook","like",t])}),FB.Event.subscribe("edge.remove",function(t){_gaq.push(["_trackSocial","facebook","unlike",t])}),FB.Event.subscribe("message.send",function(t){_gaq.push(["_trackSocial","facebook","send",t])}),clearInterval(fb))},1e3)},twitter:function(){tw=o.setInterval(function(){"undefined"!=typeof twttr&&(twttr.events.bind("tweet",function(t){t&&_gaq.push(["_trackSocial","twitter","tweet"])}),clearInterval(tw))},1e3)},digg:function(){},delicious:function(){},stumbleupon:function(){},linkedin:function(){},pinterest:function(){},love:function(){}},d={googlePlus:function(t){o.open("https://plus.google.com/share?hl="+t.buttons.googlePlus.lang+"&url="+encodeURIComponent(""!==t.buttons.googlePlus.url?t.buttons.googlePlus.url:t.url),"","toolbar=0, status=0, width=900, height=500")},facebook:function(t){o.open("//www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(""!==t.buttons.facebook.url?t.buttons.facebook.url:t.url)+"&t="+t.text,"","toolbar=0, status=0, width=900, height=500")},twitter:function(t){o.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(t.text)+"&url="+encodeURIComponent(""!==t.buttons.twitter.url?t.buttons.twitter.url:t.url)+(""!==t.buttons.twitter.via?"&via="+t.buttons.twitter.via:""),"","toolbar=0, status=0, width=650, height=360")},digg:function(t){o.open("//digg.com/tools/diggthis/submit?url="+encodeURIComponent(""!==t.buttons.digg.url?t.buttons.digg.url:t.url)+"&title="+t.text+"&related=true&style=true","","toolbar=0, status=0, width=650, height=360")},delicious:function(t){o.open("//www.delicious.com/save?v=5&noui&jump=close&url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&title="+t.text,"delicious","toolbar=no,width=550,height=550")},stumbleupon:function(t){o.open("//www.stumbleupon.com/badge/?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url),"stumbleupon","toolbar=no,width=550,height=550")},linkedin:function(t){o.open("https://www.linkedin.com/cws/share?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&token=&isFramed=true","linkedin","toolbar=no,width=550,height=550")},pinterest:function(t){o.open("//pinterest.com/pin/create/button/?url="+encodeURIComponent(""!==t.buttons.pinterest.url?t.buttons.pinterest.url:t.url)+"&media="+encodeURIComponent(t.buttons.pinterest.media)+"&description="+t.buttons.pinterest.description,"pinterest","toolbar=no,width=700,height=300")},love:function(e){t.ajax({type:"post",dataType:"json",url:simple_love.ajaxurl,data:{action:"genesis_simple_love",data_url:e.url,nonce:simple_love.nonce},success:function(e){"error"==e.type&&t("#love-before-"+e.id+" .count , #love-after-2"+e.id+" .count").html(e.count),alert(e.message)}})}};a.prototype.init=function(){var e=this;""!==this.options.urlCurl&&(u.googlePlus=this.options.urlCurl+"?url={url}&type=googlePlus",u.stumbleupon=this.options.urlCurl+"?url={url}&type=stumbleupon"),t(this.element).addClass(this.options.className),"undefined"!=typeof t(this.element).data("title")&&(this.options.title=t(this.element).attr("data-title")),"undefined"!=typeof t(this.element).data("url")&&(this.options.url=t(this.element).data("url")),"undefined"!=typeof t(this.element).data("urlalt")&&(this.options.urlalt=t(this.element).data("urlalt")),"undefined"!=typeof t(this.element).data("text")&&(this.options.text=t(this.element).data("text")),t.each(this.options.share,function(t,o){o===!0&&e.options.shareTotal++}),e.options.enableCounter===!0?t.each(this.options.share,function(t,o){if(o===!0)try{e.getSocialJson(t),e.getSocialJson(getSocialAltJson)}catch(n){}}):""!==e.options.template?this.options.render(this,this.options):this.loadButtons(),t(this.element).hover(function(){0===t(this).find(".buttons").length&&e.options.enableHover===!0&&e.loadButtons(),e.options.hover(e,e.options)},function(){e.options.hide(e,e.options)}),t(this.element).click(function(){return e.options.click(e,e.options),!1})},a.prototype.loadButtons=function(){var e=this;t(this.element).append('
'),t.each(e.options.share,function(t,o){1==o&&(c[t](e),e.options.enableTracking===!0&&p[t]())})},a.prototype.getSocialJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.url));"twitter"==e?(o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()):(o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.options.count[e]=0,o.rendererPerso()}).fail(function(){o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()}):(o.renderer(),o.options.count[e]=0,o.rendererPerso()))},a.prototype.getSocialAltJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.urlalt));o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]+=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.rendererPerso()}).fail(function(){o.renderer(),o.rendererPerso()}):(o.renderer(),o.rendererPerso())},a.prototype.rendererPerso=function(){var t=0;for(e in this.options.count)t++;t===this.options.shareTotal&&this.options.render(this,this.options)},a.prototype.renderer=function(){var e=this.options.total,o=this.options.template;hideCount=this.options.hideCount,hideCount?t(this.element).html('
'+(""!==this.options.title?'":"")+"
"):(this.options.shorterTotal===!0&&(e=this.shorterTotal(e)),""!==o?(o=o.replace("{total}",e),t(this.element).html(o)):t(this.element).html('
'+e+""+(""!==this.options.title?'":"")+"
"))},a.prototype.shorterTotal=function(t){return t>=1e6?t=(t/1e6).toFixed(2)+"M":t>=1e3&&(t=(t/1e3).toFixed(1)+"k"),t},a.prototype.openPopup=function(t){if(d[t](this.options),this.options.enableTracking===!0){var e={googlePlus:{site:"Google",action:"+1"},facebook:{site:"facebook",action:"like"},twitter:{site:"twitter",action:"tweet"},digg:{site:"digg",action:"add"},delicious:{site:"delicious",action:"add"},stumbleupon:{site:"stumbleupon",action:"add"},linkedin:{site:"linkedin",action:"share"},pinterest:{site:"pinterest",action:"pin"},love:{site:"love",action:"love"}};_gaq.push(["_trackSocial",e[t].site,e[t].action])}},a.prototype.simulateClick=function(){var e=t(this.element).html();t(this.element).html(e.replace(this.options.total,this.options.total+1))},a.prototype.update=function(t,e){""!==t&&(this.options.url=t),""!==e&&(this.options.text=e)},t.fn[r]=function(e){var o=arguments;return e===i||"object"==typeof e?this.each(function(){t.data(this,"plugin_"+r)||t.data(this,"plugin_"+r,new a(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?this.each(function(){var n=t.data(this,"plugin_"+r);n instanceof a&&"function"==typeof n[e]&&n[e].apply(n,Array.prototype.slice.call(o,1))}):void 0}}(jQuery,window,document); \ No newline at end of file +!function(t,o,n,i){function a(e,o){this.element=e,this.options=t.extend(!0,{},l,o),this.options.share=o.share,this._defaults=l,this._name=r,this.init()}var r="sharrre",l={className:"sharrre",share:{googlePlus:!1,facebook:!1,twitter:!1,digg:!1,delicious:!1,stumbleupon:!1,linkedin:!1,pinterest:!1,love:!1},shareTotal:0,template:"",title:"",url:n.location.href,text:n.title,urlCurl:"sharrre.php",count:{},total:0,shorterTotal:!0,enableHover:!0,enableCounter:!0,enableTracking:!1,hover:function(){},hide:function(){},click:function(){},render:function(){},buttons:{googlePlus:{url:"",urlCount:!1,size:"medium",lang:"en-US",annotation:""},facebook:{url:"",urlCount:!1,action:"like",layout:"button_count",width:"",send:"false",faces:"false",colorscheme:"",font:"",lang:"en_US"},twitter:{url:"",urlCount:!1,count:"horizontal",hashtags:"",via:"",related:"",lang:"en"},digg:{url:"",urlCount:!1,type:"DiggCompact"},delicious:{url:"",urlCount:!1,size:"medium"},stumbleupon:{url:"",urlCount:!1,layout:"1"},linkedin:{url:"",urlCount:!1,counter:""},pinterest:{url:"",media:"",description:"",layout:"horizontal"},love:{url:"",media:"",description:"",layout:"horizontal"}}},u={googlePlus:"",facebook:"https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",twitter:"//cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",digg:"//services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",delicious:"//feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?",stumbleupon:"",linkedin:"//www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",pinterest:"//api.pinterest.com/v1/urls/count.json?url={url}&callback=?",love:simple_love.ajaxurl+"?action=genesis_simple_love&data=getCount&nonce="+simple_love.nonce+"&data_url={url}"},c={googlePlus:function(e){var i=e.options.buttons.googlePlus;t(e.element).find(".buttons").append('
'),o.___gcfg={lang:e.options.buttons.googlePlus.lang};var s=0;"undefined"==typeof gapi&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//apis.google.com/js/plusone.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):gapi.plusone.go()},facebook:function(e){var o=e.options.buttons.facebook;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof FB&&0==i?(i=1,function(t,e,n){var i,s=t.getElementsByTagName(e)[0];t.getElementById(n)||(i=t.createElement(e),i.id=n,i.src="//connect.facebook.net/"+o.lang+"/all.js#xfbml=1",s.parentNode.insertBefore(i,s))}(n,"script","facebook-jssdk")):FB.XFBML.parse()},twitter:function(e){var o=e.options.buttons.twitter;t(e.element).find(".buttons").append('');var i=0;"undefined"==typeof twttr&&0==i?(i=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.twitter.com/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):t.ajax({url:"//platform.twitter.com/widgets.js",dataType:"script",cache:!0})},digg:function(e){var o=e.options.buttons.digg;t(e.element).find(".buttons").append('
');var i=0;"undefined"==typeof __DBW&&0==i&&(i=1,function(){var t=n.createElement("SCRIPT"),e=n.getElementsByTagName("SCRIPT")[0];t.type="text/javascript",t.async=!0,t.src="//widgets.digg.com/buttons.js",e.parentNode.insertBefore(t,e)}())},delicious:function(e){if("tall"==e.options.buttons.delicious.size)var o="width:50px;",n="height:35px;width:50px;font-size:15px;line-height:35px;",i="height:18px;line-height:18px;margin-top:3px;";else var o="width:93px;",n="float:right;padding:0 3px;height:20px;width:26px;line-height:20px;",i="float:left;height:20px;line-height:20px;";var s=e.shorterTotal(e.options.count.delicious);"undefined"==typeof s&&(s=0),t(e.element).find(".buttons").append('
'+s+'
Delicious Add
'),t(e.element).find(".delicious").on("click",function(){e.openPopup("delicious")})},stumbleupon:function(e){var i=e.options.buttons.stumbleupon;t(e.element).find(".buttons").append('
');var a=0;"undefined"==typeof STMBLPN&&0==a?(a=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.stumbleupon.com/1/widgets.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}(),s=o.setTimeout(function(){"undefined"!=typeof STMBLPN&&(STMBLPN.processWidgets(),clearInterval(s))},500)):STMBLPN.processWidgets()},linkedin:function(e){var i=e.options.buttons.linkedin;t(e.element).find(".buttons").append('
');var s=0;"undefined"==typeof o.IN&&0==s?(s=1,function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//platform.linkedin.com/in.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()):o.IN.init()},pinterest:function(e){var o=e.options.buttons.pinterest;t(e.element).find(".buttons").append(''),function(){var t=n.createElement("script");t.type="text/javascript",t.async=!0,t.src="//assets.pinterest.com/js/pinit.js";var e=n.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}()},love:function(e){var o=e.options.buttons.love;t(e.element).find(".buttons").append('")}},p={googlePlus:function(){},facebook:function(){fb=o.setInterval(function(){"undefined"!=typeof FB&&(FB.Event.subscribe("edge.create",function(t){_gaq.push(["_trackSocial","facebook","like",t])}),FB.Event.subscribe("edge.remove",function(t){_gaq.push(["_trackSocial","facebook","unlike",t])}),FB.Event.subscribe("message.send",function(t){_gaq.push(["_trackSocial","facebook","send",t])}),clearInterval(fb))},1e3)},twitter:function(){tw=o.setInterval(function(){"undefined"!=typeof twttr&&(twttr.events.bind("tweet",function(t){t&&_gaq.push(["_trackSocial","twitter","tweet"])}),clearInterval(tw))},1e3)},digg:function(){},delicious:function(){},stumbleupon:function(){},linkedin:function(){},pinterest:function(){},love:function(){}},d={googlePlus:function(t){o.open("https://plus.google.com/share?hl="+t.buttons.googlePlus.lang+"&url="+encodeURIComponent(""!==t.buttons.googlePlus.url?t.buttons.googlePlus.url:t.url),"","toolbar=0, status=0, width=900, height=500")},facebook:function(t){o.open("//www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(""!==t.buttons.facebook.url?t.buttons.facebook.url:t.url)+"&t="+t.text,"","toolbar=0, status=0, width=900, height=500")},twitter:function(t){o.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(t.text)+"&url="+encodeURIComponent(""!==t.buttons.twitter.url?t.buttons.twitter.url:t.url)+(""!==t.buttons.twitter.via?"&via="+t.buttons.twitter.via:""),"","toolbar=0, status=0, width=650, height=360")},digg:function(t){o.open("//digg.com/tools/diggthis/submit?url="+encodeURIComponent(""!==t.buttons.digg.url?t.buttons.digg.url:t.url)+"&title="+t.text+"&related=true&style=true","","toolbar=0, status=0, width=650, height=360")},delicious:function(t){o.open("//www.delicious.com/save?v=5&noui&jump=close&url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&title="+t.text,"delicious","toolbar=no,width=550,height=550")},stumbleupon:function(t){o.open("//www.stumbleupon.com/badge/?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url),"stumbleupon","toolbar=no,width=550,height=550")},linkedin:function(t){o.open("https://www.linkedin.com/cws/share?url="+encodeURIComponent(""!==t.buttons.delicious.url?t.buttons.delicious.url:t.url)+"&token=&isFramed=true","linkedin","toolbar=no,width=550,height=550")},pinterest:function(t){o.open("//pinterest.com/pin/create/button/?url="+encodeURIComponent(""!==t.buttons.pinterest.url?t.buttons.pinterest.url:t.url)+"&media="+encodeURIComponent(t.buttons.pinterest.media)+"&description="+t.buttons.pinterest.description,"pinterest","toolbar=no,width=700,height=300")},love:function(e){t.ajax({type:"post",dataType:"json",url:simple_love.ajaxurl,data:{action:"genesis_simple_love",data_url:e.url,nonce:simple_love.nonce},success:function(e){t("#love-before-"+e.id+" .count , #love-after-"+e.id+" .count").html(e.count),alert(e.message)}})}};a.prototype.init=function(){var e=this;""!==this.options.urlCurl&&(u.googlePlus=this.options.urlCurl+"?url={url}&type=googlePlus",u.stumbleupon=this.options.urlCurl+"?url={url}&type=stumbleupon"),t(this.element).addClass(this.options.className),"undefined"!=typeof t(this.element).data("title")&&(this.options.title=t(this.element).attr("data-title")),"undefined"!=typeof t(this.element).data("url")&&(this.options.url=t(this.element).data("url")),"undefined"!=typeof t(this.element).data("urlalt")&&(this.options.urlalt=t(this.element).data("urlalt")),"undefined"!=typeof t(this.element).data("text")&&(this.options.text=t(this.element).data("text")),t.each(this.options.share,function(t,o){o===!0&&e.options.shareTotal++}),e.options.enableCounter===!0?t.each(this.options.share,function(t,o){if(o===!0)try{e.getSocialJson(t),e.getSocialJson(getSocialAltJson)}catch(n){}}):""!==e.options.template?this.options.render(this,this.options):this.loadButtons(),t(this.element).hover(function(){0===t(this).find(".buttons").length&&e.options.enableHover===!0&&e.loadButtons(),e.options.hover(e,e.options)},function(){e.options.hide(e,e.options)}),t(this.element).click(function(){return e.options.click(e,e.options),!1})},a.prototype.loadButtons=function(){var e=this;t(this.element).append('
'),t.each(e.options.share,function(t,o){1==o&&(c[t](e),e.options.enableTracking===!0&&p[t]())})},a.prototype.getSocialJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.url));"twitter"==e?(o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()):(o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.options.count[e]=0,o.rendererPerso()}).fail(function(){o.options.hideCount=1,o.renderer(),o.options.count[e]=0,o.rendererPerso()}):(o.renderer(),o.options.count[e]=0,o.rendererPerso()))},a.prototype.getSocialAltJson=function(e){var o=this,n=0,i=u[e].replace("{url}",encodeURIComponent(this.options.urlalt));o.options.hideCount=0,this.options.buttons[e].urlCount===!0&&""!==this.options.buttons[e].url&&(i=u[e].replace("{url}",this.options.buttons[e].url)),""!=i&&""!==o.options.urlCurl?t.getJSON(i,function(t){if(null!=t){if("undefined"!=typeof t.count){var i=t.count+"";i=i.replace(" ",""),n+=parseInt(i,10)}else t.data&&t.data.length>0&&"undefined"!=typeof t.data[0].total_count?n+=parseInt(t.data[0].total_count,10):"undefined"!=typeof t[0]?n+=parseInt(t[0].total_posts,10):"undefined"!=typeof t[0];o.options.count[e]+=n,o.options.total+=n,o.renderer(),o.rendererPerso()}else o.renderer(),o.rendererPerso()}).fail(function(){o.renderer(),o.rendererPerso()}):(o.renderer(),o.rendererPerso())},a.prototype.rendererPerso=function(){var t=0;for(e in this.options.count)t++;t===this.options.shareTotal&&this.options.render(this,this.options)},a.prototype.renderer=function(){var e=this.options.total,o=this.options.template;hideCount=this.options.hideCount,hideCount?t(this.element).html('
'+(""!==this.options.title?'":"")+"
"):(this.options.shorterTotal===!0&&(e=this.shorterTotal(e)),""!==o?(o=o.replace("{total}",e),t(this.element).html(o)):t(this.element).html('
'+e+""+(""!==this.options.title?'":"")+"
"))},a.prototype.shorterTotal=function(t){return t>=1e6?t=(t/1e6).toFixed(2)+"M":t>=1e3&&(t=(t/1e3).toFixed(1)+"k"),t},a.prototype.openPopup=function(t){if(d[t](this.options),this.options.enableTracking===!0){var e={googlePlus:{site:"Google",action:"+1"},facebook:{site:"facebook",action:"like"},twitter:{site:"twitter",action:"tweet"},digg:{site:"digg",action:"add"},delicious:{site:"delicious",action:"add"},stumbleupon:{site:"stumbleupon",action:"add"},linkedin:{site:"linkedin",action:"share"},pinterest:{site:"pinterest",action:"pin"},love:{site:"love",action:"love"}};_gaq.push(["_trackSocial",e[t].site,e[t].action])}},a.prototype.simulateClick=function(){var e=t(this.element).html();t(this.element).html(e.replace(this.options.total,this.options.total+1))},a.prototype.update=function(t,e){""!==t&&(this.options.url=t),""!==e&&(this.options.text=e)},t.fn[r]=function(e){var o=arguments;return e===i||"object"==typeof e?this.each(function(){t.data(this,"plugin_"+r)||t.data(this,"plugin_"+r,new a(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?this.each(function(){var n=t.data(this,"plugin_"+r);n instanceof a&&"function"==typeof n[e]&&n[e].apply(n,Array.prototype.slice.call(o,1))}):void 0}}(jQuery,window,document); \ No newline at end of file From b55a5de5efaca236877d1b04c92e712d77f1ec05 Mon Sep 17 00:00:00 2001 From: phpbits Date: Fri, 16 Oct 2015 17:05:37 +0800 Subject: [PATCH 8/8] Formatting issue and fixes from NicktheGeek --- lib/admin-icon-preview.php | 2 +- lib/admin.php | 10 ++--- lib/ajax.php | 79 +++++++++++++++++++------------------- lib/front-end.php | 8 ++-- plugin.php | 6 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/lib/admin-icon-preview.php b/lib/admin-icon-preview.php index 24cfc21..d52126f 100644 --- a/lib/admin-icon-preview.php +++ b/lib/admin-icon-preview.php @@ -178,7 +178,7 @@ function get_icon_output( $location, $icons = array() ){ case 'love' : - $data_title = __('Love', 'genesis'); + $data_title = __('Love', 'genesis-simple-share'); break; default: diff --git a/lib/admin.php b/lib/admin.php index 586f3ab..6015315 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -54,7 +54,7 @@ function __construct() { 'pinterest' => 1, 'linkedin' => 1, 'stumbleupon' => 1, - 'love' => 1, + 'love' => 1, ) ); @@ -177,9 +177,9 @@ function scripts() { ); $atts = array( - 'nonce' => wp_create_nonce( 'genesis_love' ), - 'ajaxurl' => admin_url('admin-ajax.php'), - 'love_text' => apply_filters('genesis_simple_love_text', __('Love', 'genesis') ) + 'nonce' => wp_create_nonce( 'genesis_love' ), + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'love_text' => apply_filters( 'genesis_simple_love_text', __( 'Love', 'genesis-simple-share' ) ) ); wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $atts ); @@ -432,8 +432,6 @@ function love() { $this->checkbox( $id , __( 'Use this button?', 'genesis-simple-share' ) ); - //echo $this->sort_text; - } /** diff --git a/lib/ajax.php b/lib/ajax.php index d94b97a..ce2938e 100644 --- a/lib/ajax.php +++ b/lib/ajax.php @@ -1,67 +1,66 @@ This plugin requires Genesis Simple Share. Thanks! -Version: 1.0 -Author: phpbits -Author URI: http://codecanyon.net/user/phpbits/portfolio?ref=phpbits -License: GPL2 -*/ -if(!class_exists('PHPBITS_GenesisSimpleLove')): - class PHPBITS_GenesisSimpleLove{ +/** + * Create ajax handle for checking cookies + * and updating metadata + * + * @since 1.0.7 + * @uses important genesis_simple_love ajax used. + * @param nonce, post_id + * @return json datatype + */ +if( ! class_exists( 'Genesis_Simple_Share_AJAX' ) ){ + class Genesis_Simple_Share_AJAX{ function __construct(){ - add_action("wp_ajax_genesis_simple_love", array( $this, "ajax_love" )); - add_action("wp_ajax_nopriv_genesis_simple_love", array( $this, "ajax_love" )); + add_action( 'wp_ajax_genesis_simple_love', array( $this, 'ajax_love' )); + add_action( 'wp_ajax_nopriv_genesis_simple_love', array( $this, 'ajax_love' )); } function ajax_love() { - $result = array(); + $result = array(); + $nonce = $_REQUEST['nonce']; + $post_id = url_to_postid( $_REQUEST['data_url'] ); + $loved = array(); - $nonce = $_REQUEST['nonce']; - $post_id = url_to_postid( $_REQUEST['data_url'] );; - $loved = array(); - - if ( !wp_verify_nonce( $nonce, "genesis_love")) { - exit("You don't have any power here!"); + if ( !wp_verify_nonce( $nonce, 'genesis_love' )) { + exit( 'You don\'t have any power here!' ); } $handle = ''; - if(isset($_COOKIE['genesis_simple_love'])){ + if( isset( $_COOKIE['genesis_simple_love'] ) ){ $loved = @unserialize(base64_decode($_COOKIE['genesis_simple_love'])); } //get love - if(isset($_REQUEST['data']) && 'getCount' == $_REQUEST['data']){ + if( isset( $_REQUEST['data'] ) && 'getCount' == $_REQUEST['data'] ){ echo '{"url":"'. $_REQUEST['data_url'] .'","count":"'. (int) get_post_meta($post_id, '_genesis_simple_love_', true) .'"}'; die(); } //save love - if ( is_array($loved) && !in_array( $post_id, $loved ) ){ - $loved[] = $post_id; - $post_loved = (int) get_post_meta($post_id, '_genesis_simple_love_', true); + if ( is_array( $loved ) && !in_array( $post_id, $loved ) ){ + $loved[] = $post_id; + $post_loved = (int) get_post_meta($post_id, '_genesis_simple_love_', true); $post_loved++; - update_post_meta($post_id, '_genesis_simple_love_', $post_loved); + update_post_meta( $post_id, '_genesis_simple_love_', $post_loved ); $_COOKIE['genesis_simple_love'] = base64_encode(serialize($loved)); - setcookie('genesis_simple_love', $_COOKIE['genesis_simple_love'] , time()+(10*365*24*60*60),'/'); + setcookie( 'genesis_simple_love', $_COOKIE['genesis_simple_love'] , time()+(10*365*24*60*60),'/' ); - $result['type'] = 'success'; - $result['message'] = apply_filters('genesis_simple_love_message', __('Thank You for loving this!', 'genesis-simple-love') ); - $result['count'] = $post_loved; - $result['id'] = $post_id; - }else{ - $post_loved = (int) get_post_meta($post_id, '_genesis_simple_love_', true); - $result['type'] = 'error'; - $result['message'] = apply_filters('genesis_simple_loved', __('You already loved this. Thanks!', 'genesis-simple-love') ); - $result['count'] = $post_loved; - $result['id'] = $post_id; + $result['type'] = 'success'; + $result['message'] = apply_filters( 'genesis_simple_love_message', __('Thank You for loving this!', 'genesis-simple-share' ) ); + $result['count'] = $post_loved; + $result['id'] = $post_id; + } else { + $post_loved = (int) get_post_meta( $post_id, '_genesis_simple_love_', true ); + $result['type'] = 'error'; + $result['message'] = apply_filters( 'genesis_simple_loved', __( 'You already loved this. Thanks!', 'genesis-simple-share' ) ); + $result['count'] = $post_loved; + $result['id'] = $post_id; } - echo $result = json_encode($result); + echo $result = json_encode( $result ); die(); } } - new PHPBITS_GenesisSimpleLove(); -endif; \ No newline at end of file + new Genesis_Simple_Share_AJAX(); +} \ No newline at end of file diff --git a/lib/front-end.php b/lib/front-end.php index 1f47f31..471d4fc 100644 --- a/lib/front-end.php +++ b/lib/front-end.php @@ -144,9 +144,9 @@ function load_scripts() { } $atts = array( - 'nonce' => wp_create_nonce( 'genesis_love' ), - 'ajaxurl' => admin_url('admin-ajax.php'), - 'love_text' => apply_filters('genesis_simple_love_text', __('Love', 'genesis') ) + 'nonce' => wp_create_nonce( 'genesis_love' ), + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'love_text' => apply_filters( 'genesis_simple_love_text', __( 'Love', 'genesis' ) ) ); wp_localize_script( 'genesis-simple-share-plugin-js', 'simple_love', $atts ); @@ -432,7 +432,7 @@ function get_icon_output( $location, $icons = array(), $force_show = false ){ case 'love' : - $data_title = __('Love', 'genesis'); + $data_title = __( 'Love', 'genesis-simple-share' ); break; default: diff --git a/plugin.php b/plugin.php index e2b713e..4dfaf08 100644 --- a/plugin.php +++ b/plugin.php @@ -40,7 +40,7 @@ function genesis_simple_share_init() { require_once( GENESIS_SIMPLE_SHARE_LIB . 'admin.php' ); require_once( GENESIS_SIMPLE_SHARE_LIB . 'post-meta.php' ); } - else{ + else { require_once( GENESIS_SIMPLE_SHARE_LIB . 'front-end.php' ); } @@ -48,4 +48,6 @@ function genesis_simple_share_init() { } -require_once( GENESIS_SIMPLE_SHARE_LIB . 'ajax.php' ); +if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + require_once( GENESIS_SIMPLE_SHARE_LIB . 'ajax.php' ); +} \ No newline at end of file