Version Description
(19 SEP 2018) * Fixed the social_warfare() function so it now outputs buttons as it did before. * Fixed a call to undefined function regarding mb_convert_encoding(). * Fixed an "undefined index" error in the javascript. * Fixed a bug that would sometimes make Yoast's og:description disappear. * Fixed a "return value in write context" PHP error. * Fixed Bitly authentication, link generation, and link usage with the buttons.
Download this release
Release Info
Developer | WarfarePlugins |
Plugin | WordPress Social Sharing Plugin – Social Warfare |
Version | 3.3.3 |
Comparing to | |
See all releases |
Code changes from version 3.3.0 to 3.3.3
- README.md +8 -2
- assets/css/admin.css +2 -2
- assets/css/admin.min.css +1 -1
- assets/images/admin-options-page/Thumbs.db +0 -0
- assets/js/script.js +10 -8
- assets/js/script.min.js +9 -1
- lib/Social_Warfare.php +1 -0
- lib/frontend-output/SWP_Buttons_Panel.php +204 -83
- lib/frontend-output/SWP_Shortcode.php +21 -12
- lib/options/SWP_Section_HTML.php +30 -6
- lib/options/SWP_User_Options.php +6 -1
- lib/social-networks/SWP_Twitter.php +6 -3
- lib/utilities/SWP_CURL.php +1 -0
- lib/utilities/SWP_Plugin_Updater.php +0 -0
- lib/utilities/SWP_URL_Management.php +108 -134
- lib/utilities/SWP_Utility.php +26 -1
- lib/utilities/functions.php +27 -4
- readme.txt +18 -1
- social-warfare.php +2 -2
README.md
CHANGED
@@ -15,7 +15,11 @@ All WordPress coding standards should be followed. Anything not specifically def
|
|
15 |
### Variables and Class Names
|
16 |
All PHP and Javascript variables, functions and classes, and CSS classes and ID's should follow the following naming standards.
|
17 |
|
18 |
-
**PHP:** All names in PHP will use the Snake Case nomenclature. Independent function names will be preceded with the swp_ vendor prefix (e.g. swp_my_function_name). Methods and properties within classes do not require this prefix.
|
|
|
|
|
|
|
|
|
19 |
|
20 |
Classes will be snake cased as well, but will also have the first letter of each word capitalized. Class names will also use the singular and never plural (e.g. My_Thing, not My_Things). The first letter will be capitalized on variables containing an instance of a class as well (e.g. $Class = new SWP_Class() ).
|
21 |
|
@@ -26,7 +30,9 @@ Line breaks in PHP will be used generously to make the code more easily readable
|
|
26 |
**CSS:** CSS selectors will use the snake_case nomenclature just as in our PHP code.
|
27 |
|
28 |
### Conditionals and Loops
|
29 |
-
No inline/same-line conditionals or loops will be used, nor will
|
|
|
|
|
30 |
|
31 |
### Style Guidelines for Docblocking Class Methods
|
32 |
Each file should begin with a docblock, as well as each function and class should be preceded with a docblock to explain it's purpose and functionality. There is no such thing as too much documentation on this project. The purpose is that any developer or even a non-developer should be able to easily browse each file and know exactly what is happening in that file.
|
15 |
### Variables and Class Names
|
16 |
All PHP and Javascript variables, functions and classes, and CSS classes and ID's should follow the following naming standards.
|
17 |
|
18 |
+
**PHP:** All names in PHP will use the Snake Case nomenclature. Independent/global function names will be preceded with the swp_ vendor prefix (e.g. swp_my_function_name). Methods and properties within classes do not require this prefix.
|
19 |
+
|
20 |
+
In regard to variable names, avoid abbreviations (i.e. $my_var should be $my_variable). The only exception is words or terms where the abbreviation or acronym is the commonly excepted usage of the word in regular speech (e.g. ID or ATM).
|
21 |
+
|
22 |
+
Avoid using id as a standalone variable name. Instead use a semantic identifier so it's clear to what the ID relates (e.g. $post_id).
|
23 |
|
24 |
Classes will be snake cased as well, but will also have the first letter of each word capitalized. Class names will also use the singular and never plural (e.g. My_Thing, not My_Things). The first letter will be capitalized on variables containing an instance of a class as well (e.g. $Class = new SWP_Class() ).
|
25 |
|
30 |
**CSS:** CSS selectors will use the snake_case nomenclature just as in our PHP code.
|
31 |
|
32 |
### Conditionals and Loops
|
33 |
+
No inline/same-line conditionals or loops will be used, nor will be continue to use if/endif notation. Instead we will use brace notation.
|
34 |
+
|
35 |
+
Avoid wrapping large blocks of code inside of conditionals. Instead, use a conditional with a return to stop the method from running the undesired code.
|
36 |
|
37 |
### Style Guidelines for Docblocking Class Methods
|
38 |
Each file should begin with a docblock, as well as each function and class should be preceded with a docblock to explain it's purpose and functionality. There is no such thing as too much documentation on this project. The purpose is that any developer or even a non-developer should be able to easily browse each file and know exactly what is happening in that file.
|
assets/css/admin.css
CHANGED
@@ -40,11 +40,11 @@
|
|
40 |
}
|
41 |
|
42 |
#social_warfare .swp_og_imageWrapper ul.swpmb-media-list {
|
43 |
-
background-image: url('../
|
44 |
}
|
45 |
|
46 |
#social_warfare .swp_pinterest_imageWrapper ul.swpmb-media-list {
|
47 |
-
background-image: url('../
|
48 |
}
|
49 |
|
50 |
.swpmb-field.swpmb-textarea-wrapper.swp_og_title,
|
40 |
}
|
41 |
|
42 |
#social_warfare .swp_og_imageWrapper ul.swpmb-media-list {
|
43 |
+
background-image: url('../images/img-placeholder-og.jpg');
|
44 |
}
|
45 |
|
46 |
#social_warfare .swp_pinterest_imageWrapper ul.swpmb-media-list {
|
47 |
+
background-image: url('../images/img-placeholder-pin.jpg');
|
48 |
}
|
49 |
|
50 |
.swpmb-field.swpmb-textarea-wrapper.swp_og_title,
|
assets/css/admin.min.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.notAvailable{opacity:0.3}.swp_CountDown{background-color:#CCC;display:inline-block;float:right;padding:5px 15px;-webkit-border-radius:3px 3px 0 0;border-radius:3px 3px 0 0;color:#FFF;font-weight:bold;margin-top:-27px}.swp_CountDown.swp_blue{background-color:#30394F}.swp_CountDown.swp_red{background-color:#EE464F}#social_warfare textarea.large-text{width:100%}#social_warfare ul.swpmb-media-list.ui-sortable{display:block;width:100%;-webkit-background-size:cover;background-size:cover;background-position-x:center;background-repeat:no-repeat;background-color:#ccc;-webkit-border-radius:4px;border-radius:4px;padding:0}#social_warfare .swp_og_imageWrapper ul.swpmb-media-list{background-image:url('../
|
1 |
+
.notAvailable{opacity:0.3}.swp_CountDown{background-color:#CCC;display:inline-block;float:right;padding:5px 15px;-webkit-border-radius:3px 3px 0 0;border-radius:3px 3px 0 0;color:#FFF;font-weight:bold;margin-top:-27px}.swp_CountDown.swp_blue{background-color:#30394F}.swp_CountDown.swp_red{background-color:#EE464F}#social_warfare textarea.large-text{width:100%}#social_warfare ul.swpmb-media-list.ui-sortable{display:block;width:100%;-webkit-background-size:cover;background-size:cover;background-position-x:center;background-repeat:no-repeat;background-color:#ccc;-webkit-border-radius:4px;border-radius:4px;padding:0}#social_warfare .swp_og_imageWrapper ul.swpmb-media-list{background-image:url('../images/img-placeholder-og.jpg')}#social_warfare .swp_pinterest_imageWrapper ul.swpmb-media-list{background-image:url('../images/img-placeholder-pin.jpg')}.swpmb-field.swpmb-textarea-wrapper.swp_og_title,.swpmb-field.swpmb-textarea-wrapper.swp_og_description,.swpmb-field.swpmb-textarea-wrapper.swp_pinterest_descriptionWrapper,.swpmb-field.swpmb-textarea-wrapper.swp_customTweetWrapper{width:63%;float:left}.swpmb-field.swpmb-text-wrapper.swp_share_recoveryWrapper{width:63%;float:left}.swpmb-field.swpmb-text-wrapper.swp_share_recoveryWrapper input{width:100%}.swpmb-field.swpmb-select-wrapper.swp_pin_browser_extensionWrapper,.swpmb-field.swpmb-select-wrapper.swp_pin_browser_extension_locationWrapper,.swpmb-field.swpmb-select-wrapper.swp_post_locationWrapper,.swpmb-field.swpmb-select-wrapper.swp_float_locationWrapper{width:32%;float:left;min-width:320px}.swpmb-field.swpmb-select-wrapper.swp_pin_browser_extensionWrapper select,.swpmb-field.swpmb-select-wrapper.swp_pin_browser_extension_locationWrapper select,.swpmb-field.swpmb-select-wrapper.swp_post_locationWrapper select,.swpmb-field.swpmb-select-wrapper.swp_float_locationWrapper select{width:90%}.swpmb-field.swpmb-image_advanced-wrapper.swp_og_imageWrapper,.swpmb-field.swpmb-image_advanced-wrapper.swp_pinterest_imageWrapper{width:30%;float:left;margin-right:3%}#social_warfare .swpmb-label,#social_warfare .swpmb-input{width:100%}#social_warfare .swpmb-field{margin-top:10px}#social_warfare .swpmb-image-item,#social_warfare .swpmb-media-preview,#social_warfare .swpmb-media-content .centered,#social_warfare .swpmb-media-content img{width:100%;height:auto;max-height:none;-webkit-transform:none;-ms-transform:none;transform:none}.wp-core-ui #social_warfare a.swpmb-add-media.button{display:block;background:#30394f;color:#fff;font-size:12px;line-height:1;text-align:center;vertical-align:middle;padding:15px 25px;margin:0;-webkit-box-shadow:none;box-shadow:none;border:none;height:auto}.wp-core-ui #social_warfare a.swpmb-add-media.button:hover{background:#EE464F}#social_warfare .swpmb-media-content img{-webkit-transform:translate(0%,0%);-ms-transform:translate(0%,0%);transform:translate(0%,0%)}#social_warfare .swpmb-media-content{overflow:visible}#social_warfare .swpmb-media-preview:before{padding-top:0}#social_warfare .swpmb-media-content{position:inherit}#social_warfare .swpmb-divider-wrapper hr{border:none!important}#social_warfare .swpmb-label label{font-weight:bold;color:#30394f;font-size:18px}#social_warfare .swpmb-divider-wrapper{max-height:1px;clear:both}#social_warfare .swpmb-label{margin-bottom:10px}#social_warfare h2.hndle span:before{content:'p';margin-right:10px;font-family:"sw-icon-font";vertical-align:middle}#social_warfare .dashicons,#social_warfare .sw{vertical-align:middle;margin-right:10px;font-size:18px}#social_warfare .sw-premium-blocker{position:absolute;width:100%;height:100%;top:0;left:0}#social_warfare .sw-premium-blocker:not(.no-icon):before{font-family:'sw-icon-font';content:'E';font-size:24px;float:right;margin:10px 40px 0 0}#social_warfare #swp_recovery_url{}.ui-tooltip.sw-admin-hover-notice{background:#ee464f;color:#fff;padding:15px;-webkit-border-radius:2px;border-radius:2px;margin:15px 0;border:0;-webkit-box-shadow:none;box-shadow:none;max-width:none;padding:20px}.sw-admin-hover-notice i:before{font-family:'sw-icon-font';font-size:26px;margin:0 15px 0 0;vertical-align:middle;content:'E';float:left;font-style:normal}[class$=title_wrapper] ~ [class$=title_wrapper]{border-top:1px solid #CED3DC;padding-top:40px}.swp-notice-wrapper{max-width:73%;margin-top:-15px;margin-bottom:15px}.swp-notice{padding:10px 15px;padding:20px}.swp-actions{display:flex;align-items:center}.swp-notice a{cursor:hover;text-decoration:underline;margin:0 10px}.swp-dismiss-notice.notice.notice-info{font-size:15px;line-height:25px}.swp-dismiss-notice.notice.notice-info{border-left-color:#D34250;padding:20px;margin:15px 0 15px}.swp-dismiss-notice.notice.notice-info p{font-size:15px;line-height:25px;padding:0;margin:0 0 20px}a.swp-notice-cta{cursor:pointer;text-decoration:underline;font-size:15px;line-height:30px;margin-right:50px}#swp-admin-sidebar .swp-component.dark-text{color:#333}#swp-admin-sidebar .swp-component.light-text{color:#eee}#swp-admin-sidebar .swp-component{font-size:13px;padding:20px;margin:20px;border-radius:8px}#swp-admin-sidebar .swp-component.text-center{text-align:center}#swp-admin-sidebar .swp-component-cta{margin:0 auto;display:block;padding:10px 15px;border:0;border-radius:4px;text-align:center;text-decoration:none;color:white;text-transform:uppercase;letter-spacing:2px;font-weight:bold;cursor:pointer;width:90%}#swp-admin-sidebar button.swp-component-cta{width:100%}#swp-admin-sidebar .swp-component-icon{text-align:center}#swp-admin-sidebar .swp-component-icon .dashicons{font-size:40px;width:40px;height:40px;text-align:center}#swp-admin-sidebar .swp-component .swp-component-title{font-size:26px;text-align:center;font-weight:bold}
|
assets/images/admin-options-page/Thumbs.db
DELETED
Binary file
|
assets/js/script.js
CHANGED
@@ -217,7 +217,7 @@ var socialWarfarePlugin = socialWarfarePlugin || {};
|
|
217 |
if (typeof swpFloatBeforeContent != 'undefined' && false === swpFloatBeforeContent) {
|
218 |
var theContent = jQuery(".swp-content-locator").parent();
|
219 |
|
220 |
-
if (index === 0 && theContent.offset().top > (scrollPos + jQuery(window).height())) {
|
221 |
visible = true;
|
222 |
}
|
223 |
}
|
@@ -454,23 +454,25 @@ var socialWarfarePlugin = socialWarfarePlugin || {};
|
|
454 |
return;
|
455 |
}
|
456 |
|
457 |
-
var pinMedia
|
458 |
|
459 |
if ('undefined' !== typeof swpPinIt.image_source) {
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
|
|
464 |
} else if (image.data('media')) {
|
465 |
pinMedia = image.data('media');
|
466 |
} else if ($(this).data('lazy-src')) {
|
467 |
pinMedia = $(this).data('lazy-src');
|
468 |
} else if (image[0].src) {
|
469 |
pinMedia = image[0].src;
|
470 |
-
}
|
471 |
|
472 |
// Bail if we don't have any media to pin.
|
473 |
-
if (
|
474 |
return;
|
475 |
}
|
476 |
|
217 |
if (typeof swpFloatBeforeContent != 'undefined' && false === swpFloatBeforeContent) {
|
218 |
var theContent = jQuery(".swp-content-locator").parent();
|
219 |
|
220 |
+
if (index === 0 && theContent.length && theContent.offset().top > (scrollPos + jQuery(window).height())) {
|
221 |
visible = true;
|
222 |
}
|
223 |
}
|
454 |
return;
|
455 |
}
|
456 |
|
457 |
+
var pinMedia;
|
458 |
|
459 |
if ('undefined' !== typeof swpPinIt.image_source) {
|
460 |
+
|
461 |
+
//* Create a temp image to force absolute paths via jQuery.
|
462 |
+
var i = new Image();
|
463 |
+
i.src = swpPinIt.image_source;
|
464 |
+
pinMedia = jQuery(i).prop('src');
|
465 |
+
|
466 |
} else if (image.data('media')) {
|
467 |
pinMedia = image.data('media');
|
468 |
} else if ($(this).data('lazy-src')) {
|
469 |
pinMedia = $(this).data('lazy-src');
|
470 |
} else if (image[0].src) {
|
471 |
pinMedia = image[0].src;
|
472 |
+
};
|
473 |
|
474 |
// Bail if we don't have any media to pin.
|
475 |
+
if ( !pinMedia || 'undefined' === typeof pinMedia ) {
|
476 |
return;
|
477 |
}
|
478 |
|
assets/js/script.min.js
CHANGED
@@ -1 +1,9 @@
|
|
1 |
-
var socialWarfarePlugin=socialWarfarePlugin||{};!function(e,t){var i,a=e.socialWarfarePlugin;a.throttle=i=function(e,i,n,o){function s(){function a(){p=+new Date,n.apply(l,d)}function s(){r=t}var l=this,c=+new Date-p,d=arguments;o&&!r&&a(),r&&clearTimeout(r),o===t&&c>e?a():!0!==i&&(r=setTimeout(o?s:a,o===t?e-c:e))}var r,p=0;return"boolean"!=typeof i&&(o=n,n=i,i=t),a.guid&&(s.guid=n.guid=n.guid||a.guid++),s},a.debounce=function(e,a,n){return n===t?i(e,a,!1):i(e,n,!1!==a)}}(this),function(e,t,i){"use strict";function a(e){return parseInt(e,10)}function n(i){var a=t.Event(i);t(e).trigger(a)}function o(){t(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer:not(.swp_nohover) .iconFiller").removeAttr("style"),t(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer:not(.swp_nohover)").removeAttr("style")}function s(){var i=(t(".swp_social_panel").not(".swp_social_panelSide").first(),!1),a=t(e).scrollTop();return t(".swp_social_panel").not(".swp_social_panelSide, .nc_floater").each(function(n){var o=t(this).offset();if("undefined"!=typeof swpFloatBeforeContent&&!1===swpFloatBeforeContent){var s=jQuery(".swp-content-locator").parent();0===n&&s.offset().top>a+jQuery(e).height()&&(i=!0)}o.top+t(this).height()>a&&o.top<a+t(e).height()&&(i=!0)}),i}function r(){t(".nc_wrapper").length&&t(".nc_wrapper").remove();var i=t(".swp_social_panel"),a=i.data("float");if(void 0!==i&&!(t(e).width()>i.data("min-width")&&"top"!=a&&"bottom"!=a)){var n=i.data("float-color"),o="center"==i.data("align")?0:i.offset().left,s=t('<div class="nc_wrapper" style="background-color:'+n+'"></div>');if("left"==a||"right"==a)var r=i.data("float-mobile");else var r=a;s.addClass(r).hide().appendTo("body");i.first().clone().addClass("nc_floater").css({width:i.outerWidth(!0),left:o}).appendTo(s),t(".swp_social_panel .swp_count").css({transition:"padding .1s linear"})}}function p(){var i=t(".swp_social_panel").first(),a=i.data("float");if("none"==a)return void jQuery(".nc_wrapper, .swp_social_panelSide").hide();t(e).width()<i.data("min-width")&&(r(),l(),d()),"right"!=a&&"left"!=a||c(),"bottom"!=a&&"top"!=a||d()}function l(){var e=(t(".swp_social_panel").first(),s()?"collapse":"visible");t(".swp_social_panelSide").hide(),t(".nc_wrapper").css("visibility",e)}function c(){var i=t(".swp_social_panel").not(".swp_social_panelSide").first(),a=t(".swp_social_panelSide"),n=a.data("float"),o=s();if(t(e).width()<i.data("min-width")&&t(".nc_wrapper").length)return void a.hide();if(i.length||(o=!(t(e).width()>a.data("min-width"))),"slide"==a.data("transition")){var r=-1!==n.indexOf("left")?"left":"right";o?a.css(r,"-150px"):a.css(r,"5px")}else o?a.css("opacity",1).fadeOut(300).css("opacity",0):a.css("opacity",0).fadeIn(300).css({opacity:1,display:"flex"})}function d(){var i=t(".swp_social_panel").first(),a=0;if(t(e).width()>t(i).data("min-width"))var n=t(i).data("float");else var n=t(i).data("float-mobile");s()?(t(".nc_wrapper").hide(),a="bottom"==n?m:g):(t(".nc_wrapper").show(),jQuery(".swp_social_panel.nc_floater").css("opacity",1),"bottom"==n?a=m+50:i.offset().top>t(e).scrollTop()+t(e).height()&&(a=g+50,t("body").animate({"padding-top":a+"px"},0)));t("body").animate({paddingProp:a},0)}function h(){var t=jQuery("[class*=float-position-center]");if(t.length){var i=t.outerHeight(),a=e.innerHeight;if(i>a)return void t.css("top",0);var n=(a-i)/2;t.css("top",n)}}function f(){0!==t(".swp_social_panel").length&&(r(),h(),b.activateHoverStates(),_(),t(e).scroll(b.throttle(50,function(){p()})),t(e).trigger("scroll"))}function u(){var a={wrap:'<div class="sw-pinit" />',pageURL:document.URL},n=t.extend(a,n);t(".swp-content-locator").parent().find("img").each(function(){var a=t(this);if(!(typeof swpPinIt.disableOnAnchors!=i&&swpPinIt.disableOnAnchors&&jQuery(a).parents().filter("a").length||a.outerHeight()<swpPinIt.minHeight||a.outerWidth()<swpPinIt.minWidth||a.hasClass("no_pin")||a.hasClass("no-pin"))){var o=!1;if(void 0!==swpPinIt.image_source){var s=new Image;s.src=swpPinIt.image_source,o=jQuery(s).src}else a.data("media")?o=a.data("media"):t(this).data("lazy-src")?o=t(this).data("lazy-src"):a[0].src&&(o=a[0].src);if(!1!==o){var r="";void 0!==a.data("pin-description")?r=a.data("pin-description"):void 0!==swpPinIt.image_description?r=swpPinIt.image_description:a.attr("title")?r=a.attr("title"):a.attr("alt")&&(r=a.attr("alt"));var p="http://pinterest.com/pin/create/bookmarklet/?media="+encodeURI(o)+"&url="+encodeURI(n.pageURL)+"&is_video=false&description="+encodeURIComponent(r),l=a.attr("class"),c=a.attr("style");a.removeClass().attr("style","").wrap(n.wrap),a.after('<a href="'+p+'" class="sw-pinit-button sw-pinit-'+swpPinIt.vLocation+" sw-pinit-"+swpPinIt.hLocation+'">Save</a>'),a.parent(".sw-pinit").addClass(l).attr("style",c),t(".sw-pinit .sw-pinit-button").on("click",function(){if(e.open(t(this).attr("href"),"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1"),!0===swpClickTracking){"function"==typeof ga&&ga("send","event","social_media","swp_pin_image_share"),"object"==typeof dataLayer&&dataLayer.push({event:"swp_pin_image_share"})}return!1})}}});var o=w();void 0!==o&&o&&v(o)}function _(){t(".nc_tweet, a.swp_CTT").off("click"),t(".nc_tweet, a.swp_CTT").on("click",function(i){if(t(this).hasClass("noPop"))return!1;if(t(this).data("link")){i.preventDefault();var a,n,o,s,r=t(this).data("link");r=r.replace("’","'"),t(this).hasClass("pinterest")||t(this).hasClass("buffer_link")||t(this).hasClass("flipboard")?(a=550,n=775):(a=270,n=500),o=e.screenY+(e.innerHeight-a)/2,s=e.screenX+(e.innerWidth-n)/2;var p="height="+a+",width="+n+",top="+o+",left="+s;e.open(r,"_blank",p);if(1==swpClickTracking){if(t(this).hasClass("nc_tweet"))var l=t(this).parents(".nc_tweetContainer").attr("data-network");else if(t(this).hasClass("swp_CTT"))var l="ctt";"function"==typeof ga&&ga("send","event","social_media","swp_"+l+"_share"),"object"==typeof dataLayer&&dataLayer.push({event:"swp_"+l+"_share"})}return!1}})}function w(){var t=null;return document.querySelectorAll("span").forEach(function(i,a){var n=e.getComputedStyle(i);"rgb(189, 8, 28)"==n.backgroundColor&&"14px 14px"==n.backgroundSize&&"8675309"==n.zIndex&&(t=i)}),t}function v(t){var i=t.nextSibling;if(void 0!==i&&"SPAN"==i.nodeName){var a=e.getComputedStyle(i);0===a.width.indexOf("24px")&&0===a.height.indexOf("24px")&&i.remove()}t.remove()}var b=e.socialWarfarePlugin,g=a(t("body").css("padding-top").replace("px","")),m=a(t("body").css("padding-bottom").replace("px","")),y={};socialWarfarePlugin.fetchFacebookShares=function(){t.when(t.get("https://graph.facebook.com/?fields=og_object{likes.summary(true).limit(0)},share&id="+swp_post_url),swp_post_recovery_url?t.get("https://graph.facebook.com/?fields=og_object{likes.summary(true).limit(0)},share&id="+swp_post_recovery_url):"").then(function(e,i){if(void 0!==e[0].share){var n=a(e[0].share.share_count),o=a(e[0].share.comment_count);if(void 0!==e[0].og_object)var s=a(e[0].og_object.likes.summary.total_count);else var s=0;var r=n+o+s;if(swp_post_recovery_url){if(void 0!==i[0].share)var p=a(i[0].share.share_count),l=a(i[0].share.comment_count);else var p=0,l=0;if(void 0!==i[0].og_object)var c=a(i[0].og_object.likes.summary.total_count);else var c=0;var d=p+l+c;r!==d&&(r+=d)}y={action:"swp_facebook_shares_update",post_id:swp_post_id,share_counts:r},t.post(swp_admin_ajax,y)}})},b.activateHoverStates=function(){n("pre_activate_buttons"),t(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer").on("mouseenter",function(){if(!t(this).hasClass("swp_nohover")){o();var e=t(this).find(".swp_share").outerWidth(),i=t(this).find("i.sw").outerWidth(),a=t(this).width(),n=1+(e+35)/a;t(this).find(".iconFiller").width(e+i+25+"px"),t(this).css({flex:n+" 1 0%"})}}),t(".swp_social_panel:not(.swp_social_panelSide)").on("mouseleave",function(){o()})},t(e).on("load",function(){"undefined"!=typeof swpPinIt&&swpPinIt.enabled&&u()}),t(document).ready(function(){_(),f();var i=t(".swp_social_panelSide"),n=!1;if(t(".swp_social_panel").hover(function(){n=!0},function(){n=!1}),t(e).resize(b.debounce(250,function(){t(".swp_social_panel").length&&!1!==n||(e.swpAdjust=1,f())})),t(document.body).on("post-load",function(){f()}),0!==i.length){if(-1!==t(i).attr("class").indexOf("swp_side"))return;var o=t(i).height(),s=t(e).height(),r=a(s/2-o/2);setTimeout(function(){t(i).animate({top:r},0)},105)}1===t(".swp-content-locator").parent().children().length&&t(".swp-content-locator").parent().hide()})}(this,jQuery),function(e){var t=/iPhone/i,i=/iPod/i,a=/iPad/i,n=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,o=/Android/i,s=/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,r=/(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,p=/Windows Phone/i,l=/(?=.*\bWindows\b)(?=.*\bARM\b)/i,c=/BlackBerry/i,d=/BB10/i,h=/Opera Mini/i,f=/(CriOS|Chrome)(?=.*\bMobile\b)/i,u=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,_=new RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),w=function(e,t){return e.test(t)},v=function(e){var v=e||navigator.userAgent,b=v.split("[FBAN");if(void 0!==b[1]&&(v=b[0]),b=v.split("Twitter"),void 0!==b[1]&&(v=b[0]),this.apple={phone:w(t,v),ipod:w(i,v),tablet:!w(t,v)&&w(a,v),device:w(t,v)||w(i,v)||w(a,v)},this.amazon={phone:w(s,v),tablet:!w(s,v)&&w(r,v),device:w(s,v)||w(r,v)},this.android={phone:w(s,v)||w(n,v),tablet:!w(s,v)&&!w(n,v)&&(w(r,v)||w(o,v)),device:w(s,v)||w(r,v)||w(n,v)||w(o,v)},this.windows={phone:w(p,v),tablet:w(l,v),device:w(p,v)||w(l,v)},this.other={blackberry:w(c,v),blackberry10:w(d,v),opera:w(h,v),firefox:w(u,v),chrome:w(f,v),device:w(c,v)||w(d,v)||w(h,v)||w(u,v)||w(f,v)},this.seven_inch=w(_,v),this.any=this.apple.device||this.android.device||this.windows.device||this.other.device||this.seven_inch,this.phone=this.apple.phone||this.android.phone||this.windows.phone,this.tablet=this.apple.tablet||this.android.tablet||this.windows.tablet,"undefined"==typeof window)return this},b=function(){var e=new v;return e.Class=v,e};"undefined"!=typeof module&&module.exports&&"undefined"==typeof window?module.exports=v:"undefined"!=typeof module&&module.exports&&"undefined"!=typeof window?module.exports=b():"function"==typeof define&&define.amd?define("swp_isMobile",[],e.swp_isMobile=b()):e.swp_isMobile=b()}(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*!
|
2 |
+
* jQuery throttle / debounce - v1.1 - 3/7/2010
|
3 |
+
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
4 |
+
*
|
5 |
+
* Copyright (c) 2010 "Cowboy" Ben Alman
|
6 |
+
* Dual licensed under the MIT and GPL licenses.
|
7 |
+
* http://benalman.com/about/license/
|
8 |
+
*/
|
9 |
+
var socialWarfarePlugin=socialWarfarePlugin||{};(function(c,d){var b;var a=c.socialWarfarePlugin;a.throttle=b=function(g,f,k,h){var i,e=0;if(typeof f!=="boolean"){h=k;k=f;f=d}function j(){var p=this,n=+new Date()-e,o=arguments;function m(){e=+new Date();k.apply(p,o)}function l(){i=d}if(h&&!i){m()}i&&clearTimeout(i);if(h===d&&n>g){m()}else{if(f!==true){i=setTimeout(h?l:m,h===d?g-n:g)}}}if(a.guid){j.guid=k.guid=k.guid||a.guid++}return j};a.debounce=function(e,f,g){return g===d?b(e,f,false):b(e,g,f!==false)}})(this);(function(l,f,h){var r=l.socialWarfarePlugin;var t=p(f("body").css("padding-top").replace("px",""));var k=p(f("body").css("padding-bottom").replace("px",""));function p(w){return parseInt(w,10)}function q(x){var w=f.Event(x);f(l).trigger(w)}var i={};socialWarfarePlugin.fetchFacebookShares=function(){f.when(f.get("https://graph.facebook.com/?fields=og_object{likes.summary(true).limit(0)},share&id="+swp_post_url),(swp_post_recovery_url?f.get("https://graph.facebook.com/?fields=og_object{likes.summary(true).limit(0)},share&id="+swp_post_recovery_url):"")).then(function(F,E){if("undefined"!==typeof F[0].share){var D=p(F[0].share.share_count);var C=p(F[0].share.comment_count);if("undefined"!==typeof F[0].og_object){var B=p(F[0].og_object.likes.summary.total_count)}else{var B=0}var w=D+C+B;if(swp_post_recovery_url){if(typeof E[0].share!=="undefined"){var A=p(E[0].share.share_count);var z=p(E[0].share.comment_count)}else{var A=0,z=0}if(typeof E[0].og_object!=="undefined"){var x=p(E[0].og_object.likes.summary.total_count)}else{var x=0}var y=A+z+x;if(w!==y){w=w+y}}i={action:"swp_facebook_shares_update",post_id:swp_post_id,share_counts:w};f.post(swp_admin_ajax,i)}})};r.activateHoverStates=function(){q("pre_activate_buttons");f(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer").on("mouseenter",function(){if(!f(this).hasClass("swp_nohover")){v();var y=f(this).find(".swp_share").outerWidth();var x=f(this).find("i.sw").outerWidth();var z=f(this).width();var w=1+((y+35)/z);f(this).find(".iconFiller").width(y+x+25+"px");f(this).css({flex:w+" 1 0%"})}});f(".swp_social_panel:not(.swp_social_panelSide)").on("mouseleave",function(){v()})};function v(){f(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer:not(.swp_nohover) .iconFiller").removeAttr("style");f(".swp_social_panel:not(.swp_social_panelSide) .nc_tweetContainer:not(.swp_nohover)").removeAttr("style")}function e(){var w=f(".swp_social_panel").not(".swp_social_panelSide").first();var x=false;var y=f(l).scrollTop();f(".swp_social_panel").not(".swp_social_panelSide, .nc_floater").each(function(A){var B=f(this).offset();if(typeof swpFloatBeforeContent!="undefined"&&false===swpFloatBeforeContent){var z=jQuery(".swp-content-locator").parent();if(A===0&&z.length&&z.offset().top>(y+jQuery(l).height())){x=true}}if((B.top+f(this).height())>y&&B.top<(y+f(l).height())){x=true}});return x}function n(){if(f(".nc_wrapper").length){f(".nc_wrapper").remove()}var x=f(".swp_social_panel");var A=x.data("float");if(typeof x=="undefined"){return}if(f(l).width()>x.data("min-width")&&A!="top"&&A!="bottom"){return}var y=x.data("float-color");var z=x.data("align")=="center"?0:x.offset().left;var C=f('<div class="nc_wrapper" style="background-color:'+y+'"></div>');if(A=="left"||A=="right"){var w=x.data("float-mobile")}else{var w=A}C.addClass(w).hide().appendTo("body");var B=x.first().clone();B.addClass("nc_floater").css({width:x.outerWidth(true),left:z}).appendTo(C);f(".swp_social_panel .swp_count").css({transition:"padding .1s linear"})}function d(){var x=f(".swp_social_panel").first();var w=x.data("float");if(w=="none"){jQuery(".nc_wrapper, .swp_social_panelSide").hide();return}if(f(l).width()<x.data("min-width")){n();c();j()}if(w=="right"||w=="left"){m()}if(w=="bottom"||w=="top"){j()}}function c(){var x=f(".swp_social_panel").first();var w=e()?"collapse":"visible";f(".swp_social_panelSide").hide();f(".nc_wrapper").css("visibility",w)}function m(){var x=f(".swp_social_panel").not(".swp_social_panelSide").first();var y=f(".swp_social_panelSide");var w=y.data("float");var A=e();if(f(l).width()<x.data("min-width")&&f(".nc_wrapper").length){y.hide();return}if(!x.length){if(f(l).width()>y.data("min-width")){A=false}else{A=true}}if(y.data("transition")=="slide"){var z=(w.indexOf("left")!==-1)?"left":"right";if(A){y.css(z,"-150px")}else{y.css(z,"5px")}}else{if(A){y.css("opacity",1).fadeOut(300).css("opacity",0)}else{y.css("opacity",0).fadeIn(300).css({opacity:1,display:"flex"})}}}function j(){var x=f(".swp_social_panel").first();var y=0;if(f(l).width()>f(x).data("min-width")){var w=f(x).data("float")}else{var w=f(x).data("float-mobile")}if(e()){f(".nc_wrapper").hide();y=(w=="bottom")?k:t}else{f(".nc_wrapper").show();jQuery(".swp_social_panel.nc_floater").css("opacity",1);if(w=="bottom"){y=k+50}else{if(x.offset().top>f(l).scrollTop()+f(l).height()){y=t+50;f("body").animate({"padding-top":y+"px"},0)}}}var z="padding-"+w;f("body").animate({paddingProp:y},0)}function u(){var x=jQuery("[class*=float-position-center]");if(!x.length){return}var w=x.outerHeight();var z=l.innerHeight;if(w>z){x.css("top",0);return}var y=(z-w)/2;x.css("top",y)}function b(){if(0!==f(".swp_social_panel").length){n();u();r.activateHoverStates();s();f(l).scroll(r.throttle(50,function(){d()}));f(l).trigger("scroll")}}function g(){var y={wrap:'<div class="sw-pinit" />',pageURL:document.URL};var w=f.extend(y,w);f(".swp-content-locator").parent().find("img").each(function(){var E=f(this);if(typeof swpPinIt.disableOnAnchors!=h&&swpPinIt.disableOnAnchors){if(jQuery(E).parents().filter("a").length){return}}if(E.outerHeight()<swpPinIt.minHeight||E.outerWidth()<swpPinIt.minWidth){return}if(E.hasClass("no_pin")||E.hasClass("no-pin")){return}var C;if("undefined"!==typeof swpPinIt.image_source){var A=new Image();A.src=swpPinIt.image_source;C=jQuery(A).prop("src")}else{if(E.data("media")){C=E.data("media")}else{if(f(this).data("lazy-src")){C=f(this).data("lazy-src")}else{if(E[0].src){C=E[0].src}}}}if(!C||"undefined"===typeof C){return}var F="";if(typeof E.data("pin-description")!="undefined"){F=E.data("pin-description")}else{if("undefined"!==typeof swpPinIt.image_description){F=swpPinIt.image_description}else{if(E.attr("title")){F=E.attr("title")}else{if(E.attr("alt")){F=E.attr("alt")}}}}var B="http://pinterest.com/pin/create/bookmarklet/?media="+encodeURI(C)+"&url="+encodeURI(w.pageURL)+"&is_video=false&description="+encodeURIComponent(F);var D=E.attr("class");var z=E.attr("style");E.removeClass().attr("style","").wrap(w.wrap);E.after('<a href="'+B+'" class="sw-pinit-button sw-pinit-'+swpPinIt.vLocation+" sw-pinit-"+swpPinIt.hLocation+'">Save</a>');E.parent(".sw-pinit").addClass(D).attr("style",z);f(".sw-pinit .sw-pinit-button").on("click",function(){l.open(f(this).attr("href"),"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1");if(true===swpClickTracking){var G="pin_image";if("function"==typeof ga){ga("send","event","social_media","swp_"+G+"_share")}if("object"==typeof dataLayer){dataLayer.push({event:"swp_"+G+"_share"})}}return false})});var x=a();if(typeof x!="undefined"&&x){o(x)}}function s(){f(".nc_tweet, a.swp_CTT").off("click");f(".nc_tweet, a.swp_CTT").on("click",function(w){if(f(this).hasClass("noPop")){return false}if(f(this).data("link")){w.preventDefault();var x=f(this).data("link");var F,y,D,A,E,C;x=x.replace("’","'");if(f(this).hasClass("pinterest")||f(this).hasClass("buffer_link")||f(this).hasClass("flipboard")){F=550;y=775}else{F=270;y=500}D=l.screenY+(l.innerHeight-F)/2;A=l.screenX+(l.innerWidth-y)/2;var B="height="+F+",width="+y+",top="+D+",left="+A;var E=l.open(x,"_blank",B);if(true==swpClickTracking){if(f(this).hasClass("nc_tweet")){var z=f(this).parents(".nc_tweetContainer").attr("data-network")}else{if(f(this).hasClass("swp_CTT")){var z="ctt"}}if(typeof ga=="function"&&true){ga("send","event","social_media","swp_"+z+"_share")}if("object"==typeof dataLayer){dataLayer.push({event:"swp_"+z+"_share"})}}return false}})}function a(){var z="rgb(189, 8, 28)";var w="8675309";var y="14px 14px";var x=null;document.querySelectorAll("span").forEach(function(C,A){var B=l.getComputedStyle(C);if(B.backgroundColor==z){if(B.backgroundSize==y&&B.zIndex==w){x=C}}});return x}function o(x){var z=x.nextSibling;if(typeof z!="undefined"&&z.nodeName=="SPAN"){var y=l.getComputedStyle(z);var w="24px";if(y.width.indexOf(w)===0&&y.height.indexOf(w)===0){z.remove()}}x.remove()}f(l).on("load",function(){if("undefined"!==typeof swpPinIt&&swpPinIt.enabled){g()}});f(document).ready(function(){s();b();var z=f(".swp_social_panelSide");var y=false;f(".swp_social_panel").hover(function(){y=true},function(){y=false});f(l).resize(r.debounce(250,function(){if(f(".swp_social_panel").length&&false!==y){}else{l.swpAdjust=1;b()}}));f(document.body).on("post-load",function(){b()});if(0!==z.length){if(f(z).attr("class").indexOf("swp_side")!==-1){return}var w=f(z).height();var A=f(l).height();var x=p((A/2)-(w/2));setTimeout(function(){f(z).animate({top:x},0)},105)}if(1===f(".swp-content-locator").parent().children().length){f(".swp-content-locator").parent().hide()}})})(this,jQuery);(function(k){var b=/iPhone/i,m=/iPod/i,j=/iPad/i,o=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,p=/Android/i,l=/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,h=/(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,g=/Windows Phone/i,q=/(?=.*\bWindows\b)(?=.*\bARM\b)/i,n=/BlackBerry/i,a=/BB10/i,c=/Opera Mini/i,d=/(CriOS|Chrome)(?=.*\bMobile\b)/i,s=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,i=new RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i");var f=function(t,u){return t.test(u)};var e=function(v){var u=v||navigator.userAgent;var t=u.split("[FBAN");if(typeof t[1]!=="undefined"){u=t[0]}t=u.split("Twitter");if(typeof t[1]!=="undefined"){u=t[0]}this.apple={phone:f(b,u),ipod:f(m,u),tablet:!f(b,u)&&f(j,u),device:f(b,u)||f(m,u)||f(j,u)};this.amazon={phone:f(l,u),tablet:!f(l,u)&&f(h,u),device:f(l,u)||f(h,u)};this.android={phone:f(l,u)||f(o,u),tablet:!f(l,u)&&!f(o,u)&&(f(h,u)||f(p,u)),device:f(l,u)||f(h,u)||f(o,u)||f(p,u)};this.windows={phone:f(g,u),tablet:f(q,u),device:f(g,u)||f(q,u)};this.other={blackberry:f(n,u),blackberry10:f(a,u),opera:f(c,u),firefox:f(s,u),chrome:f(d,u),device:f(n,u)||f(a,u)||f(c,u)||f(s,u)||f(d,u)};this.seven_inch=f(i,u);this.any=this.apple.device||this.android.device||this.windows.device||this.other.device||this.seven_inch;this.phone=this.apple.phone||this.android.phone||this.windows.phone;this.tablet=this.apple.tablet||this.android.tablet||this.windows.tablet;if(typeof window==="undefined"){return this}};var r=function(){var t=new e();t.Class=e;return t};if(typeof module!=="undefined"&&module.exports&&typeof window==="undefined"){module.exports=e}else{if(typeof module!=="undefined"&&module.exports&&typeof window!=="undefined"){module.exports=r()}else{if(typeof define==="function"&&define.amd){define("swp_isMobile",[],k.swp_isMobile=r())}else{k.swp_isMobile=r()}}}})(this);
|
lib/Social_Warfare.php
CHANGED
@@ -34,6 +34,7 @@ class Social_Warfare {
|
|
34 |
*/
|
35 |
public function __construct() {
|
36 |
$this->core_version = SWP_VERSION;
|
|
|
37 |
add_action('plugins_loaded', array($this, 'init'));
|
38 |
}
|
39 |
|
34 |
*/
|
35 |
public function __construct() {
|
36 |
$this->core_version = SWP_VERSION;
|
37 |
+
require_once SWP_PLUGIN_DIR . '/lib/utilities/functions.php';
|
38 |
add_action('plugins_loaded', array($this, 'init'));
|
39 |
}
|
40 |
|
lib/frontend-output/SWP_Buttons_Panel.php
CHANGED
@@ -393,6 +393,14 @@ class SWP_Buttons_Panel {
|
|
393 |
}
|
394 |
|
395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
protected function establish_permalink() {
|
397 |
$this->permalink = get_permalink( $this->post_id );
|
398 |
}
|
@@ -410,27 +418,30 @@ class SWP_Buttons_Panel {
|
|
410 |
*
|
411 |
*
|
412 |
* @return Boolean True if the buttons are okay to print, else false.
|
413 |
-
* @since 3.0.8
|
414 |
* (for calls to social_warfare()).
|
|
|
415 |
* @param void
|
416 |
* @return void
|
417 |
*
|
418 |
*/
|
419 |
public function should_print() {
|
420 |
|
421 |
-
|
422 |
-
|
|
|
|
|
|
|
|
|
423 |
return true;
|
424 |
-
|
425 |
-
|
426 |
-
$user_settings = $this->location !== 'none';
|
427 |
-
|
428 |
-
$desired_conditions = is_main_query() && get_post_status( $this->post_id ) === 'publish';
|
429 |
|
|
|
|
|
430 |
$undesired_conditions = is_admin() || is_feed() || is_search() || is_attachment();
|
431 |
|
432 |
return $user_settings && $desired_conditions && !$undesired_conditions;
|
433 |
-
|
434 |
|
435 |
|
436 |
/**
|
@@ -440,12 +451,13 @@ class SWP_Buttons_Panel {
|
|
440 |
* @since 3.0.3 | 09 MAY 2018 | Switched the button locations to use the
|
441 |
* location methods instead of the raw options value.
|
442 |
* @since 3.0.6 | 15 MAY 2018 | Uses $this->option() method to prevent undefined index error.
|
|
|
443 |
* @param boolean $echo Echo's the content or returns it if false.
|
444 |
* @return string The string of HTML.
|
445 |
*
|
446 |
*/
|
447 |
public function render_HTML( $echo = false ) {
|
448 |
-
if ( !isset( $this->post_id ) ) :
|
449 |
return;
|
450 |
endif;
|
451 |
|
@@ -465,14 +477,15 @@ class SWP_Buttons_Panel {
|
|
465 |
$this->get_shape() .
|
466 |
$this->get_colors() .
|
467 |
$this->get_scale() .
|
|
|
468 |
'" ' . // end CSS classes
|
469 |
$this->get_min_width() .
|
470 |
$this->get_float_background() .
|
471 |
//* These below two data-attribute methods are inconsistent. But they
|
472 |
//* already existed and are used elsewhere, so I'm not touching them.
|
473 |
-
'" data-float="' . $this->get_float_location() .
|
474 |
-
'
|
475 |
-
'
|
476 |
|
477 |
$total_shares_html = $this->render_total_shares_html();
|
478 |
$buttons = $this->render_buttons_html();
|
@@ -496,69 +509,170 @@ class SWP_Buttons_Panel {
|
|
496 |
}
|
497 |
|
498 |
|
499 |
-
|
500 |
-
|
|
|
501 |
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
|
509 |
|
510 |
-
|
511 |
-
|
512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
513 |
}
|
514 |
|
515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
protected function get_shape() {
|
517 |
$button_shape = $this->option( 'button_shape' );
|
518 |
|
519 |
//* They have gone from an Addon to Core.
|
520 |
-
if ( false === $button_shape )
|
521 |
return " swp_flat_fresh ";
|
522 |
-
|
523 |
|
524 |
return " swp_{$button_shape} ";
|
525 |
}
|
526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
protected function get_scale() {
|
528 |
$button_size = $this->option( 'button_size' );
|
529 |
|
530 |
//* They have gone from an Addon to Core.
|
531 |
-
if ( false === $button_size )
|
532 |
return " scale-100 ";
|
533 |
-
|
534 |
|
535 |
return ' scale-' . $button_size * 100;
|
536 |
}
|
537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
protected function get_min_width() {
|
539 |
$min_width = $this->option( 'float_screen_width' );
|
540 |
|
541 |
//* They have gone from an Addon to Core.
|
542 |
-
if ( false === $min_width )
|
543 |
return 'data-min-width="1100" ';
|
544 |
-
|
545 |
|
546 |
return " data-min-width='{$min_width}' ";
|
547 |
}
|
548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
protected function get_float_background() {
|
550 |
$float_background_color = $this->option( 'float_background_color' );
|
551 |
|
552 |
//* They have gone from an Addon to Core.
|
553 |
-
if ( false === $float_background_color )
|
554 |
return " ";
|
555 |
-
|
556 |
|
557 |
return '" data-float-color="' . $float_background_color;
|
558 |
}
|
559 |
|
560 |
|
561 |
-
|
562 |
/**
|
563 |
* A function to avoid getting undefined index notices.
|
564 |
*
|
@@ -568,11 +682,11 @@ class SWP_Buttons_Panel {
|
|
568 |
*
|
569 |
*/
|
570 |
private function option($key) {
|
571 |
-
if( isset( $this->options[$key] ) )
|
572 |
return $this->options[$key];
|
573 |
-
else
|
574 |
return SWP_Utility::get_option( $key );
|
575 |
-
|
576 |
}
|
577 |
|
578 |
|
@@ -593,28 +707,28 @@ class SWP_Buttons_Panel {
|
|
593 |
public function get_float_location() {
|
594 |
$post_on = false;
|
595 |
|
596 |
-
if( is_home() && !is_front_page() || !isset( $this->post_id ) )
|
597 |
return 'none';
|
598 |
-
|
599 |
|
600 |
$post_setting = get_post_meta( $this->post_id, 'swp_float_location', true );
|
601 |
|
602 |
-
if( is_array( $post_setting ) )
|
603 |
$post_setting = $post_setting[0];
|
604 |
-
|
605 |
|
606 |
// If the location is set in the post options, use that.
|
607 |
if ( !empty( $post_setting ) && 'default' != $post_setting ) {
|
608 |
-
if( 'off' === $post_setting)
|
609 |
return 'none';
|
610 |
-
|
611 |
|
612 |
$post_on = true;
|
613 |
};
|
614 |
|
615 |
-
if ( $post_on || is_singular() && true === $this->option('floating_panel') && 'on' === $this->option('float_location_' . $this->post_data['post_type'] ) )
|
616 |
return $this->option('float_location');
|
617 |
-
|
618 |
|
619 |
return 'none';
|
620 |
}
|
@@ -635,9 +749,9 @@ class SWP_Buttons_Panel {
|
|
635 |
*
|
636 |
*/
|
637 |
public function get_mobile_float_location() {
|
638 |
-
if( is_single() && true == $this->option('floating_panel') && 'on' == $this->option('float_location_' . $this->post_data['post_type'] ) )
|
639 |
return $this->option('float_mobile');
|
640 |
-
|
641 |
|
642 |
return 'none';
|
643 |
}
|
@@ -655,11 +769,11 @@ class SWP_Buttons_Panel {
|
|
655 |
public function render_floating_HTML( $echo = true ) {
|
656 |
$blacklist = ['none', 'top', 'bottom'];
|
657 |
|
658 |
-
if ( in_array( $this->option('float_location'), $blacklist ) )
|
659 |
return '';
|
660 |
-
|
661 |
|
662 |
-
if( is_singular() && 'none' !== $this->get_float_location() )
|
663 |
|
664 |
//* BEGIN Old boilerplate that needs to be refactored.
|
665 |
$class = "";
|
@@ -667,32 +781,26 @@ class SWP_Buttons_Panel {
|
|
667 |
$side = $this->option('float_location');
|
668 |
$max_buttons = $this->option( 'float_button_count' );
|
669 |
|
670 |
-
if( false == $max_buttons || 0 == $max_buttons )
|
671 |
$max_buttons = 5;
|
672 |
-
|
673 |
|
674 |
|
675 |
-
if ( 'none' != $this->get_float_location() )
|
676 |
$float_location = $this->option('float_location');
|
677 |
$class = "swp_float_" . $this->option('float_location');
|
678 |
-
|
679 |
-
|
680 |
-
if ( isset( $this->options['float_style_source'] ) && true == $this->options['float_style_source'] ) :
|
681 |
-
$this->options['float_default_colors'] = $this->option('default_colors');
|
682 |
-
$this->options['float_single_colors'] = $this->option('single_colors');
|
683 |
-
$this->options['float_hover_colors'] = $this->option('hover_colors');
|
684 |
-
endif;
|
685 |
|
686 |
// *Get the vertical position
|
687 |
-
if ($this->option('float_alignment') )
|
688 |
$class .= " swp_side_" . $this->option('float_alignment');
|
689 |
-
|
690 |
|
691 |
// *Set button size
|
692 |
-
if ( isset($this->options['float_size']) )
|
693 |
$position = $this->option('float_alignment');
|
694 |
$class .= " scale-${size} float-position-${position}-${side}";
|
695 |
-
|
696 |
|
697 |
//* END old boilerplate.
|
698 |
|
@@ -700,7 +808,7 @@ class SWP_Buttons_Panel {
|
|
700 |
$buttons = $this->render_buttons_HTML( (int) $max_buttons );
|
701 |
|
702 |
$container = '<div class="swp_social_panelSide swp_floating_panel swp_social_panel swp_' . $this->option('float_button_shape') .
|
703 |
-
$this->get_colors() .
|
704 |
$this->option('transition') . '
|
705 |
' . $class . '
|
706 |
' . '" data-panel-position="' . $this->option('location_post') .
|
@@ -712,21 +820,21 @@ class SWP_Buttons_Panel {
|
|
712 |
'" data-transition="' . $this->option('transition') .
|
713 |
'" data-float-mobile="' . $this->get_mobile_float_location() .'">';
|
714 |
|
715 |
-
if ($this->option('totals_alignment') === 'totals_left')
|
716 |
$buttons = $share_counts . $buttons;
|
717 |
-
else
|
718 |
$buttons .= $share_counts;
|
719 |
-
|
720 |
|
721 |
$html = $container . $buttons . '</div>';
|
722 |
$this->html = $html;
|
723 |
|
724 |
-
if ( $echo )
|
725 |
echo $html;
|
726 |
-
|
727 |
|
728 |
return $html;
|
729 |
-
|
730 |
|
731 |
}
|
732 |
|
@@ -867,13 +975,13 @@ class SWP_Buttons_Panel {
|
|
867 |
* If share counts are active, renders the Total Share Counts HTML.
|
868 |
*
|
869 |
* @since 3.0.0 | 18 APR 2018 | Created
|
870 |
-
* @
|
871 |
-
*
|
872 |
* @return string $html The fully qualified HTML to display share counts.
|
873 |
*
|
874 |
*/
|
875 |
public function render_total_shares_html() {
|
876 |
-
$buttons = isset( $this->args['buttons'] ) ?
|
877 |
|
878 |
if ( false == $this->option('total_shares') ) {
|
879 |
return '';
|
@@ -883,7 +991,8 @@ class SWP_Buttons_Panel {
|
|
883 |
return '';
|
884 |
}
|
885 |
|
886 |
-
$totals_argument = in_array(
|
|
|
887 |
|
888 |
if ( $this->is_shortcode && !$totals_argument ) {
|
889 |
return '';
|
@@ -942,24 +1051,36 @@ class SWP_Buttons_Panel {
|
|
942 |
* Runs checks before ordering a set of buttons.
|
943 |
*
|
944 |
* @since 3.0.6 | 14 MAY 2018 | Removed the swp-content-locator div.
|
|
|
945 |
* @param string $content The WordPress content, if passed in.
|
946 |
* @return function @see $this->do_print
|
947 |
*
|
948 |
*/
|
949 |
public function the_buttons( $content = null ) {
|
950 |
-
if ( empty( $this->content ) ) :
|
951 |
-
return $this->do_print();
|
952 |
-
endif;
|
953 |
|
954 |
-
|
955 |
-
|
956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
957 |
|
958 |
-
if ( null !== $content && gettype( $content ) === 'string' ) :
|
959 |
-
$this->args['content'] = $content;
|
960 |
-
endif;
|
961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
962 |
|
|
|
|
|
|
|
963 |
|
964 |
return $this->do_print();
|
965 |
}
|
393 |
}
|
394 |
|
395 |
|
396 |
+
/**
|
397 |
+
* A method for fetching the permalink.
|
398 |
+
*
|
399 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
400 |
+
* @param void
|
401 |
+
* @return void Values are stored in $this->permalink.
|
402 |
+
*
|
403 |
+
*/
|
404 |
protected function establish_permalink() {
|
405 |
$this->permalink = get_permalink( $this->post_id );
|
406 |
}
|
418 |
*
|
419 |
*
|
420 |
* @return Boolean True if the buttons are okay to print, else false.
|
421 |
+
* @since 3.0.8 | 21 MAY 2018 | Added extra condition to check for content
|
422 |
* (for calls to social_warfare()).
|
423 |
+
* @since 3.3.3 | 18 SEP 2018 | Added check for in_the_loop().
|
424 |
* @param void
|
425 |
* @return void
|
426 |
*
|
427 |
*/
|
428 |
public function should_print() {
|
429 |
|
430 |
+
/**
|
431 |
+
* WordPress requires title and content. This indicates the buttons are
|
432 |
+
* called via social_warfare() or via the shortcode.
|
433 |
+
*
|
434 |
+
*/
|
435 |
+
if ( empty( $this->content ) && !isset( $this->args['content'] ) ) {
|
436 |
return true;
|
437 |
+
}
|
|
|
|
|
|
|
|
|
438 |
|
439 |
+
$user_settings = 'none' !== $this->location;
|
440 |
+
$desired_conditions = is_main_query() && in_the_loop() && get_post_status( $this->post_id ) === 'publish';
|
441 |
$undesired_conditions = is_admin() || is_feed() || is_search() || is_attachment();
|
442 |
|
443 |
return $user_settings && $desired_conditions && !$undesired_conditions;
|
444 |
+
}
|
445 |
|
446 |
|
447 |
/**
|
451 |
* @since 3.0.3 | 09 MAY 2018 | Switched the button locations to use the
|
452 |
* location methods instead of the raw options value.
|
453 |
* @since 3.0.6 | 15 MAY 2018 | Uses $this->option() method to prevent undefined index error.
|
454 |
+
* @since 3.3.1 | 13 SEP 2018 | Added get_alignment()
|
455 |
* @param boolean $echo Echo's the content or returns it if false.
|
456 |
* @return string The string of HTML.
|
457 |
*
|
458 |
*/
|
459 |
public function render_HTML( $echo = false ) {
|
460 |
+
if ( !isset( $this->post_id ) || is_preview() ) :
|
461 |
return;
|
462 |
endif;
|
463 |
|
477 |
$this->get_shape() .
|
478 |
$this->get_colors() .
|
479 |
$this->get_scale() .
|
480 |
+
$this->get_alignment() .
|
481 |
'" ' . // end CSS classes
|
482 |
$this->get_min_width() .
|
483 |
$this->get_float_background() .
|
484 |
//* These below two data-attribute methods are inconsistent. But they
|
485 |
//* already existed and are used elsewhere, so I'm not touching them.
|
486 |
+
'" data-float="' . $this->get_float_location() . '"' .
|
487 |
+
' data-float-mobile="' . $this->get_mobile_float_location() . '"' .
|
488 |
+
' style="' . $style . '" >';
|
489 |
|
490 |
$total_shares_html = $this->render_total_shares_html();
|
491 |
$buttons = $this->render_buttons_html();
|
509 |
}
|
510 |
|
511 |
|
512 |
+
protected function get_alignment() {
|
513 |
+
return ' scale-' . $this->option('button_alignment');
|
514 |
+
}
|
515 |
|
516 |
+
|
517 |
+
/**
|
518 |
+
* A function to get the color states for this buttons panel.
|
519 |
+
*
|
520 |
+
* All of the buttons contain 3 states: default, hover, and single. The
|
521 |
+
* default state is what the buttons look like when not being interacted
|
522 |
+
* with. The hover is what all the buttons in the panel look like when
|
523 |
+
* the panel is being hovered. The single is what the individual button
|
524 |
+
* being hovered will look like.
|
525 |
+
*
|
526 |
+
* This method handles generating the classes that the CSS can target to
|
527 |
+
* ensure that all three of those states work.
|
528 |
+
*
|
529 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
530 |
+
* @since 3.3.2 | 13 SEP 2018 | Modified to control float selectors better
|
531 |
+
* @param boolean $float Whether this is a floating panel or not.
|
532 |
+
* @return string The string of CSS classes to be used on the panel.
|
533 |
+
*
|
534 |
+
*/
|
535 |
+
protected function get_colors( $float = false ) {
|
536 |
+
|
537 |
+
|
538 |
+
/**
|
539 |
+
* If pro was installed, but no longer is installed or activated,
|
540 |
+
* then this option won't exist and will return false. If so, then
|
541 |
+
* we output the default core color/style classes.
|
542 |
+
*
|
543 |
+
*/
|
544 |
+
if ( false === $this->option( 'default_colors' ) ) {
|
545 |
+
return " swp_default_full_color swp_individual_full_color swp_other_full_color ";
|
546 |
+
}
|
547 |
+
|
548 |
+
|
549 |
+
/**
|
550 |
+
* If the buttons are the static horizontal buttons (not the float),
|
551 |
+
* or if it is the float but we are inheriting the styles from the
|
552 |
+
* horizontal buttons, then just output the CSS classes that are used
|
553 |
+
* for the horizontal buttons.
|
554 |
+
*
|
555 |
+
* "float_style_source" on the options page is actually answering
|
556 |
+
* the question "Do the floating buttons inherit their colors from
|
557 |
+
* the horizontal buttons?" It will be true if they do, and false if
|
558 |
+
* they don't.
|
559 |
+
*
|
560 |
+
*/
|
561 |
+
$prefix = '';
|
562 |
|
563 |
|
564 |
+
/**
|
565 |
+
* If this is a set of floating buttons and we are not inheriting
|
566 |
+
* the color styles from the static floating buttons, then we need
|
567 |
+
* to return the style classes that are specific to the floating
|
568 |
+
* buttons being rendered.
|
569 |
+
*
|
570 |
+
*/
|
571 |
+
if( true === $float && false === $this->options['float_style_source'] ) {
|
572 |
+
$prefix = 'float_';
|
573 |
+
}
|
574 |
+
|
575 |
+
|
576 |
+
/**
|
577 |
+
*
|
578 |
+
* If it's a static, horizontal panel, there is no prefix. If it's
|
579 |
+
* a floating panel, there is a prefix. However, the prefix needs
|
580 |
+
* to be removed for the CSS class name that is actualy output.
|
581 |
+
*
|
582 |
+
* So here we fetch the appropriate color options, strip out the
|
583 |
+
* "float_" prefix since we don't use that on the actual CSS
|
584 |
+
* selector, and then return the CSS classes that will be added to
|
585 |
+
* this buttons panel that is being rendered.
|
586 |
+
*
|
587 |
+
*/
|
588 |
+
$default = str_replace( $prefix, '', $this->option( $prefix . 'default_colors' ) );
|
589 |
+
$hover = str_replace( $prefix, '', $this->option( $prefix . 'hover_colors' ) );
|
590 |
+
$single = str_replace( $prefix, '', $this->option( $prefix . 'single_colors' ) );
|
591 |
+
return " swp_default_{$default} swp_other_{$hover} swp_individual_{$single} ";
|
592 |
+
|
593 |
}
|
594 |
|
595 |
|
596 |
+
/**
|
597 |
+
* A method to fetch/determine the shape of the current buttons.
|
598 |
+
*
|
599 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
600 |
+
* @param void
|
601 |
+
* @return string The string of the CSS class to be used.
|
602 |
+
*
|
603 |
+
*/
|
604 |
protected function get_shape() {
|
605 |
$button_shape = $this->option( 'button_shape' );
|
606 |
|
607 |
//* They have gone from an Addon to Core.
|
608 |
+
if ( false === $button_shape ) {
|
609 |
return " swp_flat_fresh ";
|
610 |
+
}
|
611 |
|
612 |
return " swp_{$button_shape} ";
|
613 |
}
|
614 |
|
615 |
+
|
616 |
+
/**
|
617 |
+
* A method to fetch/determine the size/scale of the panel.
|
618 |
+
*
|
619 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
620 |
+
* @param void
|
621 |
+
* @return string The CSS class to be added to the panel.
|
622 |
+
*
|
623 |
+
*/
|
624 |
protected function get_scale() {
|
625 |
$button_size = $this->option( 'button_size' );
|
626 |
|
627 |
//* They have gone from an Addon to Core.
|
628 |
+
if ( false === $button_size ) {
|
629 |
return " scale-100 ";
|
630 |
+
}
|
631 |
|
632 |
return ' scale-' . $button_size * 100;
|
633 |
}
|
634 |
|
635 |
+
|
636 |
+
/**
|
637 |
+
* A method for getting the minimum width of the buttons panel.
|
638 |
+
*
|
639 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
640 |
+
* @param void
|
641 |
+
* @return string The HTML attribute to be added to the buttons panel.
|
642 |
+
*
|
643 |
+
*/
|
644 |
protected function get_min_width() {
|
645 |
$min_width = $this->option( 'float_screen_width' );
|
646 |
|
647 |
//* They have gone from an Addon to Core.
|
648 |
+
if ( false === $min_width ) {
|
649 |
return 'data-min-width="1100" ';
|
650 |
+
}
|
651 |
|
652 |
return " data-min-width='{$min_width}' ";
|
653 |
}
|
654 |
|
655 |
+
|
656 |
+
/**
|
657 |
+
* A method to determin the background color of the floating buttons.
|
658 |
+
*
|
659 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
660 |
+
* @param void
|
661 |
+
* @return string The HTML attribute to be added to the buttons panel.
|
662 |
+
*
|
663 |
+
*/
|
664 |
protected function get_float_background() {
|
665 |
$float_background_color = $this->option( 'float_background_color' );
|
666 |
|
667 |
//* They have gone from an Addon to Core.
|
668 |
+
if ( false === $float_background_color ) {
|
669 |
return " ";
|
670 |
+
}
|
671 |
|
672 |
return '" data-float-color="' . $float_background_color;
|
673 |
}
|
674 |
|
675 |
|
|
|
676 |
/**
|
677 |
* A function to avoid getting undefined index notices.
|
678 |
*
|
682 |
*
|
683 |
*/
|
684 |
private function option($key) {
|
685 |
+
if( isset( $this->options[$key] ) ) {
|
686 |
return $this->options[$key];
|
687 |
+
} else {
|
688 |
return SWP_Utility::get_option( $key );
|
689 |
+
}
|
690 |
}
|
691 |
|
692 |
|
707 |
public function get_float_location() {
|
708 |
$post_on = false;
|
709 |
|
710 |
+
if( is_home() && !is_front_page() || !isset( $this->post_id ) ) {
|
711 |
return 'none';
|
712 |
+
}
|
713 |
|
714 |
$post_setting = get_post_meta( $this->post_id, 'swp_float_location', true );
|
715 |
|
716 |
+
if( is_array( $post_setting ) ) {
|
717 |
$post_setting = $post_setting[0];
|
718 |
+
}
|
719 |
|
720 |
// If the location is set in the post options, use that.
|
721 |
if ( !empty( $post_setting ) && 'default' != $post_setting ) {
|
722 |
+
if( 'off' === $post_setting) {
|
723 |
return 'none';
|
724 |
+
}
|
725 |
|
726 |
$post_on = true;
|
727 |
};
|
728 |
|
729 |
+
if ( $post_on || is_singular() && true === $this->option('floating_panel') && 'on' === $this->option('float_location_' . $this->post_data['post_type'] ) ) {
|
730 |
return $this->option('float_location');
|
731 |
+
}
|
732 |
|
733 |
return 'none';
|
734 |
}
|
749 |
*
|
750 |
*/
|
751 |
public function get_mobile_float_location() {
|
752 |
+
if( is_single() && true == $this->option('floating_panel') && 'on' == $this->option('float_location_' . $this->post_data['post_type'] ) ) {
|
753 |
return $this->option('float_mobile');
|
754 |
+
}
|
755 |
|
756 |
return 'none';
|
757 |
}
|
769 |
public function render_floating_HTML( $echo = true ) {
|
770 |
$blacklist = ['none', 'top', 'bottom'];
|
771 |
|
772 |
+
if ( in_array( $this->option('float_location'), $blacklist ) || is_preview() ) {
|
773 |
return '';
|
774 |
+
}
|
775 |
|
776 |
+
if( is_singular() && 'none' !== $this->get_float_location() ) {
|
777 |
|
778 |
//* BEGIN Old boilerplate that needs to be refactored.
|
779 |
$class = "";
|
781 |
$side = $this->option('float_location');
|
782 |
$max_buttons = $this->option( 'float_button_count' );
|
783 |
|
784 |
+
if( false == $max_buttons || 0 == $max_buttons ) {
|
785 |
$max_buttons = 5;
|
786 |
+
}
|
787 |
|
788 |
|
789 |
+
if ( 'none' != $this->get_float_location() ) {
|
790 |
$float_location = $this->option('float_location');
|
791 |
$class = "swp_float_" . $this->option('float_location');
|
792 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
793 |
|
794 |
// *Get the vertical position
|
795 |
+
if ($this->option('float_alignment') ) {
|
796 |
$class .= " swp_side_" . $this->option('float_alignment');
|
797 |
+
}
|
798 |
|
799 |
// *Set button size
|
800 |
+
if ( isset($this->options['float_size']) ) {
|
801 |
$position = $this->option('float_alignment');
|
802 |
$class .= " scale-${size} float-position-${position}-${side}";
|
803 |
+
}
|
804 |
|
805 |
//* END old boilerplate.
|
806 |
|
808 |
$buttons = $this->render_buttons_HTML( (int) $max_buttons );
|
809 |
|
810 |
$container = '<div class="swp_social_panelSide swp_floating_panel swp_social_panel swp_' . $this->option('float_button_shape') .
|
811 |
+
$this->get_colors(true) .
|
812 |
$this->option('transition') . '
|
813 |
' . $class . '
|
814 |
' . '" data-panel-position="' . $this->option('location_post') .
|
820 |
'" data-transition="' . $this->option('transition') .
|
821 |
'" data-float-mobile="' . $this->get_mobile_float_location() .'">';
|
822 |
|
823 |
+
if ($this->option('totals_alignment') === 'totals_left') {
|
824 |
$buttons = $share_counts . $buttons;
|
825 |
+
} else {
|
826 |
$buttons .= $share_counts;
|
827 |
+
}
|
828 |
|
829 |
$html = $container . $buttons . '</div>';
|
830 |
$this->html = $html;
|
831 |
|
832 |
+
if ( $echo ) {
|
833 |
echo $html;
|
834 |
+
}
|
835 |
|
836 |
return $html;
|
837 |
+
}
|
838 |
|
839 |
}
|
840 |
|
975 |
* If share counts are active, renders the Total Share Counts HTML.
|
976 |
*
|
977 |
* @since 3.0.0 | 18 APR 2018 | Created
|
978 |
+
* @since 3.3.2 | 12 SEP 2018 | Moved strtolower to $totals_argument
|
979 |
+
* @param void
|
980 |
* @return string $html The fully qualified HTML to display share counts.
|
981 |
*
|
982 |
*/
|
983 |
public function render_total_shares_html() {
|
984 |
+
$buttons = isset( $this->args['buttons'] ) ? $this->args['buttons'] : array();
|
985 |
|
986 |
if ( false == $this->option('total_shares') ) {
|
987 |
return '';
|
991 |
return '';
|
992 |
}
|
993 |
|
994 |
+
$totals_argument = in_array('total', array_map('strtolower', $buttons))
|
995 |
+
|| in_array('totals', array_map('strtolower', $buttons));
|
996 |
|
997 |
if ( $this->is_shortcode && !$totals_argument ) {
|
998 |
return '';
|
1051 |
* Runs checks before ordering a set of buttons.
|
1052 |
*
|
1053 |
* @since 3.0.6 | 14 MAY 2018 | Removed the swp-content-locator div.
|
1054 |
+
* @since 3.3.3 | 18 SEP 2018 | Added return value for should_print() condition.
|
1055 |
* @param string $content The WordPress content, if passed in.
|
1056 |
* @return function @see $this->do_print
|
1057 |
*
|
1058 |
*/
|
1059 |
public function the_buttons( $content = null ) {
|
|
|
|
|
|
|
1060 |
|
1061 |
+
/**
|
1062 |
+
* If the content is empty, it means that the user is calling a panel
|
1063 |
+
* of buttons directly using the social_warfare() function of the
|
1064 |
+
* [social_warfare] shortcode.
|
1065 |
+
*
|
1066 |
+
*/
|
1067 |
+
if ( empty( $this->content ) ) {
|
1068 |
+
return $this->do_print();
|
1069 |
+
}
|
1070 |
|
|
|
|
|
|
|
1071 |
|
1072 |
+
/**
|
1073 |
+
* We have a standalone method designed to let us know if all the proper
|
1074 |
+
* desired conditions are met in order to allow us to print the buttons.
|
1075 |
+
*
|
1076 |
+
*/
|
1077 |
+
if ( !$this->should_print() ) {
|
1078 |
+
return $this->content;
|
1079 |
+
}
|
1080 |
|
1081 |
+
if ( null !== $content && gettype( $content ) === 'string' ) {
|
1082 |
+
$this->args['content'] = $content;
|
1083 |
+
}
|
1084 |
|
1085 |
return $this->do_print();
|
1086 |
}
|
lib/frontend-output/SWP_Shortcode.php
CHANGED
@@ -39,7 +39,6 @@ class SWP_Shortcode {
|
|
39 |
*/
|
40 |
add_shortcode( 'clickToTweet', array($this, 'click_to_tweet' ) );
|
41 |
add_shortcode( 'socialWarfare', array($this, 'buttons_shortcode' ) );
|
42 |
-
|
43 |
}
|
44 |
|
45 |
|
@@ -128,11 +127,18 @@ class SWP_Shortcode {
|
|
128 |
function click_to_tweet( $atts ) {
|
129 |
global $post;
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
$user_twitter_handle = get_post_meta( get_the_ID() , 'swp_twitter_username' , true );
|
138 |
|
@@ -152,8 +158,8 @@ class SWP_Shortcode {
|
|
152 |
|
153 |
$html = '<div class="sw-tweet-clear"></div>';
|
154 |
$html .= '<a class="swp_CTT ' . $theme;
|
155 |
-
$html .= '" href="https://twitter.com/share?text=' . $tweet . $via;
|
156 |
-
$html .= '" data-link="https://twitter.com/share?text=' . $tweet . $via;
|
157 |
$html .= '" rel="nofollow noreferrer noopener" target="_blank">';
|
158 |
$html .= '<span class="sw-click-to-tweet">';
|
159 |
$html .= '<span class="sw-ctt-text">';
|
@@ -182,13 +188,16 @@ class SWP_Shortcode {
|
|
182 |
protected function get_tweet( $atts ) {
|
183 |
$max_tweet_length = 240;
|
184 |
|
185 |
-
// Check for a custom tweet from the
|
186 |
$tweet = $atts['tweet'];
|
187 |
|
188 |
-
|
189 |
-
|
|
|
190 |
|
191 |
-
$
|
|
|
|
|
192 |
|
193 |
return $tweet;
|
194 |
}
|
39 |
*/
|
40 |
add_shortcode( 'clickToTweet', array($this, 'click_to_tweet' ) );
|
41 |
add_shortcode( 'socialWarfare', array($this, 'buttons_shortcode' ) );
|
|
|
42 |
}
|
43 |
|
44 |
|
127 |
function click_to_tweet( $atts ) {
|
128 |
global $post;
|
129 |
|
130 |
+
if ( strpos( $atts['tweet'], 'http' ) > -1 ) :
|
131 |
+
/**
|
132 |
+
* They included a link in the tweet text. Do not pass a &url paramter.
|
133 |
+
*
|
134 |
+
* Twitter will diregard value if it is: empty, a whitespace, or %20.
|
135 |
+
* Instead, give it an invalid URL! It achieves the targeted effect.
|
136 |
+
*
|
137 |
+
*/
|
138 |
+
$url = '&url=x';
|
139 |
+
else :
|
140 |
+
$url = '&url=' . SWP_URL_Management::process_url( get_permalink() , 'twitter' , get_the_ID() );
|
141 |
+
endif;
|
142 |
|
143 |
$user_twitter_handle = get_post_meta( get_the_ID() , 'swp_twitter_username' , true );
|
144 |
|
158 |
|
159 |
$html = '<div class="sw-tweet-clear"></div>';
|
160 |
$html .= '<a class="swp_CTT ' . $theme;
|
161 |
+
$html .= '" href="https://twitter.com/share?text=' . $tweet . $via . $url;
|
162 |
+
$html .= '" data-link="https://twitter.com/share?text=' . $tweet . $via . $url;
|
163 |
$html .= '" rel="nofollow noreferrer noopener" target="_blank">';
|
164 |
$html .= '<span class="sw-click-to-tweet">';
|
165 |
$html .= '<span class="sw-ctt-text">';
|
188 |
protected function get_tweet( $atts ) {
|
189 |
$max_tweet_length = 240;
|
190 |
|
191 |
+
// Check for a custom tweet from the shortcode attributes. .
|
192 |
$tweet = $atts['tweet'];
|
193 |
|
194 |
+
if ( function_exists( 'mb_convert_encoding' ) ) :
|
195 |
+
$tweet = mb_convert_encoding( $tweet, 'UTF-8', get_bloginfo( "charset" ) );
|
196 |
+
endif;
|
197 |
|
198 |
+
$html_safe_tweet = htmlentities( $tweet, ENT_COMPAT, 'UTF-8' );
|
199 |
+
$tweet = utf8_uri_encode( $tweet, $max_tweet_length );
|
200 |
+
$tweet = urlencode( $tweet );
|
201 |
|
202 |
return $tweet;
|
203 |
}
|
lib/options/SWP_Section_HTML.php
CHANGED
@@ -187,6 +187,8 @@ class SWP_Section_HTML extends SWP_Option {
|
|
187 |
$selected = '';
|
188 |
endif;
|
189 |
|
|
|
|
|
190 |
|
191 |
$html = '<div class="sw-grid sw-col-940 sw-fit sw-option-container ' . $this->key . '_wrapper" ' . $this->render_dependency() . '>';
|
192 |
|
@@ -224,21 +226,43 @@ class SWP_Section_HTML extends SWP_Option {
|
|
224 |
/**
|
225 |
* Render the Bitly connection button on the Advanced tab.
|
226 |
*
|
227 |
-
|
|
|
228 |
* @param void
|
229 |
* @return object $this The calling instance, for method chaining.
|
230 |
*
|
231 |
*/
|
232 |
public function do_bitly_authentication_button() {
|
233 |
-
$link = "https://bitly.com/oauth/authorize?client_id=96c9b292c5503211b68cf4ab53f6e2f4b6d0defb&state=" . admin_url( 'admin-ajax.php' ) . "&redirect_uri=https://warfareplugins.com/bitly_oauth.php";
|
234 |
|
235 |
-
|
|
|
|
|
|
|
236 |
$text = __( 'Connected', 'social-warfare' );
|
|
|
237 |
$color = 'sw-green-button';
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
239 |
$text = __( 'Authenticate', 'social-warfare' );
|
240 |
$color = 'sw-navy-button';
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
ob_start() ?>
|
244 |
|
@@ -247,7 +271,7 @@ class SWP_Section_HTML extends SWP_Option {
|
|
247 |
<p class="sw-authenticate-label"><?php __( 'Bitly Link Shortening', 'social-warfare' ) ?></p>
|
248 |
</div>
|
249 |
<div class="sw-grid sw-col-300">
|
250 |
-
<a class="button <?= $color ?>" href="<?= $link ?>"><?= $text ?></a>
|
251 |
</div>
|
252 |
<div class="sw-grid sw-col-300 sw-fit"></div>
|
253 |
</div>
|
187 |
$selected = '';
|
188 |
endif;
|
189 |
|
190 |
+
$this->default = false;
|
191 |
+
$this->key = 'twitter_shares';
|
192 |
|
193 |
$html = '<div class="sw-grid sw-col-940 sw-fit sw-option-container ' . $this->key . '_wrapper" ' . $this->render_dependency() . '>';
|
194 |
|
226 |
/**
|
227 |
* Render the Bitly connection button on the Advanced tab.
|
228 |
*
|
229 |
+
* @see https://dev.bitly.com/authentication.html
|
230 |
+
* @since 3.0.0 | 01 MAR 2018 | Created
|
231 |
* @param void
|
232 |
* @return object $this The calling instance, for method chaining.
|
233 |
*
|
234 |
*/
|
235 |
public function do_bitly_authentication_button() {
|
|
|
236 |
|
237 |
+
|
238 |
+
if ( SWP_Utility::get_option('bitly_access_token') ) {
|
239 |
+
|
240 |
+
//* Display a confirmation button. On click takes them to bitly settings page.
|
241 |
$text = __( 'Connected', 'social-warfare' );
|
242 |
+
$text .= " for:<br/>" . SWP_Utility::get_option( 'bitly_access_login' );
|
243 |
$color = 'sw-green-button';
|
244 |
+
$link = 'https://app.bitly.com/bitlinks/?actions=accountMain&actions=settings&actions=security';
|
245 |
+
$target = "_blank";
|
246 |
+
|
247 |
+
} else {
|
248 |
+
|
249 |
+
//* Display the button, which takes them to a Bitly auth page.
|
250 |
$text = __( 'Authenticate', 'social-warfare' );
|
251 |
$color = 'sw-navy-button';
|
252 |
+
$target = "";
|
253 |
+
|
254 |
+
//* The base URL for authorizing SW to work on a user's Bitly account.
|
255 |
+
$link = "https://bitly.com/oauth/authorize";
|
256 |
+
|
257 |
+
//* client_id: The SWP application id, assigned by Bitly.
|
258 |
+
$link .= "?client_id=96c9b292c5503211b68cf4ab53f6e2f4b6d0defb";
|
259 |
+
|
260 |
+
//* state: Optional state to include in the redirect URI.
|
261 |
+
$link .= "&state=" . admin_url( 'admin-ajax.php' );
|
262 |
+
|
263 |
+
//* redirect_uri: The page to which a user is redirected upon successfully authenticating.
|
264 |
+
$link .= "&redirect_uri=https://warfareplugins.com/bitly_oauth.php";
|
265 |
+
}
|
266 |
|
267 |
ob_start() ?>
|
268 |
|
271 |
<p class="sw-authenticate-label"><?php __( 'Bitly Link Shortening', 'social-warfare' ) ?></p>
|
272 |
</div>
|
273 |
<div class="sw-grid sw-col-300">
|
274 |
+
<a target="<?= $target ?>" class="button <?= $color ?>" href="<?= $link ?>"><?= $text ?></a>
|
275 |
</div>
|
276 |
<div class="sw-grid sw-col-300 sw-fit"></div>
|
277 |
</div>
|
lib/options/SWP_User_Options.php
CHANGED
@@ -114,7 +114,12 @@ class SWP_User_options {
|
|
114 |
|
115 |
public function generate_whitelist() {
|
116 |
$addons = apply_filters( 'swp_registrations', array() );
|
117 |
-
$whitelist = array('last_migrated');
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
if ( empty( $addons) ) {
|
120 |
return $whitelist;
|
114 |
|
115 |
public function generate_whitelist() {
|
116 |
$addons = apply_filters( 'swp_registrations', array() );
|
117 |
+
$whitelist = array('last_migrated', 'bitly_access_token', 'bitly_access_login');
|
118 |
+
|
119 |
+
$post_types = get_post_types();
|
120 |
+
foreach( $post_types as $post_type ) {
|
121 |
+
$whitelist[] = 'swp_og_type_' . $post_type;
|
122 |
+
}
|
123 |
|
124 |
if ( empty( $addons) ) {
|
125 |
return $whitelist;
|
lib/social-networks/SWP_Twitter.php
CHANGED
@@ -238,10 +238,13 @@ class SWP_Twitter extends SWP_Social_Network {
|
|
238 |
$tweet = $tweet[0];
|
239 |
endif;
|
240 |
|
241 |
-
|
242 |
-
|
|
|
243 |
|
244 |
-
$
|
|
|
|
|
245 |
|
246 |
return $tweet;
|
247 |
}
|
238 |
$tweet = $tweet[0];
|
239 |
endif;
|
240 |
|
241 |
+
if ( function_exists( 'mb_convert_encoding' ) ) {
|
242 |
+
$converted_tweet = mb_convert_encoding( $tweet, 'UTF-8', get_bloginfo( 'charset' ) );
|
243 |
+
}
|
244 |
|
245 |
+
$html_safe_tweet = html_entity_decode( $tweet, ENT_COMPAT, 'UTF-8' );
|
246 |
+
$tweet = utf8_uri_encode( $html_safe_tweet, $max_tweet_length );
|
247 |
+
$tweet = urlencode( $tweet );
|
248 |
|
249 |
return $tweet;
|
250 |
}
|
lib/utilities/SWP_CURL.php
CHANGED
@@ -101,6 +101,7 @@ class SWP_CURL {
|
|
101 |
curl_close( $ch );
|
102 |
|
103 |
if ( $curl_errno > 0 ) {
|
|
|
104 |
return false;
|
105 |
}
|
106 |
|
101 |
curl_close( $ch );
|
102 |
|
103 |
if ( $curl_errno > 0 ) {
|
104 |
+
// echo curl_error ( $cont );
|
105 |
return false;
|
106 |
}
|
107 |
|
lib/utilities/SWP_Plugin_Updater.php
CHANGED
File without changes
|
lib/utilities/SWP_URL_Management.php
CHANGED
@@ -29,7 +29,7 @@ class SWP_URL_Management {
|
|
29 |
*/
|
30 |
public function __construct() {
|
31 |
|
32 |
-
add_filter( 'swp_link_shortening' , array(
|
33 |
add_filter( 'swp_analytics' , array( $this , 'google_analytics' ) );
|
34 |
add_action( 'wp_ajax_nopriv_swp_bitly_oauth', array( $this , 'bitly_oauth_callback' ) );
|
35 |
|
@@ -80,6 +80,40 @@ class SWP_URL_Management {
|
|
80 |
}
|
81 |
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
/**
|
84 |
* The Bitly Link Shortener Method
|
85 |
*
|
@@ -92,108 +126,77 @@ class SWP_URL_Management {
|
|
92 |
* @access public
|
93 |
*
|
94 |
*/
|
95 |
-
public function link_shortener( $array ) {
|
96 |
global $post;
|
97 |
-
|
|
|
98 |
$google_analytics = SWP_Utility::get_option('google_analytics');
|
99 |
$access_token = SWP_Utility::get_option( 'bitly_access_token' );
|
|
|
|
|
|
|
|
|
100 |
|
101 |
// Recently done.
|
102 |
-
if ( true == $array['fresh_cache'] )
|
|
|
|
|
|
|
103 |
return $array;
|
104 |
-
|
105 |
|
106 |
// We need this information to make a bitly request.
|
107 |
-
if ( false == $access_token || true !== SWP_Utility::get_option( 'bitly_authentication' ) )
|
108 |
-
|
109 |
-
|
110 |
|
111 |
// These can not have bitly urls created.
|
112 |
-
if ( $array['network'] == 'total_shares' || $array['network'] == 'pinterest' )
|
113 |
return $array;
|
114 |
-
|
115 |
|
116 |
-
|
117 |
-
if ( isset( $_GLOBALS['bitly_status'] ) && $_GLOBALS['bitly_status'] == 'failure' ) :
|
118 |
-
return $array;
|
119 |
-
endif;
|
120 |
|
121 |
-
|
122 |
-
if (
|
123 |
-
$array['url'] = $_GLOBALS['sw']['links'][ $postID ];
|
124 |
return $array;
|
125 |
endif;
|
126 |
|
127 |
-
$start_date = trim( SWP_Utility::get_option( 'bitly_start_date' ) );
|
128 |
-
|
129 |
//* They have decided to only allow posts after a certain date.
|
130 |
-
if ( $start_date )
|
131 |
-
|
132 |
if ( !is_object( $post ) || empty( $post->post_date ) ) :
|
133 |
return $array;
|
134 |
endif;
|
135 |
|
136 |
$start_date = DateTime::createFromFormat( 'Y-m-d', $start_date );
|
137 |
-
|
138 |
-
//* They did not format the date correctly.
|
139 |
-
if ( false == $start_date ) :
|
140 |
-
return $array;
|
141 |
-
endif;
|
142 |
-
|
143 |
$post_date = new DateTime( $post->post_date );
|
144 |
|
145 |
-
//* The post is
|
146 |
if ( $start_date > $post_date ) :
|
147 |
return $array;
|
148 |
endif;
|
149 |
-
|
150 |
-
|
151 |
-
$links_enabled = SWP_Utility::get_option( "bitly_links_{$post->post_type}" );
|
152 |
-
|
153 |
-
//* They have disabled bitly links on this post type.
|
154 |
-
if ( false == $links_enabled || 'off' == $links_enabled ) :
|
155 |
-
return $array;
|
156 |
-
endif;
|
157 |
|
158 |
$network = $array['network'];
|
159 |
-
|
160 |
-
if ( true == $google_analytics ) :
|
161 |
-
$prior_bitly_url = get_post_meta( $postID, 'bitly_link_' . $network, true );
|
162 |
-
else :
|
163 |
-
$prior_bitly_url = get_post_meta( $postID, 'bitly_link', true );
|
164 |
-
endif;
|
165 |
-
|
166 |
-
|
167 |
-
if ( $prior_bitly_url ) :
|
168 |
-
$array['url'] = $prior_bitly_url;
|
169 |
-
return $array;
|
170 |
-
endif;
|
171 |
-
|
172 |
-
|
173 |
$url = urldecode( $array['url'] );
|
174 |
-
$new_bitly_url =
|
175 |
|
|
|
|
|
176 |
|
177 |
-
|
|
|
|
|
178 |
|
179 |
-
delete_post_meta( $
|
180 |
-
update_post_meta( $
|
181 |
-
$array['url'] = $
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
if ( false == $google_analytics ) :
|
189 |
-
|
190 |
-
// Delete the meta fields and then update to keep the database clean and up to date.
|
191 |
-
delete_post_meta( $postID,'bitly_link_' . $network );
|
192 |
-
|
193 |
-
// Save the link in a global so we can skip this part next time
|
194 |
-
$_GLOBALS['sw']['links'][ $postID ] = $bitly_url;
|
195 |
-
|
196 |
-
endif;
|
197 |
|
198 |
return $array;
|
199 |
}
|
@@ -213,50 +216,29 @@ class SWP_URL_Management {
|
|
213 |
* @access public
|
214 |
*
|
215 |
*/
|
216 |
-
public function make_bitly_url( $url, $
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
$
|
|
|
221 |
|
222 |
-
|
223 |
|
224 |
-
|
225 |
-
|
226 |
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
// Fetch a response from the Bitly Shortening API
|
237 |
-
$data = SWP_CURL::file_get_contents_curl( $bitly_api );
|
238 |
-
|
239 |
-
// Parse the JSON formated response into an array
|
240 |
-
$data = json_decode( $data , true );
|
241 |
-
|
242 |
-
// If the shortening succeeded....
|
243 |
-
if ( isset( $data['data']['url'] ) ) :
|
244 |
-
|
245 |
-
// Store the short URL to return to the plugin
|
246 |
-
$short_url = $data['data']['url'];
|
247 |
-
|
248 |
-
// If the shortening failed....
|
249 |
-
else :
|
250 |
-
|
251 |
-
// Return a status of false
|
252 |
-
$short_url = false;
|
253 |
-
|
254 |
-
endif;
|
255 |
-
|
256 |
-
endif;
|
257 |
-
|
258 |
-
return $short_url;
|
259 |
|
|
|
|
|
260 |
}
|
261 |
|
262 |
|
@@ -275,31 +257,25 @@ class SWP_URL_Management {
|
|
275 |
* @access public static
|
276 |
*/
|
277 |
public static function process_url( $url, $network, $postID, $is_cache_fresh = true ) {
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
else :
|
284 |
-
// Fetch the parameters into an array for use by the filters
|
285 |
-
$array['url'] = $url;
|
286 |
-
$array['network'] = $network;
|
287 |
-
$array['postID'] = $postID;
|
288 |
-
$array['fresh_cache'] = $is_cache_fresh;
|
289 |
|
290 |
-
|
291 |
|
292 |
-
|
293 |
|
294 |
-
|
295 |
-
|
296 |
-
// Run the link shortening hook filters, but not on Pinterest
|
297 |
-
$array = apply_filters( 'swp_link_shortening' , $array );
|
298 |
-
endif;
|
299 |
-
|
300 |
-
return $array['url'];
|
301 |
|
|
|
|
|
|
|
|
|
302 |
endif;
|
|
|
|
|
303 |
}
|
304 |
|
305 |
|
@@ -317,13 +293,11 @@ class SWP_URL_Management {
|
|
317 |
*
|
318 |
*/
|
319 |
public function bitly_oauth_callback() {
|
320 |
-
$
|
321 |
-
|
322 |
-
// Set the premium code to null
|
323 |
-
$options['bitly_access_token'] = $_GET['access_token'];
|
324 |
|
325 |
-
|
326 |
-
|
327 |
|
328 |
echo admin_url( 'admin.php?page=social-warfare' );
|
329 |
}
|
29 |
*/
|
30 |
public function __construct() {
|
31 |
|
32 |
+
add_filter( 'swp_link_shortening' , array( __CLASS__ , 'link_shortener' ) );
|
33 |
add_filter( 'swp_analytics' , array( $this , 'google_analytics' ) );
|
34 |
add_action( 'wp_ajax_nopriv_swp_bitly_oauth', array( $this , 'bitly_oauth_callback' ) );
|
35 |
|
80 |
}
|
81 |
|
82 |
|
83 |
+
/**
|
84 |
+
* Fetch the bitly link that is cached in the local database.
|
85 |
+
*
|
86 |
+
* When the cache is fresh, we just pull the existing bitly link from the
|
87 |
+
* database rather than making an API call on every single page load.
|
88 |
+
*
|
89 |
+
* @since 3.3.2 | 12 SEP 2018 | Created
|
90 |
+
* @param int $post_id The post ID
|
91 |
+
* @param string $network The key for the current social network
|
92 |
+
* @return mixed string: The short url; false on failure.
|
93 |
+
*
|
94 |
+
*/
|
95 |
+
public static function fetch_local_bitly_link( $post_id, $network ) {
|
96 |
+
|
97 |
+
// If analytics are on, get a different link for each network.
|
98 |
+
if ( true == SWP_Utility::get_option('google_analytics') ) {
|
99 |
+
$short_url = get_post_meta( $post_id, 'bitly_link_' . $network, true);
|
100 |
+
|
101 |
+
if ( is_string( $short_url ) && strlen( $short_url ) ) {
|
102 |
+
return $short_url;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
// If analytics are off, just pull the general short link.
|
107 |
+
$short_url = get_post_meta( $post_id, 'bitly_link', true );
|
108 |
+
|
109 |
+
if ( is_string( $short_url ) && strlen( $short_url ) ) {
|
110 |
+
return $short_url;
|
111 |
+
}
|
112 |
+
|
113 |
+
return false;
|
114 |
+
}
|
115 |
+
|
116 |
+
|
117 |
/**
|
118 |
* The Bitly Link Shortener Method
|
119 |
*
|
126 |
* @access public
|
127 |
*
|
128 |
*/
|
129 |
+
public static function link_shortener( $array ) {
|
130 |
global $post;
|
131 |
+
|
132 |
+
$post_id = $array['postID'];
|
133 |
$google_analytics = SWP_Utility::get_option('google_analytics');
|
134 |
$access_token = SWP_Utility::get_option( 'bitly_access_token' );
|
135 |
+
$cached_bitly_link = SWP_URL_Management::fetch_local_bitly_link( $post_id, $array['network'] );
|
136 |
+
$start_date = SWP_Utility::get_option( 'bitly_start_date' );
|
137 |
+
|
138 |
+
|
139 |
|
140 |
// Recently done.
|
141 |
+
if ( true == $array['fresh_cache'] ) {
|
142 |
+
if( false !== $cached_bitly_link ) {
|
143 |
+
$array['url'] = $cached_bitly_link;
|
144 |
+
}
|
145 |
return $array;
|
146 |
+
}
|
147 |
|
148 |
// We need this information to make a bitly request.
|
149 |
+
if ( false == $access_token || true !== SWP_Utility::get_option( 'bitly_authentication' ) ) {
|
150 |
+
return $array;
|
151 |
+
}
|
152 |
|
153 |
// These can not have bitly urls created.
|
154 |
+
if ( $array['network'] == 'total_shares' || $array['network'] == 'pinterest' ) {
|
155 |
return $array;
|
156 |
+
}
|
157 |
|
158 |
+
$links_enabled = SWP_Utility::get_option( "bitly_links_{$post->post_type}" );
|
|
|
|
|
|
|
159 |
|
160 |
+
//* They have disabled bitly links on this post type.
|
161 |
+
if ( false == $links_enabled || 'off' == $links_enabled ) :
|
|
|
162 |
return $array;
|
163 |
endif;
|
164 |
|
|
|
|
|
165 |
//* They have decided to only allow posts after a certain date.
|
166 |
+
if ( $start_date ) {
|
|
|
167 |
if ( !is_object( $post ) || empty( $post->post_date ) ) :
|
168 |
return $array;
|
169 |
endif;
|
170 |
|
171 |
$start_date = DateTime::createFromFormat( 'Y-m-d', $start_date );
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
$post_date = new DateTime( $post->post_date );
|
173 |
|
174 |
+
//* The post is too new for $start_date.
|
175 |
if ( $start_date > $post_date ) :
|
176 |
return $array;
|
177 |
endif;
|
178 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
$network = $array['network'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
$url = urldecode( $array['url'] );
|
182 |
+
$new_bitly_url = SWP_URL_Management::make_bitly_url( $url, $access_token );
|
183 |
|
184 |
+
if ( $new_bitly_url ) {
|
185 |
+
$meta_key = 'bitly_link';
|
186 |
|
187 |
+
if ( $google_analytics ) {
|
188 |
+
$meta_key .= "_$network";
|
189 |
+
}
|
190 |
|
191 |
+
delete_post_meta( $post_id, $meta_key );
|
192 |
+
update_post_meta( $post_id, $meta_key, $new_bitly_url );
|
193 |
+
$array['url'] = $new_bitly_url;
|
194 |
+
}
|
195 |
|
196 |
+
// // Delete the meta fields and then update to keep the database clean and up to date.
|
197 |
+
// if ( false == $google_analytics ) {
|
198 |
+
// delete_post_meta( $post_id, 'bitly_link_' . $network );
|
199 |
+
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
return $array;
|
202 |
}
|
216 |
* @access public
|
217 |
*
|
218 |
*/
|
219 |
+
public static function make_bitly_url( $url, $access_token ) {
|
220 |
+
// Create a link to reach the Bitly API
|
221 |
+
$api_request_url = 'https://api-ssl.bitly.com/v3/shorten';
|
222 |
+
$api_request_url .= "?access_token=$access_token";
|
223 |
+
$api_request_url .= "&longUrl=" . urlencode( $url );
|
224 |
+
$api_request_url .= "&format=json";
|
225 |
|
226 |
+
// echo __METHOD__, "<pre>", var_dump($api_request_url), die;
|
227 |
|
228 |
+
// Fetch a response from the Bitly Shortening API
|
229 |
+
$response = SWP_CURL::file_get_contents_curl( $api_request_url );
|
230 |
|
231 |
+
// Parse the JSON formated response into an array
|
232 |
+
$result = json_decode( $response , true );
|
233 |
|
234 |
+
// If the shortening succeeded....
|
235 |
+
if ( isset( $result['data']['url'] ) ) {
|
236 |
+
// Store the short URL to return to the plugin
|
237 |
+
return $result['data']['url'];
|
238 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
+
// If the shortening failed....
|
241 |
+
return false;
|
242 |
}
|
243 |
|
244 |
|
257 |
* @access public static
|
258 |
*/
|
259 |
public static function process_url( $url, $network, $postID, $is_cache_fresh = true ) {
|
260 |
+
// Fetch the parameters into an array for use by the filters
|
261 |
+
$array['url'] = $url;
|
262 |
+
$array['network'] = $network;
|
263 |
+
$array['postID'] = $postID;
|
264 |
+
$array['fresh_cache'] = $is_cache_fresh;
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
+
if( !is_attachment() ):
|
267 |
|
268 |
+
// Run the anaylitcs hook filters
|
269 |
|
270 |
+
$array = apply_filters( 'swp_analytics' , $array );
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
|
272 |
+
// Run the link shortening hook filters, but not on Pinterest
|
273 |
+
// $array = apply_filters( 'swp_link_shortening' , $array );
|
274 |
+
$array = SWP_URL_Management::link_shortener($array);
|
275 |
+
// echo "<pre>Array after link_shortener(): <br>", var_dump($array), "</pre>";
|
276 |
endif;
|
277 |
+
|
278 |
+
return $array['url'];
|
279 |
}
|
280 |
|
281 |
|
293 |
*
|
294 |
*/
|
295 |
public function bitly_oauth_callback() {
|
296 |
+
$access_token = isset( $_GET['access_token'] ) ? $_GET['access_token'] : '';
|
297 |
+
$login = isset( $_GET['login'] ) ? $_GET['login'] : '';
|
|
|
|
|
298 |
|
299 |
+
SWP_Utility::update_option( 'bitly_access_token', $access_token );
|
300 |
+
SWP_Utility::update_option( 'bitly_access_login', $login);
|
301 |
|
302 |
echo admin_url( 'admin.php?page=social-warfare' );
|
303 |
}
|
lib/utilities/SWP_Utility.php
CHANGED
@@ -73,6 +73,8 @@ class SWP_Utility {
|
|
73 |
* @return bool Whether or not the options were updated in the database.
|
74 |
*/
|
75 |
public static function store_settings() {
|
|
|
|
|
76 |
if ( !check_ajax_referer( 'swp_plugin_options_save', 'security', false ) ) {
|
77 |
wp_send_json_error( esc_html__( 'Security failed.', 'social-warfare' ) );
|
78 |
die;
|
@@ -98,7 +100,9 @@ class SWP_Utility {
|
|
98 |
}
|
99 |
}
|
100 |
|
101 |
-
|
|
|
|
|
102 |
|
103 |
wp_die();
|
104 |
}
|
@@ -288,4 +292,25 @@ class SWP_Utility {
|
|
288 |
return get_site_url();
|
289 |
}
|
290 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
}
|
73 |
* @return bool Whether or not the options were updated in the database.
|
74 |
*/
|
75 |
public static function store_settings() {
|
76 |
+
global $swp_user_options;
|
77 |
+
|
78 |
if ( !check_ajax_referer( 'swp_plugin_options_save', 'security', false ) ) {
|
79 |
wp_send_json_error( esc_html__( 'Security failed.', 'social-warfare' ) );
|
80 |
die;
|
100 |
}
|
101 |
}
|
102 |
|
103 |
+
$new_settings = array_merge( $swp_user_options, $settings );
|
104 |
+
|
105 |
+
echo json_encode( update_option( 'social_warfare_settings', $new_settings ) );
|
106 |
|
107 |
wp_die();
|
108 |
}
|
292 |
return get_site_url();
|
293 |
}
|
294 |
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Updates an option in the Social Warfare settings.
|
298 |
+
*
|
299 |
+
* @since 3.3.2 | 12 SEP 2018 | Created.
|
300 |
+
*
|
301 |
+
* @param string $key The key under which the option needs to be stored.
|
302 |
+
* @param mixed $value The value at the key.
|
303 |
+
* @return bool True if the option was updated, else false.
|
304 |
+
*
|
305 |
+
*/
|
306 |
+
public static function update_option( $key, $value ) {
|
307 |
+
if ( empty( $key ) ) {
|
308 |
+
return false;
|
309 |
+
}
|
310 |
+
|
311 |
+
$options = get_option( 'social_warfare_settings', array() );
|
312 |
+
$options[$key] = $value;
|
313 |
+
|
314 |
+
return update_option( 'social_warfare_settings', $options );
|
315 |
+
}
|
316 |
}
|
lib/utilities/functions.php
CHANGED
@@ -10,15 +10,38 @@
|
|
10 |
*
|
11 |
*/
|
12 |
|
13 |
-
function socialWarfare( $content = false, $where = 'default', $echo = true ) {
|
14 |
-
social_warfare( array( 'content' => $content, 'where' => $where, 'echo' => $echo ) );
|
15 |
-
}
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
function social_warfare( $args = array() ) {
|
18 |
$buttons_panel = new SWP_Buttons_Panel( $args );
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
function swp_kilomega( $number ) {
|
23 |
return SWP_Utiltiy::kilomega( $number );
|
24 |
}
|
10 |
*
|
11 |
*/
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
+
/**
|
15 |
+
* This is the primary function that people can use to add buttons into their
|
16 |
+
* themes and whatnot. It is always encouraged to make it pluggable by adding
|
17 |
+
* wrapping it in checks for existence.
|
18 |
+
*
|
19 |
+
* @param array $args See SWP_Buttons_Panel.
|
20 |
+
* @return void It echoes the results to the screen.
|
21 |
+
*/
|
22 |
function social_warfare( $args = array() ) {
|
23 |
$buttons_panel = new SWP_Buttons_Panel( $args );
|
24 |
+
echo $buttons_panel->render_HTML();
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* This is the old camelCased version of the above function. We're leaving it here
|
30 |
+
* as a passthrough to support folks who installed this into their themes ages
|
31 |
+
* ago to make sure that it will still work for them.
|
32 |
+
*
|
33 |
+
*/
|
34 |
+
function socialWarfare( $content = false, $where = 'default', $echo = true ) {
|
35 |
+
social_warfare( array( 'content' => $content, 'where' => $where, 'echo' => $echo ) );
|
36 |
}
|
37 |
|
38 |
+
|
39 |
+
/**
|
40 |
+
* A wrapper function used for formatting numbers.
|
41 |
+
*
|
42 |
+
* @param integer $number A number to be formatted.
|
43 |
+
* @return string The formatted number.
|
44 |
+
*/
|
45 |
function swp_kilomega( $number ) {
|
46 |
return SWP_Utiltiy::kilomega( $number );
|
47 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: holas84, dustinwstout, webinator, warfareplugins, nutsandboltsmedi
|
|
3 |
Tags: sharing buttons, social media share, floating share buttons, facebook share, google plus share, linkedin share, pin it, pinterest save, mix button, tweet button, twitter share, click to tweet, social sharing buttons, social share, social sharing, social media sharing, wordpress social sharing plugin, social sharing plugin, share buttons, share counts
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.9
|
6 |
-
Stable tag: 3.3.
|
7 |
License: GNU General Public License v2.0 or later
|
8 |
|
9 |
The most beautiful, responsive, lightning fast social share buttons built to boost shares and drive more traffic without slowing down your site.
|
@@ -193,6 +193,23 @@ We have a growing archive of <a href="https://warfareplugins.com/support/" rel="
|
|
193 |
|
194 |
== Changelog ==
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
= 3.3.0 (11 SEP 2018) =
|
197 |
* Added CSS to hide buttons on print views.
|
198 |
* Added Mix to the Social Networks.
|
3 |
Tags: sharing buttons, social media share, floating share buttons, facebook share, google plus share, linkedin share, pin it, pinterest save, mix button, tweet button, twitter share, click to tweet, social sharing buttons, social share, social sharing, social media sharing, wordpress social sharing plugin, social sharing plugin, share buttons, share counts
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.9
|
6 |
+
Stable tag: 3.3.3
|
7 |
License: GNU General Public License v2.0 or later
|
8 |
|
9 |
The most beautiful, responsive, lightning fast social share buttons built to boost shares and drive more traffic without slowing down your site.
|
193 |
|
194 |
== Changelog ==
|
195 |
|
196 |
+
= 3.3.3 (19 SEP 2018)
|
197 |
+
* Fixed the social_warfare() function so it now outputs buttons as it did before.
|
198 |
+
* Fixed a call to undefined function regarding mb_convert_encoding().
|
199 |
+
* Fixed an "undefined index" error in the javascript.
|
200 |
+
* Fixed a bug that would sometimes make Yoast's og:description disappear.
|
201 |
+
* Fixed a "return value in write context" PHP error.
|
202 |
+
* Fixed Bitly authentication, link generation, and link usage with the buttons.
|
203 |
+
|
204 |
+
= 3.3.2 (14 SEP 2018) =
|
205 |
+
* Fixed a line of code that caused the 'social_warfare()' function to disappear.
|
206 |
+
|
207 |
+
= 3.3.1 (11 SEP 2018) =
|
208 |
+
* Fixed the URL for post editor placeholder images.
|
209 |
+
* Fixed the Twitter Count toggle.
|
210 |
+
* Added backward compatability for swp_kilomega().
|
211 |
+
* Added compatability for mb_convert_encoding().
|
212 |
+
|
213 |
= 3.3.0 (11 SEP 2018) =
|
214 |
* Added CSS to hide buttons on print views.
|
215 |
* Added Mix to the Social Networks.
|
social-warfare.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Social Warfare
|
4 |
* Plugin URI: https://warfareplugins.com
|
5 |
* Description: A plugin to maximize social shares and drive more traffic using the fastest and most intelligent share buttons on the market, calls to action via in-post click-to-tweets, popular posts widgets based on share popularity, link-shortening, Google Analytics and much, much more!
|
6 |
-
* Version: 3.3.
|
7 |
* Author: Warfare Plugins
|
8 |
* Author URI: https://warfareplugins.com
|
9 |
* Text Domain: social-warfare
|
@@ -16,7 +16,7 @@ defined( 'WPINC' ) || die;
|
|
16 |
* Define plugin constants for use throughout the plugin (Version and Directories)
|
17 |
*
|
18 |
*/
|
19 |
-
define( 'SWP_VERSION' , '3.3.
|
20 |
define( 'SWP_PLUGIN_FILE', __FILE__ );
|
21 |
define( 'SWP_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
|
22 |
define( 'SWP_PLUGIN_DIR', dirname( __FILE__ ) );
|
3 |
* Plugin Name: Social Warfare
|
4 |
* Plugin URI: https://warfareplugins.com
|
5 |
* Description: A plugin to maximize social shares and drive more traffic using the fastest and most intelligent share buttons on the market, calls to action via in-post click-to-tweets, popular posts widgets based on share popularity, link-shortening, Google Analytics and much, much more!
|
6 |
+
* Version: 3.3.3
|
7 |
* Author: Warfare Plugins
|
8 |
* Author URI: https://warfareplugins.com
|
9 |
* Text Domain: social-warfare
|
16 |
* Define plugin constants for use throughout the plugin (Version and Directories)
|
17 |
*
|
18 |
*/
|
19 |
+
define( 'SWP_VERSION' , '3.3.3' );
|
20 |
define( 'SWP_PLUGIN_FILE', __FILE__ );
|
21 |
define( 'SWP_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
|
22 |
define( 'SWP_PLUGIN_DIR', dirname( __FILE__ ) );
|