PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 2.2.4
Wp Social Login and Register Social Counter v2.2.4
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 4 years ago instagram-counter.php 5 years ago
counters-api.php
1548 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 $html = xsc_remote_get("https://www.pinterest.com/$username/", false);
1053
1054 $prev = libxml_use_internal_errors(true);
1055 $doc = new DOMDocument();
1056 @$doc->loadHTML($html);
1057 libxml_use_internal_errors($prev);
1058
1059 $metas = $doc->getElementsByTagName('meta');
1060 for($i = 0; $i < $metas->length; $i++) {
1061 $meta = $metas->item($i);
1062 if($meta->getAttribute('name') == 'pinterestapp:followers') {
1063 $result = $meta->getAttribute('content');
1064 break;
1065 }
1066 }
1067 } catch(Exception $e) {
1068 $result = 0;
1069 }
1070
1071 if(!empty($result)) //To update the stored data
1072 {
1073 $xsc_data['pinterest'] = $result;
1074 }
1075
1076 if(empty($result) && !empty($xsc_options['data']['pinterest'])) //Get the stored data
1077 {
1078 $result = $xsc_options['data']['pinterest'];
1079 }
1080 }
1081
1082 return $result;
1083 }
1084 endif;
1085
1086
1087 /**
1088 * Flickr Followers
1089 */
1090 if(!function_exists('xsc_flickr_count')) :
1091 function xsc_flickr_count($cache_time = 3600) {
1092
1093 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1094
1095 if(!empty($xsc_transient['flickr'])) {
1096 $result = $xsc_transient['flickr'];
1097 } elseif(empty($xsc_transient['flickr']) && !empty($xsc_data) && !empty($xsc_options['data']['flickr'])) {
1098 $result = $xsc_options['data']['flickr'];
1099 } else {
1100 $id = $xsc_options_save['social']['flickr']['id'];
1101 $api = $xsc_options_save['social']['flickr']['api'];
1102 try {
1103 $data = @xsc_remote_get("https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=$api&group_id=$id&format=json&nojsoncallback=1");
1104 $result = (int)$data['group']['members']['_content'];
1105 } catch(Exception $e) {
1106 $result = 0;
1107 }
1108
1109 if(!empty($result)) //To update the stored data
1110 {
1111 $xsc_data['flickr'] = $result;
1112 }
1113
1114 if(empty($result) && !empty($xsc_options['data']['flickr'])) //Get the stored data
1115 {
1116 $result = $xsc_options['data']['flickr'];
1117 }
1118 }
1119
1120 return $result;
1121
1122 }
1123 endif;
1124
1125
1126 /**
1127 * Steam Followers
1128 */
1129 if(!function_exists('xsc_steam_count')) :
1130 function xsc_steam_count($cache_time = 3600) {
1131
1132 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1133
1134 if(!empty($xsc_transient['steam'])) {
1135 $result = $xsc_transient['steam'];
1136 } elseif(empty($xsc_transient['steam']) && !empty($xsc_data) && !empty($xsc_options['data']['steam'])) {
1137 $result = $xsc_options['data']['steam'];
1138 } else {
1139 $id = $xsc_options_save['social']['steam']['group'];
1140 try {
1141 $data = @xsc_remote_get("http://steamcommunity.com/groups/$id/memberslistxml?xml=1", false);
1142 $data = @new SimpleXmlElement($data);
1143 $result = (int)$data->groupDetails->memberCount;
1144 } catch(Exception $e) {
1145 $result = 0;
1146 }
1147
1148 if(!empty($result)) //To update the stored data
1149 {
1150 $xsc_data['steam'] = $result;
1151 }
1152
1153 if(empty($result) && !empty($xsc_options['data']['steam'])) //Get the stored data
1154 {
1155 $result = $xsc_options['data']['steam'];
1156 }
1157 }
1158
1159 return $result;
1160 }
1161 endif;
1162
1163
1164 /**
1165 * Rss Subscribers
1166 */
1167 if(!function_exists('xsc_rss_count')) :
1168 function xsc_rss_count($cache_time = 3600) {
1169
1170 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1171
1172 if(!empty($xsc_transient['rss'])) {
1173 $result = $xsc_transient['rss'];
1174 } elseif(empty($xsc_transient['rss']) && !empty($xsc_data) && !empty($xsc_options['data']['rss'])) {
1175 $result = $xsc_options['data']['rss'];
1176 } else {
1177 if(($xsc_options_save['social']['rss']['type'] == 'feedpress.it') && !empty($xsc_options_save['social']['rss']['feedpress'])) {
1178 try {
1179 $feedpress_url = esc_url($xsc_options_save['social']['rss']['feedpress']);
1180 $feedpress_url = str_replace('feedpress.it', 'feed.press', $feedpress_url);
1181 //$feedpress_url = str_replace( 'http', 'https', $feedpress_url);
1182
1183 $data = @xsc_remote_get($feedpress_url);
1184 $result = (int)$data['subscribers'];
1185 } catch(Exception $e) {
1186 $result = 0;
1187 }
1188 } elseif(($xsc_options_save['social']['rss']['type'] == 'Manual') && !empty($xsc_options_save['social']['rss']['manual'])) {
1189 $result = $xsc_options_save['social']['rss']['manual'];
1190 } else {
1191 $result = 0;
1192 }
1193 if(!empty($result)) //To update the stored data
1194 {
1195 $xsc_data['rss'] = $result;
1196 }
1197
1198 if(empty($result) && !empty($xsc_options['data']['rss'])) //Get the stored data
1199 {
1200 $result = $xsc_options['data']['rss'];
1201 }
1202 }
1203
1204 return $result;
1205
1206 }
1207 endif;
1208
1209
1210 /*
1211 * Spotify Followers
1212 */
1213 if(!function_exists('xsc_spotify_count')) :
1214 function xsc_spotify_count($cache_time = 3600) {
1215
1216 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1217
1218 if(!empty($xsc_transient['spotify'])) {
1219 $result = $xsc_transient['spotify'];
1220 } elseif(empty($xsc_transient['spotify']) && !empty($xsc_data) && !empty($xsc_options['data']['spotify'])) {
1221 $result = $xsc_options['data']['spotify'];
1222 } else {
1223 $id = $url = $xsc_options_save['social']['spotify']['id'];
1224 $id = rtrim($id, "/");
1225 $id = urlencode(str_replace([
1226 'https://play.spotify.com/',
1227 'https://player.spotify.com/',
1228 'artist/',
1229 'user/',
1230 ], '', $id));
1231
1232 try {
1233 if(!empty($url) && strpos($url, 'artist') !== false) {
1234 $data = @xsc_remote_get("https://api.spotify.com/v1/artists/$id");
1235 } else {
1236 $data = @xsc_remote_get("https://api.spotify.com/v1/users/$id");
1237 }
1238 $result = (int)$data['followers']['total'];
1239
1240 } catch(Exception $e) {
1241 $result = 0;
1242 }
1243
1244 if(!empty($result)) //To update the stored data
1245 {
1246 $xsc_data['spotify'] = $result;
1247 }
1248
1249 if(empty($result) && !empty($xsc_options['data']['spotify'])) //Get the stored data
1250 {
1251 $result = $xsc_options['data']['spotify'];
1252 }
1253 }
1254
1255 return $result;
1256
1257 }
1258 endif;
1259
1260
1261 /**
1262 * Goodreads Followers
1263 */
1264 if(!function_exists('xsc_goodreads_count')) :
1265 function xsc_goodreads_count($cache_time = 3600) {
1266
1267 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1268
1269 if(!empty($xsc_transient['goodreads'])) {
1270 $result = $xsc_transient['goodreads'];
1271 } elseif(empty($xsc_transient['goodreads']) && !empty($xsc_data) && !empty($xsc_options['data']['goodreads'])) {
1272 $result = $xsc_options['data']['goodreads'];
1273 } else {
1274 $id = $url = $xsc_options_save['social']['goodreads']['id'];
1275 $key = $xsc_options_save['social']['goodreads']['key'];
1276
1277 $id = rtrim($id, "/");
1278 $id = @parse_url($id);
1279 $id = $id['path'];
1280 $id = str_replace(['/user/show/', '/author/show/'], '', $id);
1281 if(strpos($id, '-') !== false) {
1282 $id = explode('-', $id);
1283 } else {
1284 $id = explode('.', $id);
1285 }
1286 $id = $id[0];
1287 try {
1288 if(!empty($url) && strpos($url, 'author') !== false) {
1289 $data = @xsc_remote_get("https://www.goodreads.com/author/show/$id.xml?key=$key", false);
1290 $data = @new SimpleXmlElement($data);
1291 $result = (int)$data->author->author_followers_count;
1292 } else {
1293 $data = @xsc_remote_get("https://www.goodreads.com/user/show/$id.xml?key=$key", false);
1294 $data = @new SimpleXmlElement($data);
1295 $result = (int)$data->user->friends_count;
1296 }
1297
1298 } catch(Exception $e) {
1299 $result = 0;
1300 }
1301
1302 if(!empty($result)) //To update the stored data
1303 {
1304 $xsc_data['goodreads'] = $result;
1305 }
1306
1307 if(empty($result) && !empty($xsc_options['data']['goodreads'])) //Get the stored data
1308 {
1309 $result = $xsc_options['data']['goodreads'];
1310 }
1311 }
1312
1313 return $result;
1314
1315 }
1316 endif;
1317
1318
1319 /**
1320 * Twitch Followers
1321 */
1322 if(!function_exists('xsc_twitch_count')) :
1323 function xsc_twitch_count($cache_time = 3600) {
1324
1325 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1326
1327 if(!empty($xsc_transient['twitch'])) {
1328 $result = $xsc_transient['twitch'];
1329 } elseif(empty($xsc_transient['twitch']) && !empty($xsc_data) && !empty($xsc_options['data']['twitch'])) {
1330 $result = $xsc_options['data']['twitch'];
1331 } else {
1332 $id = $xsc_options_save['social']['twitch']['id'];
1333 $api = get_option('twitch_access_token');
1334
1335 try {
1336 $data = @xsc_remote_get("https://api.twitch.tv/kraken/channels/$id?oauth_token=$api");
1337
1338 $result = (int)$data['followers'];
1339 } catch(Exception $e) {
1340 $result = 0;
1341 }
1342
1343 if(!empty($result)) //To update the stored data
1344 {
1345 $xsc_data['twitch'] = $result;
1346 }
1347
1348 if(empty($result) && !empty($xsc_options['data']['twitch'])) //Get the stored data
1349 {
1350 $result = $xsc_options['data']['twitch'];
1351 }
1352 }
1353
1354 return $result;
1355
1356 }
1357 endif;
1358
1359
1360 /**
1361 * Mixcloud Followers
1362 */
1363 if(!function_exists('xsc_mixcloud_count')) :
1364 function xsc_mixcloud_count($cache_time = 3600) {
1365
1366 global $xsc_data, $xsc_options, $xsc_transient, $xsc_options_save;
1367
1368 if(!empty($xsc_transient['mixcloud'])) {
1369 $result = $xsc_transient['mixcloud'];
1370 } elseif(empty($xsc_transient['mixcloud']) && !empty($xsc_data) && !empty($xsc_options['data']['mixcloud'])) {
1371 $result = $xsc_options['data']['mixcloud'];
1372 } else {
1373 $id = $xsc_options_save['social']['mixcloud']['id'];
1374 try {
1375 $data = @xsc_remote_get("http://api.mixcloud.com/$id/");
1376 $result = (int)$data['follower_count'];
1377 } catch(Exception $e) {
1378 $result = 0;
1379 }
1380
1381 if(!empty($result)) //To update the stored data
1382 {
1383 $xsc_data['mixcloud'] = $result;
1384 }
1385
1386 if(empty($result) && !empty($xsc_options['data']['mixcloud'])) //Get the stored data
1387 {
1388 $result = $xsc_options['data']['mixcloud'];
1389 }
1390 }
1391
1392 return $result;
1393
1394 }
1395 endif;
1396
1397
1398 /**
1399 * Posts Number
1400 */
1401 if(!function_exists('xsc_posts_count')) :
1402 function xsc_posts_count($cache_time = 3600) {
1403 $count_posts = wp_count_posts();
1404
1405 return $result = $count_posts->publish;
1406 }
1407 endif;
1408
1409
1410 /**
1411 * Comments number
1412 */
1413 if(!function_exists('xsc_comments_count')) :
1414 function xsc_comments_count($cache_time = 3600) {
1415 $comments_count = wp_count_comments();
1416
1417 return $result = $comments_count->approved;
1418 }
1419 endif;
1420
1421
1422 /**
1423 * Members number
1424 */
1425 if(!function_exists('xsc_members_count')) :
1426 function xsc_members_count($cache_time = 3600) {
1427 $members_count = count_users();
1428
1429 return $result = $members_count['total_users'];
1430 }
1431 endif;
1432
1433
1434 /**
1435 * Groups number
1436 */
1437 if(!function_exists('xsc_groups_count')) :
1438 function xsc_groups_count($cache_time = 3600) {
1439 return $result = groups_get_total_group_count();
1440 }
1441 endif;
1442
1443
1444 /**
1445 * bbPress Counters
1446 */
1447 if(!function_exists('xsc_bbpress_count')) :
1448 function xsc_bbpress_count($count) {
1449 $arg = [
1450 'count_users' => false,
1451 'count_forums' => false,
1452 'count_topics' => false,
1453 'count_private_topics' => false,
1454 'count_spammed_topics' => false,
1455 'count_trashed_topics' => false,
1456 'count_replies' => false,
1457 'count_private_replies' => false,
1458 'count_spammed_replies' => false,
1459 'count_trashed_replies' => false,
1460 'count_tags' => false,
1461 'count_empty_tags' => false,
1462 ];
1463
1464 $arg['count_' . $count] = true;
1465
1466 $counters = bbp_get_statistics($arg);
1467 if($count == 'forums') {
1468 $result = $counters['forum_count'];
1469 } elseif($count == 'topics') {
1470 $result = $counters['topic_count'];
1471 } elseif($count == 'replies') {
1472 $result = $counters['reply_count'];
1473 }
1474
1475 return $result;
1476
1477 }
1478 endif;
1479
1480
1481 if(!function_exists('xsc_remote_get')) :
1482 function xsc_remote_get($url, $json = true, $args = ['timeout' => 18, 'sslverify' => false]) {
1483 $get_request = preg_replace('/\s+/', '', $url);
1484 $get_request = wp_remote_get($url, $args);
1485 $request = wp_remote_retrieve_body($get_request);
1486
1487 if($json) {
1488 $request = @json_decode($request, true);
1489 }
1490
1491 return $request;
1492 }
1493 endif;
1494
1495
1496 if(!function_exists('xs_format_num')) :
1497 function xs_format_num($number) {
1498
1499 if(!is_numeric($number)) {
1500 return $number;
1501 }
1502
1503 global $wp_locale;
1504
1505 $sep = [];
1506 $sep[] = (isset($wp_locale)) ? $wp_locale->number_format['decimal_point'] : '.';
1507 $sep[] = (isset($wp_locale)) ? $wp_locale->number_format['thousands_sep'] : ',';
1508
1509 $number = str_replace($sep, '', $number);
1510
1511 $precision = 1;
1512
1513 if($number < 100) {
1514 // 0 - 900
1515 $n_format = number_format($number, $precision);
1516 $suffix = '';
1517 } else {
1518 if($number < 900000) {
1519 // 0.9k-850k
1520 $n_format = number_format($number / 1000, $precision);
1521 $suffix = 'K';
1522 } else {
1523 if($number < 900000000) {
1524 // 0.9m-850m
1525 $n_format = number_format($number / 1000000, $precision);
1526 $suffix = 'M';
1527 } else {
1528 if($number < 900000000000) {
1529 // 0.9b-850b
1530 $n_format = number_format($number / 1000000000, $precision);
1531 $suffix = 'B';
1532 } else {
1533 // 0.9t+
1534 $n_format = number_format($number / 1000000000000, $precision);
1535 $suffix = 'T';
1536 }
1537 }
1538 }
1539 }
1540
1541 // Remove unecessary zeroes after decimal
1542 $dotzero = '.' . str_repeat('0', $precision);
1543 $n_format = str_replace($dotzero, '', $n_format);
1544
1545 return $n_format . $suffix;
1546 }
1547 endif;
1548