Version Description
- Bugfix: Added url encoding for server side Share Counts API
Download this release
Release Info
Developer | shareaholic |
Plugin | WordPress Social Tools, Related Posts, Monetization – Shareaholic |
Version | 7.4.0.3 |
Comparing to | |
See all releases |
Code changes from version 7.4.0.2 to 7.4.0.3
- lib/social-share-counts/share_count.php +39 -11
- public_js.php +1 -1
- readme.txt +8 -1
- shareaholic.php +3 -3
- utilities.php +1 -1
lib/social-share-counts/share_count.php
CHANGED
@@ -19,6 +19,10 @@ abstract class ShareaholicShareCount {
|
|
19 |
protected $services;
|
20 |
|
21 |
public function __construct($url, $services) {
|
|
|
|
|
|
|
|
|
22 |
$this->url = $url;
|
23 |
$this->services = $services;
|
24 |
}
|
@@ -26,7 +30,7 @@ abstract class ShareaholicShareCount {
|
|
26 |
public static function get_services_config() {
|
27 |
return array(
|
28 |
'facebook' => array(
|
29 |
-
'url' => 'https://graph.facebook.com
|
30 |
'method' => 'GET',
|
31 |
'timeout' => 3, // in number of seconds
|
32 |
'callback' => 'facebook_count_callback',
|
@@ -97,6 +101,23 @@ abstract class ShareaholicShareCount {
|
|
97 |
);
|
98 |
}
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
/**
|
101 |
* Check if calling the service returned any type of error
|
102 |
*
|
@@ -123,7 +144,7 @@ abstract class ShareaholicShareCount {
|
|
123 |
return false;
|
124 |
}
|
125 |
$body = json_decode($response['body'], true);
|
126 |
-
return isset($body['
|
127 |
}
|
128 |
|
129 |
|
@@ -139,7 +160,7 @@ abstract class ShareaholicShareCount {
|
|
139 |
return false;
|
140 |
}
|
141 |
$body = json_decode($response['body'], true);
|
142 |
-
return isset($body['count']) ? $body['count'] :
|
143 |
}
|
144 |
|
145 |
|
@@ -155,7 +176,7 @@ abstract class ShareaholicShareCount {
|
|
155 |
return false;
|
156 |
}
|
157 |
$body = json_decode($response['body'], true);
|
158 |
-
return isset($body['count']) ? $body['count'] :
|
159 |
}
|
160 |
|
161 |
|
@@ -172,6 +193,9 @@ abstract class ShareaholicShareCount {
|
|
172 |
* @param $config The services configuration object to be updated
|
173 |
*/
|
174 |
public function google_plus_prepare_request($url, &$config) {
|
|
|
|
|
|
|
175 |
$post_fields = array(
|
176 |
array(
|
177 |
'method' => 'pos.plusones.get',
|
@@ -205,6 +229,7 @@ abstract class ShareaholicShareCount {
|
|
205 |
return false;
|
206 |
}
|
207 |
$body = json_decode($response['body'], true);
|
|
|
208 |
return isset($body[0]['result']['metadata']['globalCounts']['count']) ? intval($body[0]['result']['metadata']['globalCounts']['count']) : 0;
|
209 |
}
|
210 |
|
@@ -221,7 +246,8 @@ abstract class ShareaholicShareCount {
|
|
221 |
return false;
|
222 |
}
|
223 |
$body = json_decode($response['body'], true);
|
224 |
-
return
|
|
|
225 |
}
|
226 |
|
227 |
|
@@ -238,7 +264,7 @@ abstract class ShareaholicShareCount {
|
|
238 |
}
|
239 |
$response['body'] = substr($response['body'], 2, strlen($response['body']) - 3);
|
240 |
$body = json_decode($response['body'], true);
|
241 |
-
return isset($body['count']) ? $body['count'] :
|
242 |
}
|
243 |
|
244 |
|
@@ -254,7 +280,7 @@ abstract class ShareaholicShareCount {
|
|
254 |
return false;
|
255 |
}
|
256 |
$body = json_decode($response['body'], true);
|
257 |
-
return isset($body['shares']) ? $body['shares'] :
|
258 |
}
|
259 |
|
260 |
|
@@ -270,7 +296,8 @@ abstract class ShareaholicShareCount {
|
|
270 |
return false;
|
271 |
}
|
272 |
$body = json_decode($response['body'], true);
|
273 |
-
return
|
|
|
274 |
}
|
275 |
|
276 |
|
@@ -286,7 +313,8 @@ abstract class ShareaholicShareCount {
|
|
286 |
return false;
|
287 |
}
|
288 |
$body = json_decode($response['body'], true);
|
289 |
-
return
|
|
|
290 |
}
|
291 |
|
292 |
|
@@ -307,7 +335,7 @@ abstract class ShareaholicShareCount {
|
|
307 |
// From documentation, need to just grab the 2nd param: http://vk.com/developers.php?oid=-17680044&p=Share
|
308 |
$matches = array();
|
309 |
preg_match('/^VK\.Share\.count\(\d, (\d+)\);$/i', $response['body'], $matches);
|
310 |
-
return isset($matches[1]) ? intval($matches[1]) :
|
311 |
}
|
312 |
|
313 |
|
@@ -327,7 +355,7 @@ abstract class ShareaholicShareCount {
|
|
327 |
// 'ODKL.updateCount('odklcnt0','14198');'
|
328 |
$matches = array();
|
329 |
preg_match('/^ODKL\.updateCount\(\'odklcnt0\',\'(\d+)\'\);$/i', $response['body'], $matches);
|
330 |
-
return isset($matches[1]) ? intval($matches[1]) :
|
331 |
}
|
332 |
|
333 |
|
19 |
protected $services;
|
20 |
|
21 |
public function __construct($url, $services) {
|
22 |
+
// encode the url if needed
|
23 |
+
if (!$this->is_url_encoded($url)) {
|
24 |
+
$url = urlencode($url);
|
25 |
+
}
|
26 |
$this->url = $url;
|
27 |
$this->services = $services;
|
28 |
}
|
30 |
public static function get_services_config() {
|
31 |
return array(
|
32 |
'facebook' => array(
|
33 |
+
'url' => 'https://graph.facebook.com/?id=%s',
|
34 |
'method' => 'GET',
|
35 |
'timeout' => 3, // in number of seconds
|
36 |
'callback' => 'facebook_count_callback',
|
101 |
);
|
102 |
}
|
103 |
|
104 |
+
/**
|
105 |
+
* Check if the url is encoded
|
106 |
+
*
|
107 |
+
* The check is very simple and will fail if the url is encoded
|
108 |
+
* more than once because the check only decodes once
|
109 |
+
*
|
110 |
+
* @param string $url the url to check if it is encoded
|
111 |
+
* @return boolean true if the url is encoded and false otherwise
|
112 |
+
*/
|
113 |
+
public function is_url_encoded($url) {
|
114 |
+
$decoded = urldecode($url);
|
115 |
+
if (strcmp($url, $decoded) === 0) {
|
116 |
+
return false;
|
117 |
+
}
|
118 |
+
return true;
|
119 |
+
}
|
120 |
+
|
121 |
/**
|
122 |
* Check if calling the service returned any type of error
|
123 |
*
|
144 |
return false;
|
145 |
}
|
146 |
$body = json_decode($response['body'], true);
|
147 |
+
return isset($body['shares']) ? intval($body['shares']) : false;
|
148 |
}
|
149 |
|
150 |
|
160 |
return false;
|
161 |
}
|
162 |
$body = json_decode($response['body'], true);
|
163 |
+
return isset($body['count']) ? intval($body['count']) : false;
|
164 |
}
|
165 |
|
166 |
|
176 |
return false;
|
177 |
}
|
178 |
$body = json_decode($response['body'], true);
|
179 |
+
return isset($body['count']) ? intval($body['count']) : false;
|
180 |
}
|
181 |
|
182 |
|
193 |
* @param $config The services configuration object to be updated
|
194 |
*/
|
195 |
public function google_plus_prepare_request($url, &$config) {
|
196 |
+
if ($this->is_url_encoded($url)) {
|
197 |
+
$url = urldecode($url);
|
198 |
+
}
|
199 |
$post_fields = array(
|
200 |
array(
|
201 |
'method' => 'pos.plusones.get',
|
229 |
return false;
|
230 |
}
|
231 |
$body = json_decode($response['body'], true);
|
232 |
+
// special case: do not return false if the count is not set because the api can return without counts
|
233 |
return isset($body[0]['result']['metadata']['globalCounts']['count']) ? intval($body[0]['result']['metadata']['globalCounts']['count']) : 0;
|
234 |
}
|
235 |
|
246 |
return false;
|
247 |
}
|
248 |
$body = json_decode($response['body'], true);
|
249 |
+
// special case: do not return false if the count is set because the api can return without total posts
|
250 |
+
return isset($body[0]['total_posts']) ? intval($body[0]['total_posts']) : 0;
|
251 |
}
|
252 |
|
253 |
|
264 |
}
|
265 |
$response['body'] = substr($response['body'], 2, strlen($response['body']) - 3);
|
266 |
$body = json_decode($response['body'], true);
|
267 |
+
return isset($body['count']) ? intval($body['count']) : false;
|
268 |
}
|
269 |
|
270 |
|
280 |
return false;
|
281 |
}
|
282 |
$body = json_decode($response['body'], true);
|
283 |
+
return isset($body['shares']) ? intval($body['shares']) : false;
|
284 |
}
|
285 |
|
286 |
|
296 |
return false;
|
297 |
}
|
298 |
$body = json_decode($response['body'], true);
|
299 |
+
// special case: do not return false if views is not set because the api can return it not set
|
300 |
+
return isset($body['result']['views']) ? intval($body['result']['views']) : 0;
|
301 |
}
|
302 |
|
303 |
|
313 |
return false;
|
314 |
}
|
315 |
$body = json_decode($response['body'], true);
|
316 |
+
// special case: do not return false if the ups is not set because the api can return it not set
|
317 |
+
return isset($body['data']['children'][0]['data']['ups']) ? intval($body['data']['children'][0]['data']['ups']) : 0;
|
318 |
}
|
319 |
|
320 |
|
335 |
// From documentation, need to just grab the 2nd param: http://vk.com/developers.php?oid=-17680044&p=Share
|
336 |
$matches = array();
|
337 |
preg_match('/^VK\.Share\.count\(\d, (\d+)\);$/i', $response['body'], $matches);
|
338 |
+
return isset($matches[1]) ? intval($matches[1]) : false;
|
339 |
}
|
340 |
|
341 |
|
355 |
// 'ODKL.updateCount('odklcnt0','14198');'
|
356 |
$matches = array();
|
357 |
preg_match('/^ODKL\.updateCount\(\'odklcnt0\',\'(\d+)\'\);$/i', $response['body'], $matches);
|
358 |
+
return isset($matches[1]) ? intval($matches[1]) : false;
|
359 |
}
|
360 |
|
361 |
|
public_js.php
CHANGED
@@ -97,7 +97,7 @@ class ShareaholicPublicJS {
|
|
97 |
data: { action: 'shareaholic_share_counts_api', url: url, services: services },
|
98 |
success: function(res) {
|
99 |
if(res && res.data) {
|
100 |
-
cb(res.data);
|
101 |
}
|
102 |
}
|
103 |
})
|
97 |
data: { action: 'shareaholic_share_counts_api', url: url, services: services },
|
98 |
success: function(res) {
|
99 |
if(res && res.data) {
|
100 |
+
cb(res.data, true);
|
101 |
}
|
102 |
}
|
103 |
})
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: shareaholic
|
|
3 |
Tags: sexybookmarks, shareaholic, shareholic, facebook, twitter, linkedin, URL Shortener, bitly, tinyurl, Goo.gl, Google+1, Google Analytics, Google Plus, Google, Instapaper, Wish List, Digg, Gmail, Google Bookmarks, Translate, Tumblr, AIM, Yahoo Messenger, Delicious, StumbleUpon, mister wong, evernote, add this, addtoany, share this, sharethis, share and follow, share and enjoy, sharing is sexy, sharing is caring, yahoo, reddit, hackernews, tweet button, twitter button, fark, buffer, myspace, orkut, netlog, hubspot, weheartit, printfriendly, yammer, wanelo, pinterest, google translate, bookmarks, social, email button, social share, socialize, sociable, sharebar, bookmark button, share button, social bookmarking, bookmarks menu, bookmarking, share, seo, analytics, stats, sharing, facebook like, facebook recommend, WPMU, mutisite, shortcode, yaarp, yarpp, nrelate, outbrain, linkwithin, related content, related posts, related, popular posts, popular, thumbnails, recommendations
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 3.8.1
|
6 |
-
Stable tag: 7.4.0.
|
7 |
|
8 |
Adds an attractive social bookmarking menu and related content widget to your posts, pages, index, or any combination of the three.
|
9 |
|
@@ -155,6 +155,9 @@ Please see here: [Usage & Installation Instructions](http://support.shareaholic.
|
|
155 |
|
156 |
== Changelog ==
|
157 |
|
|
|
|
|
|
|
158 |
= 7.4.0.2 =
|
159 |
* Miscellaneous performance enhancements for Share Counts
|
160 |
|
@@ -1047,6 +1050,10 @@ Please see here: [Usage & Installation Instructions](http://support.shareaholic.
|
|
1047 |
|
1048 |
== Upgrade Notice ==
|
1049 |
|
|
|
|
|
|
|
|
|
1050 |
= 7.4.0.2 =
|
1051 |
|
1052 |
Miscellaneous performance enhancements for Share Counts
|
3 |
Tags: sexybookmarks, shareaholic, shareholic, facebook, twitter, linkedin, URL Shortener, bitly, tinyurl, Goo.gl, Google+1, Google Analytics, Google Plus, Google, Instapaper, Wish List, Digg, Gmail, Google Bookmarks, Translate, Tumblr, AIM, Yahoo Messenger, Delicious, StumbleUpon, mister wong, evernote, add this, addtoany, share this, sharethis, share and follow, share and enjoy, sharing is sexy, sharing is caring, yahoo, reddit, hackernews, tweet button, twitter button, fark, buffer, myspace, orkut, netlog, hubspot, weheartit, printfriendly, yammer, wanelo, pinterest, google translate, bookmarks, social, email button, social share, socialize, sociable, sharebar, bookmark button, share button, social bookmarking, bookmarks menu, bookmarking, share, seo, analytics, stats, sharing, facebook like, facebook recommend, WPMU, mutisite, shortcode, yaarp, yarpp, nrelate, outbrain, linkwithin, related content, related posts, related, popular posts, popular, thumbnails, recommendations
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 3.8.1
|
6 |
+
Stable tag: 7.4.0.3
|
7 |
|
8 |
Adds an attractive social bookmarking menu and related content widget to your posts, pages, index, or any combination of the three.
|
9 |
|
155 |
|
156 |
== Changelog ==
|
157 |
|
158 |
+
= 7.4.0.3 =
|
159 |
+
* Bugfix: Added url encoding for server side Share Counts API
|
160 |
+
|
161 |
= 7.4.0.2 =
|
162 |
* Miscellaneous performance enhancements for Share Counts
|
163 |
|
1050 |
|
1051 |
== Upgrade Notice ==
|
1052 |
|
1053 |
+
= 7.4.0.3 =
|
1054 |
+
|
1055 |
+
Added url encoding for server side Share Counts API for added reliability
|
1056 |
+
|
1057 |
= 7.4.0.2 =
|
1058 |
|
1059 |
Miscellaneous performance enhancements for Share Counts
|
shareaholic.php
CHANGED
@@ -3,14 +3,14 @@
|
|
3 |
* The main file!
|
4 |
*
|
5 |
* @package shareaholic
|
6 |
-
* @version 7.4.0.
|
7 |
*/
|
8 |
|
9 |
/*
|
10 |
Plugin Name: Shareaholic | share buttons, analytics, related content
|
11 |
Plugin URI: https://shareaholic.com/publishers/
|
12 |
Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
|
13 |
-
Version: 7.4.0.
|
14 |
Author: Shareaholic
|
15 |
Author URI: https://shareaholic.com
|
16 |
Text Domain: shareaholic
|
@@ -61,7 +61,7 @@ class Shareaholic {
|
|
61 |
const CM_API_URL = 'https://cm-web.shareaholic.com'; // uses static IPs for firewall whitelisting
|
62 |
const REC_API_URL = 'http://recommendations.shareaholic.com';
|
63 |
|
64 |
-
const VERSION = '7.4.0.
|
65 |
|
66 |
/**
|
67 |
* Starts off as false so that ::get_instance() returns
|
3 |
* The main file!
|
4 |
*
|
5 |
* @package shareaholic
|
6 |
+
* @version 7.4.0.3
|
7 |
*/
|
8 |
|
9 |
/*
|
10 |
Plugin Name: Shareaholic | share buttons, analytics, related content
|
11 |
Plugin URI: https://shareaholic.com/publishers/
|
12 |
Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
|
13 |
+
Version: 7.4.0.3
|
14 |
Author: Shareaholic
|
15 |
Author URI: https://shareaholic.com
|
16 |
Text Domain: shareaholic
|
61 |
const CM_API_URL = 'https://cm-web.shareaholic.com'; // uses static IPs for firewall whitelisting
|
62 |
const REC_API_URL = 'http://recommendations.shareaholic.com';
|
63 |
|
64 |
+
const VERSION = '7.4.0.3';
|
65 |
|
66 |
/**
|
67 |
* Starts off as false so that ::get_instance() returns
|
utilities.php
CHANGED
@@ -1034,7 +1034,7 @@ class ShareaholicUtilities {
|
|
1034 |
$has_important_services = true;
|
1035 |
// Does it have counts for twtr, fb, linkedin, pinterest, and delicious?
|
1036 |
foreach (array('twitter', 'facebook', 'linkedin', 'pinterest', 'delicious') as $service) {
|
1037 |
-
if (!isset($response['body']['data'][$service]) || !is_numeric($response['body']['data'][$service])) {
|
1038 |
$has_important_services = false;
|
1039 |
}
|
1040 |
}
|
1034 |
$has_important_services = true;
|
1035 |
// Does it have counts for twtr, fb, linkedin, pinterest, and delicious?
|
1036 |
foreach (array('twitter', 'facebook', 'linkedin', 'pinterest', 'delicious') as $service) {
|
1037 |
+
if (!isset($response['body']['data'][$service]) || !is_numeric($response['body']['data'][$service]) || $response['body']['data'][$service] <= 0) {
|
1038 |
$has_important_services = false;
|
1039 |
}
|
1040 |
}
|