PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 3.1.7
Wp Social Login and Register Social Counter v3.1.7
trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / lib / counter / counters-api.php
wp-social / lib / counter Last commit date
counters-api.php 2 years ago instagram-counter.php 5 years ago
counters-api.php
1544 lines
1 <?php
2
3 defined('ABSPATH') || exit;
4
5 $xsc_data = array();
6 $xsc_options = get_option('xs_counter_options') ? get_option('xs_counter_options') : array('data' => array());
7 $xsc_transient = get_transient('xs_counters_data');
8 $xsc_options_save = get_option('xs_counter_providers_data') ? get_option('xs_counter_providers_data') : [];
9
10 if(empty($xsc_transient) || (false === $xsc_transient)) {
11 $xsc_transient = [];
12 }
13
14 /**
15 * Twitter Followers Count
16 * todo - we are not using this function any more, check for other reference and delete it
17 *
18 */
19 if(!function_exists('xsc_twitter_count')) :
20 function xsc_twitter_count($cache_time = 3600) {
21
22 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
23
24 if(!empty($xsc_transient['twitter'])) {
25 $result = $xsc_transient['twitter'];
26 } elseif(empty($xsc_transient['twitter']) && !empty($xsc_data) && !empty($xsc_options['data']['twitter'])) {
27 $result = $xsc_options['data']['twitter'];
28 } else {
29 $result = '';
30 $id = isset($xsc_options_save['social']['twitter']['id']) ? $xsc_options_save['social']['twitter']['id'] : 'xpeedstudio';
31 $default_token = 'AAAAAAAAAAAAAAAAAAAAAJBzagAAAAAAXr%2Fxj2UWtV%2BnQNigsUm%2Bjrlkr4o%3DoYt2AFQFvPpPsJ1wtVmJ3MLetbYnmTWLFzDZJWLnXZtRJRZKOQ';
32 $token = get_option('xs_counter_twitter_token') ? get_option('xs_counter_twitter_token') : '';
33 $token = strlen($token) > 5 ? $token : $default_token;
34
35 $args = [
36 'httpversion' => '1.1',
37 'blocking' => true,
38 'timeout' => 10,
39 'headers' => [
40 'Authorization' => "Bearer $token",
41 'Accept-Language' => 'en',
42 ],
43 ];
44
45 add_filter('https_ssl_verify', '__return_false');
46 $api_url = "https://api.twitter.com/1.1/users/show.json?screen_name=$id";
47 $response = xsc_remote_get($api_url, true, $args);
48
49 /**
50 * We will show actual count always if user gives the access token
51 * even if it is 0!
52 */
53 if(isset($response['followers_count'])) {
54 $result = intval($response['followers_count']);
55 }
56
57
58 if(!empty($result)) //To update the stored data
59 {
60 $xsc_data['twitter'] = $result;
61 }
62
63 if(empty($result) && !empty($xsc_options['data']['twitter'])) //Get the stored data
64 {
65 $result = $xsc_options['data']['twitter'];
66 }
67 }
68
69 return (int)$result;
70
71 }
72 endif;
73
74 /**
75 * Facebook Fans
76 */
77
78 if(!function_exists('xsc_facebook_count')) :
79 function xsc_facebook_count($cache_time = 43000) {
80
81 //todo - delete it.
82
83 return 0;
84
85
86 $tran_key = '_xs_social_facebook_count_';
87
88 $trans_value = get_transient($tran_key);
89
90 if(false === $trans_value) {
91
92 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
93
94 $counter = 0;
95
96
97 if(!empty($xsc_transient['facebook'])) {
98 $counter = $xsc_transient['facebook'];
99 } elseif(empty($xsc_transient['facebook']) && !empty($xsc_data) && !empty($xsc_options['data']['facebook'])) {
100 $counter = $xsc_options['data']['facebook'];
101 } else {
102
103 $counter = '';
104
105 $social_id = isset($xsc_options_save['social']['facebook']['id']) ? $xsc_options_save['social']['facebook']['id'] : 'xpeedstudio';
106
107 $get_request = wp_remote_get("https://www.facebook.com/plugins/likebox.php?href=https://facebook.com/$social_id&show_faces=true&header=false&stream=false&show_border=false&locale=en_US", ['timeout' => 20]);
108 $the_request = wp_remote_retrieve_body($get_request);
109
110 $pattern = '/_1drq[^>]+>(.*?)<\/a/s';
111 preg_match($pattern, $the_request, $matches);
112
113 if(!empty($matches[1])) {
114 $number = strip_tags($matches[1]);
115
116 foreach(str_split($number) as $char) {
117 if(is_numeric($char)) {
118 $counter .= $char;
119 }
120 }
121 }
122
123 if(!empty($counter)) //To update the stored data
124 {
125 $xsc_data['facebook'] = $counter;
126 }
127
128 if(empty($counter) && !empty($xsc_options['data']['facebook'])) //Get the stored data
129 {
130 $counter = $xsc_options['data']['facebook'];
131 }
132 }
133
134 $expiration_time = empty($cache_time) ? 43200 : intval($cache_time);
135
136 set_transient($tran_key, $counter, $expiration_time);
137 update_option('_xs_social_facebook_last_cached', time());
138
139 return (int)$counter;
140 }
141
142 return (int)$trans_value;
143
144 }
145 endif;
146
147 /**
148 * Google+ Followers
149 */
150
151 if(!function_exists('xsc_google_count')) :
152 function xsc_google_count($cache_time = 3600) {
153
154 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
155
156 if(!empty($xsc_transient['google'])) {
157 $result = $xsc_transient['google'];
158 } elseif(empty($xsc_transient['google']) && !empty($xsc_data) && !empty($xsc_options['data']['google'])) {
159 $result = $xsc_options['data']['google'];
160 } else {
161 $id = (isset($xsc_options_save['social']['google']['id']) && strlen($xsc_options_save['social']['google']['id']) > 5) ? $xsc_options_save['social']['google']['id'] : 'google';
162 $key = (isset($xsc_options_save['social']['google']['key']) && strlen($xsc_options_save['social']['google']['key']) > 4) ? $xsc_options_save['social']['google']['key'] : 'AIzaSyBAwpfyAadivJ6EimaAOLh-F1gBeuwyVoY';
163
164 try {
165 // Get googleplus data.
166 $googleplus_data = xsc_remote_get('https://www.googleapis.com/plus/v1/people/' . $id . '?key=' . $key);
167
168 if(isset($googleplus_data['circledByCount'])) {
169 $result = (int)$googleplus_data['circledByCount'];
170 }
171 } catch(Exception $e) {
172 $result = 0;
173 }
174
175 if(!empty($result)) //To update the stored data
176 {
177 $xsc_data['google'] = $result;
178 }
179
180 if(empty($result) && !empty($xsc_options['data']['google'])) //Get the stored data
181 {
182 $result = $xsc_options['data']['google'];
183 }
184 }
185
186 return $result;
187
188 }
189 endif;
190
191
192 /**
193 * Youtube Subscribers
194 * todo - No more needed, use this class - lib/provider/counter/youtube-counter.php
195 */
196 if(!function_exists('xsc_youtube_count')) :
197 function xsc_youtube_count($cache_time = 3600) {
198
199 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
200
201 if(!empty($xsc_transient['youtube'])) {
202 $result = $xsc_transient['youtube'];
203 } elseif(empty($xsc_transient['youtube']) && !empty($xsc_data) && !empty($xsc_options['data']['youtube'])) {
204 $result = $xsc_options['data']['youtube'];
205 } else {
206 $result = '';
207 $id = (isset($xsc_options_save['social']['youtube']['id']) && strlen($xsc_options_save['social']['youtube']['id']) > 5) ? $xsc_options_save['social']['youtube']['id'] : 'UCJp-j8uvirVgez7TDAmfGYA';
208 $api = (isset($xsc_options_save['social']['youtube']['key']) && strlen($xsc_options_save['social']['youtube']['key']) > 4) ? $xsc_options_save['social']['youtube']['key'] : 'AIzaSyBAwpfyAadivJ6EimaAOLh-F1gBeuwyVoY';
209 try {
210 if(!empty($xsc_options_save['social']['youtube']['type']) && $xsc_options_save['social']['youtube']['type'] == 'Channel') {
211 $data = @xsc_remote_get("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=$id&key=$api");
212 } else {
213 $data = @xsc_remote_get("https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=$id&key=$api");
214 }
215 $result = (int)isset($data['items'][0]['statistics']['subscriberCount']) ? $data['items'][0]['statistics']['subscriberCount'] : 0;
216
217 } catch(Exception $e) {
218 $result = 0;
219 }
220
221 if(!empty($result)) //To update the stored data
222 {
223 $xsc_data['youtube'] = $result;
224 }
225
226 if(empty($result) && !empty($xsc_options['data']['youtube'])) //Get the stored data
227 {
228 $result = $xsc_options['data']['youtube'];
229 }
230 }
231
232 return (int)$result;
233
234 }
235 endif;
236
237
238 /**
239 * Vimeo Subscribers
240 */
241 if(!function_exists('xsc_vimeo_count')) :
242 function xsc_vimeo_count($cache_time = 3600) {
243
244 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
245
246 if(!empty($xsc_transient['vimeo'])) {
247 $result = $xsc_transient['vimeo'];
248 } elseif(empty($xsc_transient['vimeo']) && !empty($xsc_data) && !empty($xsc_options['data']['vimeo'])) {
249 $result = $xsc_options['data']['vimeo'];
250 } else {
251 $id = isset($xsc_options_save['social']['vimeo']['id']) ? $xsc_options_save['social']['vimeo']['id'] : 'user1837238';
252 try {
253 //$data = xsc_remote_get( "http://vimeo.com/api/v2/channel/$id/info.json" );
254 $default_token = '6m4GyfcFCklFySPiz9DDqup1gbL9oqkj';
255 $token = get_option('xs_counter_VimeoToken') ? get_option('xs_counter_VimeoToken') : '';
256 $token = strlen($token) > 5 ? $token : $default_token;
257
258 $args = [
259 'httpversion' => '1.1',
260 'blocking' => true,
261 'timeout' => 10,
262 'headers' => [
263 'Authorization' => "bearer $token",
264 ],
265 ];
266 $api_url = "http://vimeo.com/api/v2/channel/$id/info.json";
267 $data = xsc_remote_get($api_url, true, $args);
268 print_r($data);
269 $result = (int)isset($data['total_subscribers']) ? $data['total_subscribers'] : 0;
270 } catch(Exception $e) {
271 $result = 0;
272 }
273
274 if(!empty($result)) //To update the stored data
275 {
276 $xsc_data['vimeo'] = $result;
277 }
278
279 if(empty($result) && !empty($xsc_options['data']['vimeo'])) //Get the stored data
280 {
281 $result = $xsc_options['data']['vimeo'];
282 }
283 }
284
285 return $result;
286
287 }
288 endif;
289
290
291 /**
292 * Dribbble Followers
293 * todo - No more needed, use this class - lib/provider/counter/dribbble-counter.php
294 */
295 if(!function_exists('xsc_dribbble_count')) :
296 function xsc_dribbble_count($cache_time = 3600) {
297
298 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
299
300 if(!empty($xsc_transient['dribbble'])) {
301 $result = $xsc_transient['dribbble'];
302 } elseif(empty($xsc_transient['dribbble']) && !empty($xsc_data) && !empty($xsc_options['data']['dribbble'])) {
303 $result = $xsc_options['data']['dribbble'];
304 } else {
305 $result = '';
306 $id = isset($xsc_options_save['social']['dribbble']['id']) ? $xsc_options_save['social']['dribbble']['id'] : 'NicolasIbrahim';
307
308
309 $default_token = 'doesNotWork';
310 $token = get_option('xs_counter_dribbble_token') ? get_option('xs_counter_dribbble_token') : '';
311 $token = strlen($token) > 5 ? $token : $default_token;
312
313 try {
314 $data = @xsc_remote_get("https://api.dribbble.com/v2/user/$id?access_token=$token");
315 $result = (int)isset($data['followers_count']) ? $data['followers_count'] : 0;
316
317 } catch(Exception $e) {
318 $result = 0;
319 }
320
321 if(!empty($result)) //To update the stored data
322 {
323 $xsc_data['dribbble'] = $result;
324 }
325
326 if(empty($result) && !empty($xsc_options['data']['dribbble'])) //Get the stored data
327 {
328 $result = $xsc_options['data']['dribbble'];
329 }
330 }
331
332 return (int)$result;
333
334 }
335 endif;
336
337
338 /**
339 * Github Followers
340 */
341 if(!function_exists('xsc_github_count')) :
342 function xsc_github_count($cache_time = 3600) {
343
344 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
345
346 if(!empty($xsc_transient['github'])) {
347 $result = $xsc_transient['github'];
348 } elseif(empty($xsc_transient['github']) && !empty($xsc_data) && !empty($xsc_options['data']['github'])) {
349 $result = $xsc_options['data']['github'];
350 } else {
351 $id = isset($xsc_options_save['social']['github']['id']) ? $xsc_options_save['social']['github']['id'] : 'VingtCinq';
352 try {
353 $data = @xsc_remote_get("https://api.github.com/users/$id");
354 $result = (int)$data['followers'];
355 } catch(Exception $e) {
356 $result = 0;
357 }
358
359 if(!empty($result)) //To update the stored data
360 {
361 $xsc_data['github'] = $result;
362 }
363
364 if(empty($result) && !empty($xsc_options['data']['github'])) //Get the stored data
365 {
366 $result = $xsc_options['data']['github'];
367 }
368 }
369
370 return $result;
371
372 }
373 endif;
374
375
376 /**
377 * Envato Followers
378 */
379 if(!function_exists('xsc_envato_count')) :
380 function xsc_envato_count($cache_time = 3600) {
381
382 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
383
384 if(!empty($xsc_transient['envato'])) {
385 $result = $xsc_transient['envato'];
386 } elseif(empty($xsc_transient['envato']) && !empty($xsc_data) && !empty($xsc_options['data']['envato'])) {
387 $result = $xsc_options['data']['envato'];
388 } else {
389 //https://build.envato.com/api/
390 $id = isset($xsc_options_save['social']['envato']['id']) ? $xsc_options_save['social']['envato']['id'] : 'xpeedstudio';
391 try {
392 //$data = @xsc_remote_get("http://marketplace.envato.com/api/edge/user:$id.json");
393 $default_token = '6m4GyfcFCklFySPiz9DDqup1gbL9oqkj';
394 $token = get_option('xs_counter_EnvatoToken') ? get_option('xs_counter_EnvatoToken') : '';
395 $token = strlen($token) > 5 ? $token : $default_token;
396
397 $args = [
398 'httpversion' => '1.1',
399 'blocking' => true,
400 'timeout' => 10,
401 'headers' => [
402 'Authorization' => "Bearer $token",
403 ],
404 ];
405 $api_url = "https://api.envato.com/v1/market/user:$id.json";
406 $data = xsc_remote_get($api_url, true, $args);
407 print_r($data);
408 $result = (int)isset($data['user']['followers']) ? $data['user']['followers'] : 0;
409 } catch(Exception $e) {
410 $result = 0;
411 }
412
413 if(!empty($result)) //To update the stored data
414 {
415 $xsc_data['envato'] = $result;
416 }
417
418 if(empty($result) && !empty($xsc_options['data']['envato'])) //Get the stored data
419 {
420 $result = $xsc_options['data']['envato'];
421 }
422 }
423
424 return $result;
425
426 }
427 endif;
428
429
430 /**
431 * SoundCloud Followers
432 */
433 if(!function_exists('xsc_soundcloud_count')) :
434 function xsc_soundcloud_count($cache_time = 3600) {
435
436 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
437
438 if(!empty($xsc_transient['soundcloud'])) {
439 $result = $xsc_transient['soundcloud'];
440 } elseif(empty($xsc_transient['soundcloud']) && !empty($xsc_data) && !empty($xsc_options['data']['soundcloud'])) {
441 $result = $xsc_options['data']['soundcloud'];
442 } else {
443 $id = $xsc_options_save['social']['soundcloud']['id'];
444 $api = $xsc_options_save['social']['soundcloud']['api'];
445 try {
446 $data = @xsc_remote_get("http://api.soundcloud.com/users/$id.json?consumer_key=$api");
447 $result = (int)$data['followers_count'];
448 } catch(Exception $e) {
449 $result = 0;
450 }
451
452 if(!empty($result)) //To update the stored data
453 {
454 $xsc_data['soundcloud'] = $result;
455 }
456
457 if(empty($result) && !empty($xsc_options['data']['soundcloud'])) //Get the stored data
458 {
459 $result = $xsc_options['data']['soundcloud'];
460 }
461 }
462
463 return $result;
464
465 }
466 endif;
467
468
469 /**
470 * Behance Followers
471 */
472 if(!function_exists('xsc_behance_count')) :
473 function xsc_behance_count($cache_time = 3600) {
474
475 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
476
477 if(!empty($xsc_transient['behance'])) {
478 $result = $xsc_transient['behance'];
479 } elseif(empty($xsc_transient['behance']) && !empty($xsc_data) && !empty($xsc_options['data']['behance'])) {
480 $result = $xsc_options['data']['behance'];
481 } else {
482 $id = isset($xsc_options_save['social']['behance']['id']) ? $xsc_options_save['social']['behance']['id'] : 'mostafahazi';
483 $api = isset($xsc_options_save['social']['behance']['api']) ? $xsc_options_save['social']['behance']['api'] : 'INekEPLWGFlXlfmWjjOZD79vWNaD1Nxj';
484 try {
485 $url = sprintf(
486 'https://www.behance.net/v2/users/%s?api_key=%s',
487 $id,
488 $api
489 );
490 $data = xsc_remote_get($url);
491 //print_r($data);
492 $result = (int)isset($data['user']['stats']['followers']) ? $data['user']['stats']['followers'] : 0;
493 } catch(Exception $e) {
494 $result = 0;
495 }
496
497 if(!empty($result)) //To update the stored data
498 {
499 $xsc_data['behance'] = $result;
500 }
501
502 if(empty($result) && !empty($xsc_options['data']['behance'])) //Get the stored data
503 {
504 $result = $xsc_options['data']['behance'];
505 }
506 }
507
508 return $result;
509
510 }
511 endif;
512
513
514 ///**
515 // * Instagram Followers
516
517 // Delete as it does not work anymore...
518 // todo - delete it later
519 // */
520 //if(!function_exists('xsc_instagram_count')) :
521 //
522 // function xsc_instagram_count($cache_time) {
523 //
524 //
525 // $tran_key = '_xs_social_instagram_count_55';
526 //
527 // $trans_value = get_transient($tran_key);
528 //
529 //
530 // if(false === $trans_value) {
531 //
532 // global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
533 //
534 // if(!empty($xsc_transient['instagram'])) {
535 // $result = $xsc_transient['instagram'];
536 // } elseif(empty($xsc_transient['instagram']) && !empty($xsc_data) && !empty($xsc_options['data']['instagram'])) {
537 // $result = $xsc_options['data']['instagram'];
538 // } else {
539 //
540 //
541 // $default_token = '2367672995.f53f83f.88eda6a77b1d4a9fb704fedc4ff869eb';
542 // $token = get_option('xs_counter_instagram_token') ? get_option('xs_counter_instagram_token') : '';
543 // if(strlen($token) > 5) {
544 // $token = strlen($token) > 5 ? $token : $default_token;
545 // $explodeUs = explode('.', $token);
546 // $id = current($explodeUs);
547 // $url = sprintf(
548 // 'https://api.instagram.com/v1/users/%s?access_token=%s',
549 // $id,
550 // $token
551 // );
552 // $data = xsc_remote_get($url);
553 // $result = (int)isset($data['data']['counts']['followed_by']) ? $data['data']['counts']['followed_by'] : 0;
554 // } else {
555 //
556 // $id = isset($xsc_options_save['social']['instagram']['id']) ? $xsc_options_save['social']['instagram']['id'] : '2367672995';
557 //
558 // $url = 'http://instagram.com/' . $id . '#';
559 //
560 // $get_request = wp_remote_get($url, ['timeout' => 20]);
561 // $the_request = wp_remote_retrieve_body($get_request);
562 //
563 // $pattern = "/followed_by\":[ ]*{\"count\":(.*?)}/";
564 //
565 // if(is_string($the_request) && preg_match($pattern, $the_request, $matches)) {
566 //
567 // $result = intval($matches[1]);
568 // }
569 // }
570 //
571 // if(!empty($result)) //To update the stored data
572 // {
573 // $xsc_data['instagram'] = $result;
574 // }
575 //
576 // if(empty($result) && !empty($xsc_options['data']['instagram'])) //Get the stored data
577 // {
578 // $result = $xsc_options['data']['instagram'];
579 // }
580 //
581 // }
582 //
583 // $expiration_time = empty($cache_time) ? 43200 : intval($cache_time);
584 //
585 // set_transient($tran_key, $result, $expiration_time);
586 // update_option('_xs_social_instagram_last_cached', time());
587 //
588 // return $result;
589 // }
590 //
591 // return $trans_value;
592 //
593 // }
594 //endif;
595 //
596
597 /**
598 * Foursquare Followers
599 */
600 if(!function_exists('xsc_foursquare_count')) :
601 function xsc_foursquare_count($cache_time = 3600) {
602
603 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
604
605 if(!empty($xsc_transient['foursquare'])) {
606 $result = $xsc_transient['foursquare'];
607 } elseif(empty($xsc_transient['foursquare']) && !empty($xsc_data) && !empty($xsc_options['data']['foursquare'])) {
608 $result = $xsc_options['data']['foursquare'];
609 } else {
610 $api = get_option('foursquare_access_token');
611 $date = date("Ymd");
612 try {
613 $data = @xsc_remote_get("https://api.foursquare.com/v2/users/self?oauth_token=$api&v=$date");
614 $result = (int)$data['response']['user']['friends']['count'];
615 } catch(Exception $e) {
616 $result = 0;
617 }
618
619 if(!empty($result)) //To update the stored data
620 {
621 $xsc_data['foursquare'] = $result;
622 }
623
624 if(empty($result) && !empty($xsc_options['data']['foursquare'])) //Get the stored data
625 {
626 $result = $xsc_options['data']['foursquare'];
627 }
628 }
629
630 return $result;
631
632 }
633 endif;
634
635
636 /**
637 * Mailchimp Subscribers
638 */
639 if(!function_exists('xsc_mailchimp_count')) :
640 function xsc_mailchimp_count($cache_time) {
641
642 $tran_key = '_xs_social_mailchimp_count_';
643
644 $trans_value = get_transient($tran_key);
645
646 if(false === $trans_value) {
647
648 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
649
650 if(!empty($xsc_transient['mailchimp'])) {
651 $result = $xsc_transient['mailchimp'];
652 } elseif(empty($xsc_transient['mailchimp']) && !empty($xsc_data) && !empty($xsc_options['data']['mailchimp'])) {
653 $result = $xsc_options['data']['mailchimp'];
654 } else {
655
656 $result = 0;
657 $id = isset($xsc_options_save['social']['mailchimp']['id']) ? $xsc_options_save['social']['mailchimp']['id'] : ''; //35bfe5a4f5
658 $apikey = isset($xsc_options_save['social']['mailchimp']['api']) ? $xsc_options_save['social']['mailchimp']['api'] : '7025ab20d2b50082e656df4e8e98f02f-us8';
659
660 $server = explode('-', $apikey);
661 $hosting = end($server);
662
663 $url = sprintf('https://%s.api.mailchimp.com/3.0/lists/%s', $hosting, $id);
664 $response = wp_remote_get($url, [
665 'timeout' => 10,
666 'headers' => [
667 'Authorization' => 'apikey ' . $apikey,
668 'Content-Type' => 'application/vnd.api+json',
669 ],
670 ]);
671 $response = wp_remote_retrieve_body($response);
672 $response = json_decode($response, true);
673
674 /*
675 //https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/
676 $url = sprintf('https://%s.api.mailchimp.com/3.0/', $hosting);
677 $response = wp_remote_get( $url, array(
678 'timeout' => 10,
679 'headers' => array(
680 'Authorization' => 'apikey ' . $apikey,
681 'Content-Type' => 'application/vnd.api+json',
682 )
683 ));
684 $response = wp_remote_retrieve_body( $response );
685 $response = json_decode( $response, true );
686
687 print_r($response);
688 */
689
690 if(isset($response['lists'][0]['stats'])) {
691 $result = isset($response['lists'][0]['stats']['member_count']) ? $response['lists'][0]['stats']['member_count'] : 0;
692 } else {
693 $result = isset($response['stats']['member_count']) ? $response['stats']['member_count'] : 0;
694 }
695
696 if(!empty($result)) //To update the stored data
697 {
698 $xsc_data['mailchimp'] = $result;
699 }
700
701 if(empty($result) && !empty($xsc_options['data']['mailchimp'])) //Get the stored data
702 {
703 $result = $xsc_options['data']['mailchimp'];
704 }
705 }
706
707 $expiration_time = empty($cache_time) ? 43200 : intval($cache_time);
708
709 set_transient($tran_key, $result, $expiration_time);
710 update_option('_xs_social_mailchimp_last_cached', time());
711
712 return $result;
713 }
714
715 return $trans_value;
716
717 }
718 endif;
719
720
721 /**
722 * MailPoet Subscribers
723 */
724 if(!function_exists('xsc_mailpoet_count')) :
725 function xsc_mailpoet_count($cache_time = 3600) {
726
727 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
728
729 if(!empty($xsc_transient['mailpoet'])) {
730 $result = $xsc_transient['mailpoet'];
731 } elseif(empty($xsc_transient['mailpoet']) && !empty($xsc_data) && !empty($xsc_options['data']['mailpoet'])) {
732 $result = $xsc_options['data']['mailpoet'];
733 } else {
734
735 $list = $xsc_options_save['social']['mailpoet']['list'];
736
737 if(!empty($list)) {
738 if($list == 'all') {
739 $result = do_shortcode('[mailpoet_subscribers_count]');
740 } else {
741 $result = do_shortcode('[mailpoet_subscribers_count segments="' . $list . '"]');
742 }
743 }
744
745 if(!empty($result)) //To update the stored data
746 {
747 $xsc_data['mailpoet'] = $result;
748 }
749
750 if(empty($result) && !empty($xsc_options['data']['mailpoet'])) //Get the stored data
751 {
752 $result = $xsc_options['data']['mailpoet'];
753 }
754 }
755
756 return $result;
757
758 }
759 endif;
760
761
762 /**
763 * myMail Subscribers
764 */
765 if(!function_exists('xsc_mymail_count')) :
766 function xsc_mymail_count($cache_time = 3600) {
767
768 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
769
770 if(!empty($xsc_transient['mymail'])) {
771 $result = $xsc_transient['mymail'];
772 } elseif(empty($xsc_transient['mymail']) && !empty($xsc_data) && !empty($xsc_options['data']['mymail'])) {
773 $result = $xsc_options['data']['mymail'];
774 } else {
775
776 $list = $xsc_options_save['social']['mymail']['list'];
777
778 if(!empty($list)) {
779 if($list == 'all') {
780 $counts = mailster('subscribers')->get_count_by_status();
781 $result = $counts[1];
782 } else {
783 $result = mailster('lists')->get_member_count($list, 1);
784 }
785 }
786
787 if(!empty($result)) //To update the stored data
788 {
789 $xsc_data['mymail'] = $result;
790 }
791
792 if(empty($result) && !empty($xsc_options['data']['mymail'])) //Get the stored data
793 {
794 $result = $xsc_options['data']['mymail'];
795 }
796 }
797
798 return $result;
799
800 }
801 endif;
802
803
804 /**
805 * LinkedIn Followers
806 */
807 if(!function_exists('xsc_linkedin_count')) :
808 function xsc_linkedin_count($cache_time = 3600) {
809
810 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
811
812 if(!empty($xsc_transient['linkedin'])) {
813 $result = $xsc_transient['linkedin'];
814 } elseif(empty($xsc_transient['linkedin']) && !empty($xsc_data) && !empty($xsc_options['data']['linkedin'])) {
815 $result = $xsc_options['data']['linkedin'];
816 } else {
817 $default_token = 'AQRX2qAD_yEPBj6jdTLqcn6rgPCgZCKcF8gRPppRcW94N7zZus35iZ4LylyRcuMfm7HnphraWkSTyDF6sxFPSZk5x2GnQnHYDV3Ueu1-qVp5J_3Nw5ZIC1A_OOkn1pfj1q_ZihHq4_6HOfkS7oVO9ZTjUogsfc1U6DEKgGQVi1JT-5NLfKm3E2XoZal33g';
818 $token = get_option('xs_counter_linkedin_token') ? get_option('xs_counter_linkedin_token') : '';
819 //$token = strlen($token) > 5 ? $token : $default_token;
820
821 $type = isset($xsc_options_save['social']['linkedin']['type']) ? $xsc_options_save['social']['linkedin']['type'] : 'Profile';
822 $result = 0;
823 if(!empty($xsc_options_save['social']['linkedin']['type']) && !empty($token)) {
824
825 $args = [
826 'headers' => [
827 'Authorization' => sprintf('Bearer %s', $token),
828 'Content-Type' => 'application/json',
829 'x-li-format' => 'json',
830 'X-Restli-Protocol-Version' => '2.0.0',
831 ],
832 ];
833
834 if($type == 'Profile') {
835 $id = isset($xsc_options_save['social']['linkedin']['id']) ? $xsc_options_save['social']['linkedin']['id'] : '';
836
837 //$data = xsc_remote_get('https://api.linkedin.com/v2/me', true, $args);
838 $fields = 'id,numConnections';
839
840 //$data = xsc_remote_get('https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams),numConnections)', true, $args);
841 $data = xsc_remote_get('https://api.linkedin.com/v2/me?projection=(num-connections)', true, $args);
842
843 try {
844 $result = (int)isset($data['numConnections']) ? $data['numConnections'] : 0;
845 } catch(Exception $e) {
846 $result = 0;
847 }
848
849 } elseif($type == 'Company') {
850 $companyId = isset($xsc_options_save['social']['linkedin']['id']) ? $xsc_options_save['social']['linkedin']['id'] : '';
851 $page_id = sprintf('https://api.linkedin.com/v1/companies/%s/num-followers?format=json', $companyId);
852 //$page_id = sprintf('https://api.linkedin.com/v2/organizations?q=vanityI&vanityName=%s', $companyId );
853 try {
854 $data = xsc_remote_get($page_id, true, $args);
855 //print_r($data);
856 if(!is_array($data)) {
857 $result = $data;
858 }
859 } catch(Exception $e) {
860 $result = 0;
861 }
862 }
863
864 if(!empty($result)) { //To update the stored data
865 $xsc_data['linkedin'] = $result;
866 }
867
868 if(empty($result) && !empty($xsc_options['data']['linkedin'])) { //Get the stored data
869 $result = $xsc_options['data']['linkedin'];
870 }
871 }
872 }
873
874 return $result;
875 }
876 endif;
877
878
879 /**
880 * Vk Members
881 */
882 if(!function_exists('xsc_vkontakte_count')) :
883 function xsc_vkontakte_count($cache_time = 3600) {
884
885 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
886
887 $counter = 0;
888
889 if(!empty($xsc_transient['vkontakte'])) {
890 $counter = $xsc_transient['vkontakte'];
891 } elseif(empty($xsc_transient['vkontakte']) && !empty($xsc_data) && !empty($xsc_options['data']['vkontakte'])) {
892 $counter = $xsc_options['data']['vkontakte'];
893 } else {
894
895 $id = isset($xsc_options_save['social']['vkontakte']['id']) ? $xsc_options_save['social']['vkontakte']['id'] : 'id72867608';
896
897 $get_request = wp_remote_get("https://m.vk.com/$id", ['timeout' => 20]);
898 $the_request = wp_remote_retrieve_body($get_request);
899
900 $pattern = '/pm_counter[^>]+>(.*?)<\/em/s';
901 preg_match($pattern, $the_request, $matches);
902
903 if(!empty($matches[1])) {
904 $number = strip_tags($matches[1]);
905 $counter = '';
906
907 foreach(str_split($number) as $char) {
908 if(is_numeric($char)) {
909 $counter .= $char;
910 }
911 }
912 }
913
914 if(!empty($counter)) //To update the stored data
915 {
916 $xsc_data['vkontakte'] = $counter;
917 }
918
919 if(empty($counter) && !empty($xsc_options['data']['vkontakte'])) //Get the stored data
920 {
921 $counter = $xsc_options['data']['vkontakte'];
922 }
923 }
924
925 return $counter;
926
927 }
928 endif;
929
930
931 /**
932 * Tumblr Followers
933 */
934 if(!function_exists('xsc_tumblr_count')) :
935 function xsc_tumblr_count($cache_time = 3600) {
936
937 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
938
939 if(!empty($xsc_transient['tumblr'])) {
940 $result = $xsc_transient['tumblr'];
941 } elseif(empty($xsc_transient['tumblr']) && !empty($xsc_data) && !empty($xsc_options['data']['tumblr'])) {
942 $result = $xsc_options['data']['tumblr'];
943 } else {
944 $base_hostname = str_replace([
945 'http://',
946 'https://',
947 ], '', $xsc_options_save['social']['tumblr']['hostname']);
948
949 try {
950 $consumer_key = get_option('tumblr_api_key');
951 $consumer_secret = get_option('tumblr_api_secret');
952 $oauth_token = get_option('tumblr_oauth_token');
953 $oauth_token_secret = get_option('tumblr_token_secret');
954 $tumblr_api_URI = 'http://api.tumblr.com/v2/blog/' . $base_hostname . '/followers';
955
956 $tum_oauth = new TumblrOAuthTie($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
957 $tumblr_api = $tum_oauth->post($tumblr_api_URI, '');
958
959 if($tumblr_api->meta->status == 200 && !empty($tumblr_api->response->total_users)) {
960 $result = (int)$tumblr_api->response->total_users;
961 }
962
963 } catch(Exception $e) {
964 $result = 0;
965 }
966
967 if(!empty($result)) //To update the stored data
968 {
969 $xsc_data['tumblr'] = $result;
970 }
971
972 if(empty($result) && !empty($xsc_options['data']['tumblr'])) //Get the stored data
973 {
974 $result = $xsc_options['data']['tumblr'];
975 }
976 }
977
978 return $result;
979
980 }
981 endif;
982
983
984 /**
985 * 500px Followers
986 */
987 if(!function_exists('xsc_500px_count')) :
988 function xsc_500px_count($cache_time = 3600) {
989
990 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
991
992 $result = 0;
993
994 if(!empty($xsc_transient['500px'])) {
995 $result = $xsc_transient['500px'];
996 } elseif(empty($xsc_transient['500px']) && !empty($xsc_data) && !empty($xsc_options['data']['500px'])) {
997 $result = $xsc_options['data']['500px'];
998 } else {
999
1000 $social_id = $xsc_options_save['social']['500px']['username'];
1001 $get_request = wp_remote_get("https://500px.com/$social_id", ['timeout' => 20]);
1002 $the_request = wp_remote_retrieve_body($get_request);
1003
1004 $pattern = '/followers[^>]+>(.*?)<\/li/s';
1005 preg_match($pattern, $the_request, $matches);
1006
1007 if(!empty($matches[1])) {
1008
1009 $number = strip_tags($matches[1]);
1010 $result = '';
1011
1012 foreach(str_split($number) as $char) {
1013 if(is_numeric($char)) {
1014 $result .= $char;
1015 }
1016 }
1017 }
1018
1019 if(!empty($result)) //To update the stored data
1020 {
1021 $xsc_data['500px'] = $result;
1022 }
1023
1024 if(empty($result) && !empty($xsc_options['data']['500px'])) //Get the stored data
1025 {
1026 $result = $xsc_options['data']['500px'];
1027 }
1028 }
1029
1030 return $result;
1031
1032 }
1033 endif;
1034
1035
1036 /**
1037 * Pinterest Followers
1038 */
1039 if(!function_exists('xsc_pinterest_count')) :
1040 function xsc_pinterest_count($cache_time = 3600) {
1041
1042 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1043
1044 if(!empty($xsc_transient['pinterest'])) {
1045 $result = $xsc_transient['pinterest'];
1046 } elseif(empty($xsc_transient['pinterest']) && !empty($xsc_data) && !empty($xsc_options['data']['pinterest'])) {
1047 $result = $xsc_options['data']['pinterest'];
1048 } else {
1049 $result = '';
1050 $username = isset($xsc_options_save['social']['pinterest']['username']) ? $xsc_options_save['social']['pinterest']['username'] : '101outfitcom';
1051 try {
1052 // Pinterest API integration
1053 $api_url = 'https://api.pinterest.com/v3/pidgets/users/' . urlencode($username) . '/pins/';
1054 $response = wp_remote_get($api_url);
1055
1056 if (!is_wp_error($response) && $response['response']['code'] === 200) {
1057 $data = json_decode($response['body'], true);
1058
1059 if (isset($data['data']['user']['follower_count'])) {
1060 $result = $data['data']['user']['follower_count'];
1061 }
1062 }
1063 } catch(Exception $e) {
1064 $result = 0;
1065 }
1066
1067 if(!empty($result)) //To update the stored data
1068 {
1069 $xsc_data['pinterest'] = $result;
1070 }
1071
1072 if(empty($result) && !empty($xsc_options['data']['pinterest'])) //Get the stored data
1073 {
1074 $result = $xsc_options['data']['pinterest'];
1075 }
1076 }
1077
1078 return $result;
1079 }
1080 endif;
1081
1082
1083 /**
1084 * Flickr Followers
1085 */
1086 if(!function_exists('xsc_flickr_count')) :
1087 function xsc_flickr_count($cache_time = 3600) {
1088
1089 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1090
1091 if(!empty($xsc_transient['flickr'])) {
1092 $result = $xsc_transient['flickr'];
1093 } elseif(empty($xsc_transient['flickr']) && !empty($xsc_data) && !empty($xsc_options['data']['flickr'])) {
1094 $result = $xsc_options['data']['flickr'];
1095 } else {
1096 $id = $xsc_options_save['social']['flickr']['id'];
1097 $api = $xsc_options_save['social']['flickr']['api'];
1098 try {
1099 $data = @xsc_remote_get("https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=$api&group_id=$id&format=json&nojsoncallback=1");
1100 $result = (int)$data['group']['members']['_content'];
1101 } catch(Exception $e) {
1102 $result = 0;
1103 }
1104
1105 if(!empty($result)) //To update the stored data
1106 {
1107 $xsc_data['flickr'] = $result;
1108 }
1109
1110 if(empty($result) && !empty($xsc_options['data']['flickr'])) //Get the stored data
1111 {
1112 $result = $xsc_options['data']['flickr'];
1113 }
1114 }
1115
1116 return $result;
1117
1118 }
1119 endif;
1120
1121
1122 /**
1123 * Steam Followers
1124 */
1125 if(!function_exists('xsc_steam_count')) :
1126 function xsc_steam_count($cache_time = 3600) {
1127
1128 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1129
1130 if(!empty($xsc_transient['steam'])) {
1131 $result = $xsc_transient['steam'];
1132 } elseif(empty($xsc_transient['steam']) && !empty($xsc_data) && !empty($xsc_options['data']['steam'])) {
1133 $result = $xsc_options['data']['steam'];
1134 } else {
1135 $id = $xsc_options_save['social']['steam']['group'];
1136 try {
1137 $data = @xsc_remote_get("http://steamcommunity.com/groups/$id/memberslistxml?xml=1", false);
1138 $data = @new SimpleXmlElement($data);
1139 $result = (int)$data->groupDetails->memberCount;
1140 } catch(Exception $e) {
1141 $result = 0;
1142 }
1143
1144 if(!empty($result)) //To update the stored data
1145 {
1146 $xsc_data['steam'] = $result;
1147 }
1148
1149 if(empty($result) && !empty($xsc_options['data']['steam'])) //Get the stored data
1150 {
1151 $result = $xsc_options['data']['steam'];
1152 }
1153 }
1154
1155 return $result;
1156 }
1157 endif;
1158
1159
1160 /**
1161 * Rss Subscribers
1162 */
1163 if(!function_exists('xsc_rss_count')) :
1164 function xsc_rss_count($cache_time = 3600) {
1165
1166 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1167
1168 if(!empty($xsc_transient['rss'])) {
1169 $result = $xsc_transient['rss'];
1170 } elseif(empty($xsc_transient['rss']) && !empty($xsc_data) && !empty($xsc_options['data']['rss'])) {
1171 $result = $xsc_options['data']['rss'];
1172 } else {
1173 if(($xsc_options_save['social']['rss']['type'] == 'feedpress.it') && !empty($xsc_options_save['social']['rss']['feedpress'])) {
1174 try {
1175 $feedpress_url = esc_url($xsc_options_save['social']['rss']['feedpress']);
1176 $feedpress_url = str_replace('feedpress.it', 'feed.press', $feedpress_url);
1177 //$feedpress_url = str_replace( 'http', 'https', $feedpress_url);
1178
1179 $data = @xsc_remote_get($feedpress_url);
1180 $result = (int)$data['subscribers'];
1181 } catch(Exception $e) {
1182 $result = 0;
1183 }
1184 } elseif(($xsc_options_save['social']['rss']['type'] == 'Manual') && !empty($xsc_options_save['social']['rss']['manual'])) {
1185 $result = $xsc_options_save['social']['rss']['manual'];
1186 } else {
1187 $result = 0;
1188 }
1189 if(!empty($result)) //To update the stored data
1190 {
1191 $xsc_data['rss'] = $result;
1192 }
1193
1194 if(empty($result) && !empty($xsc_options['data']['rss'])) //Get the stored data
1195 {
1196 $result = $xsc_options['data']['rss'];
1197 }
1198 }
1199
1200 return $result;
1201
1202 }
1203 endif;
1204
1205
1206 /*
1207 * Spotify Followers
1208 */
1209 if(!function_exists('xsc_spotify_count')) :
1210 function xsc_spotify_count($cache_time = 3600) {
1211
1212 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1213
1214 if(!empty($xsc_transient['spotify'])) {
1215 $result = $xsc_transient['spotify'];
1216 } elseif(empty($xsc_transient['spotify']) && !empty($xsc_data) && !empty($xsc_options['data']['spotify'])) {
1217 $result = $xsc_options['data']['spotify'];
1218 } else {
1219 $id = $url = $xsc_options_save['social']['spotify']['id'];
1220 $id = rtrim($id, "/");
1221 $id = urlencode(str_replace([
1222 'https://play.spotify.com/',
1223 'https://player.spotify.com/',
1224 'artist/',
1225 'user/',
1226 ], '', $id));
1227
1228 try {
1229 if(!empty($url) && strpos($url, 'artist') !== false) {
1230 $data = @xsc_remote_get("https://api.spotify.com/v1/artists/$id");
1231 } else {
1232 $data = @xsc_remote_get("https://api.spotify.com/v1/users/$id");
1233 }
1234 $result = (int)$data['followers']['total'];
1235
1236 } catch(Exception $e) {
1237 $result = 0;
1238 }
1239
1240 if(!empty($result)) //To update the stored data
1241 {
1242 $xsc_data['spotify'] = $result;
1243 }
1244
1245 if(empty($result) && !empty($xsc_options['data']['spotify'])) //Get the stored data
1246 {
1247 $result = $xsc_options['data']['spotify'];
1248 }
1249 }
1250
1251 return $result;
1252
1253 }
1254 endif;
1255
1256
1257 /**
1258 * Goodreads Followers
1259 */
1260 if(!function_exists('xsc_goodreads_count')) :
1261 function xsc_goodreads_count($cache_time = 3600) {
1262
1263 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1264
1265 if(!empty($xsc_transient['goodreads'])) {
1266 $result = $xsc_transient['goodreads'];
1267 } elseif(empty($xsc_transient['goodreads']) && !empty($xsc_data) && !empty($xsc_options['data']['goodreads'])) {
1268 $result = $xsc_options['data']['goodreads'];
1269 } else {
1270 $id = $url = $xsc_options_save['social']['goodreads']['id'];
1271 $key = $xsc_options_save['social']['goodreads']['key'];
1272
1273 $id = rtrim($id, "/");
1274 $id = @parse_url($id);
1275 $id = $id['path'];
1276 $id = str_replace(['/user/show/', '/author/show/'], '', $id);
1277 if(strpos($id, '-') !== false) {
1278 $id = explode('-', $id);
1279 } else {
1280 $id = explode('.', $id);
1281 }
1282 $id = $id[0];
1283 try {
1284 if(!empty($url) && strpos($url, 'author') !== false) {
1285 $data = @xsc_remote_get("https://www.goodreads.com/author/show/$id.xml?key=$key", false);
1286 $data = @new SimpleXmlElement($data);
1287 $result = (int)$data->author->author_followers_count;
1288 } else {
1289 $data = @xsc_remote_get("https://www.goodreads.com/user/show/$id.xml?key=$key", false);
1290 $data = @new SimpleXmlElement($data);
1291 $result = (int)$data->user->friends_count;
1292 }
1293
1294 } catch(Exception $e) {
1295 $result = 0;
1296 }
1297
1298 if(!empty($result)) //To update the stored data
1299 {
1300 $xsc_data['goodreads'] = $result;
1301 }
1302
1303 if(empty($result) && !empty($xsc_options['data']['goodreads'])) //Get the stored data
1304 {
1305 $result = $xsc_options['data']['goodreads'];
1306 }
1307 }
1308
1309 return $result;
1310
1311 }
1312 endif;
1313
1314
1315 /**
1316 * Twitch Followers
1317 */
1318 if(!function_exists('xsc_twitch_count')) :
1319 function xsc_twitch_count($cache_time = 3600) {
1320
1321 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1322
1323 if(!empty($xsc_transient['twitch'])) {
1324 $result = $xsc_transient['twitch'];
1325 } elseif(empty($xsc_transient['twitch']) && !empty($xsc_data) && !empty($xsc_options['data']['twitch'])) {
1326 $result = $xsc_options['data']['twitch'];
1327 } else {
1328 $id = $xsc_options_save['social']['twitch']['id'];
1329 $api = get_option('twitch_access_token');
1330
1331 try {
1332 $data = @xsc_remote_get("https://api.twitch.tv/kraken/channels/$id?oauth_token=$api");
1333
1334 $result = (int)$data['followers'];
1335 } catch(Exception $e) {
1336 $result = 0;
1337 }
1338
1339 if(!empty($result)) //To update the stored data
1340 {
1341 $xsc_data['twitch'] = $result;
1342 }
1343
1344 if(empty($result) && !empty($xsc_options['data']['twitch'])) //Get the stored data
1345 {
1346 $result = $xsc_options['data']['twitch'];
1347 }
1348 }
1349
1350 return $result;
1351
1352 }
1353 endif;
1354
1355
1356 /**
1357 * Mixcloud Followers
1358 */
1359 if(!function_exists('xsc_mixcloud_count')) :
1360 function xsc_mixcloud_count($cache_time = 3600) {
1361
1362 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1363
1364 if(!empty($xsc_transient['mixcloud'])) {
1365 $result = $xsc_transient['mixcloud'];
1366 } elseif(empty($xsc_transient['mixcloud']) && !empty($xsc_data) && !empty($xsc_options['data']['mixcloud'])) {
1367 $result = $xsc_options['data']['mixcloud'];
1368 } else {
1369 $id = $xsc_options_save['social']['mixcloud']['id'];
1370 try {
1371 $data = @xsc_remote_get("http://api.mixcloud.com/$id/");
1372 $result = (int)$data['follower_count'];
1373 } catch(Exception $e) {
1374 $result = 0;
1375 }
1376
1377 if(!empty($result)) //To update the stored data
1378 {
1379 $xsc_data['mixcloud'] = $result;
1380 }
1381
1382 if(empty($result) && !empty($xsc_options['data']['mixcloud'])) //Get the stored data
1383 {
1384 $result = $xsc_options['data']['mixcloud'];
1385 }
1386 }
1387
1388 return $result;
1389
1390 }
1391 endif;
1392
1393
1394 /**
1395 * Posts Number
1396 */
1397 if(!function_exists('xsc_posts_count')) :
1398 function xsc_posts_count($cache_time = 3600) {
1399 $count_posts = wp_count_posts();
1400
1401 return $result = $count_posts->publish;
1402 }
1403 endif;
1404
1405
1406 /**
1407 * Comments number
1408 */
1409 if(!function_exists('xsc_comments_count')) :
1410 function xsc_comments_count($cache_time = 3600) {
1411 $comments_count = wp_count_comments();
1412
1413 return $result = $comments_count->approved;
1414 }
1415 endif;
1416
1417
1418 /**
1419 * Members number
1420 */
1421 if(!function_exists('xsc_members_count')) :
1422 function xsc_members_count($cache_time = 3600) {
1423 $members_count = count_users();
1424
1425 return $result = $members_count['total_users'];
1426 }
1427 endif;
1428
1429
1430 /**
1431 * Groups number
1432 */
1433 if(!function_exists('xsc_groups_count')) :
1434 function xsc_groups_count($cache_time = 3600) {
1435 return $result = groups_get_total_group_count();
1436 }
1437 endif;
1438
1439
1440 /**
1441 * bbPress Counters
1442 */
1443 if(!function_exists('xsc_bbpress_count')) :
1444 function xsc_bbpress_count($count) {
1445 $arg = [
1446 'count_users' => false,
1447 'count_forums' => false,
1448 'count_topics' => false,
1449 'count_private_topics' => false,
1450 'count_spammed_topics' => false,
1451 'count_trashed_topics' => false,
1452 'count_replies' => false,
1453 'count_private_replies' => false,
1454 'count_spammed_replies' => false,
1455 'count_trashed_replies' => false,
1456 'count_tags' => false,
1457 'count_empty_tags' => false,
1458 ];
1459
1460 $arg['count_' . $count] = true;
1461
1462 $counters = bbp_get_statistics($arg);
1463 if($count == 'forums') {
1464 $result = $counters['forum_count'];
1465 } elseif($count == 'topics') {
1466 $result = $counters['topic_count'];
1467 } elseif($count == 'replies') {
1468 $result = $counters['reply_count'];
1469 }
1470
1471 return $result;
1472
1473 }
1474 endif;
1475
1476
1477 if(!function_exists('xsc_remote_get')) :
1478 function xsc_remote_get($url, $json = true, $args = ['timeout' => 18, 'sslverify' => false]) {
1479 $get_request = preg_replace('/\s+/', '', $url);
1480 $get_request = wp_remote_get($url, $args);
1481 $request = wp_remote_retrieve_body($get_request);
1482
1483 if($json) {
1484 $request = @json_decode($request, true);
1485 }
1486
1487 return $request;
1488 }
1489 endif;
1490
1491
1492 if(!function_exists('xs_format_num')) :
1493 function xs_format_num($number) {
1494
1495 if(!is_numeric($number)) {
1496 return $number;
1497 }
1498
1499 global $wp_locale;
1500
1501 $sep = [];
1502 $sep[] = (isset($wp_locale)) ? $wp_locale->number_format['decimal_point'] : '.';
1503 $sep[] = (isset($wp_locale)) ? $wp_locale->number_format['thousands_sep'] : ',';
1504
1505 $number = str_replace($sep, '', $number);
1506
1507 $precision = 1;
1508
1509 if($number < 100) {
1510 // 0 - 900
1511 $n_format = number_format($number, $precision);
1512 $suffix = '';
1513 } else {
1514 if($number < 900000) {
1515 // 0.9k-850k
1516 $n_format = number_format($number / 1000, $precision);
1517 $suffix = 'K';
1518 } else {
1519 if($number < 900000000) {
1520 // 0.9m-850m
1521 $n_format = number_format($number / 1000000, $precision);
1522 $suffix = 'M';
1523 } else {
1524 if($number < 900000000000) {
1525 // 0.9b-850b
1526 $n_format = number_format($number / 1000000000, $precision);
1527 $suffix = 'B';
1528 } else {
1529 // 0.9t+
1530 $n_format = number_format($number / 1000000000000, $precision);
1531 $suffix = 'T';
1532 }
1533 }
1534 }
1535 }
1536
1537 // Remove unecessary zeroes after decimal
1538 $dotzero = '.' . str_repeat('0', $precision);
1539 $n_format = str_replace($dotzero, '', $n_format);
1540
1541 return $n_format . $suffix;
1542 }
1543 endif;
1544