PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 3.2.1
Wp Social Login and Register Social Counter v3.2.1
3.2.1 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 / provider / counter / instagram-counter.php
wp-social / lib / provider / counter Last commit date
comments-counter.php 5 years ago counter-interface.php 5 years ago counter.php 5 years ago dribbble-counter.php 5 years ago facebook-counter.php 3 years ago instagram-counter.php 10 months ago no-provider-counter.php 5 years ago pinterest-counter.php 2 years ago posts-counter.php 5 years ago tiktok-counter.php 1 week ago twitter-counter.php 1 year ago youtube-counter.php 5 years ago
instagram-counter.php
127 lines
1 <?php
2
3 namespace WP_Social\Lib\Provider\Counter;
4
5 class Instagram_Counter extends Counter {
6
7 public static $provider_key = 'instagram';
8
9 private $global_options;
10
11
12 public function need_to_call_legacy_function() {
13
14 return false;
15 }
16
17
18 public static function get_transient_key() {
19
20 return '_xs_social_instagram_count_';
21 }
22
23
24 public static function get_transient_timeout_key() {
25
26 return 'timeout_' . self::get_transient_key();
27 }
28
29
30 public static function get_last_cache_key() {
31
32 return '_xs_social_'.self::$provider_key.'_last_cached';
33 }
34
35
36 public function set_config_data($conf_array) {
37
38 $this->global_options = $conf_array;
39
40 return $this;
41 }
42
43 public function get_cached_count() {
44
45 return $this->get_count($this->cache_time);
46 }
47
48 /**
49 * todo - move it to parent class and make it available for all
50 *
51 */
52 public function get_default_fan_count() {
53
54 return empty($this->global_options['data']['value']) ? 0 : $this->global_options['data']['value'];
55 }
56
57 public function get_count($global_cache_time = 43200) {
58
59 if(empty($this->global_options['access_token']) || empty($this->global_options['user_id'])) {
60
61 /**
62 * Client does not set up his access token, so just show defaults value
63 */
64
65 return empty($this->global_options['data']['value']) ? 0 : $this->global_options['data']['value'];
66 }
67
68
69 /**
70 * At this point client has set up his credentials and want to grab show actual values
71 *
72 */
73 $tran_key = self::get_transient_key();
74 $trans_value = get_transient($tran_key);
75
76 if(false === $trans_value) {
77
78 $access_token = $this->global_options['access_token'];
79 $user_id = $this->global_options['user_id'];
80
81 $url = "https://graph.instagram.com/$user_id?fields=username,followers_count&access_token=$access_token";
82 try {
83
84 $get_request = wp_remote_get($url, array('timeout' => 40, 'sslverify' => false,));
85 if(is_wp_error($get_request)) {
86
87 $result = -1;
88
89 } else {
90
91 $body = wp_remote_retrieve_body($get_request);
92 $dt = json_decode($body);
93
94 /**
95 * todo - this is a temporary fix for immediate release
96 */
97 if(!empty($dt->error)) {
98
99 $result = $this->get_default_fan_count();
100
101 } else {
102 $result = empty($dt->followers_count) ? 0 : intval($dt->followers_count);
103 }
104 }
105
106 $expiration_time = empty($global_cache_time) ? 43200: intval($global_cache_time);
107
108 set_transient($tran_key, $result, $expiration_time);
109 update_option(self::get_last_cache_key(), time());
110
111 } catch(\Exception $e) {
112
113 /**
114 * todo - AR; need to get confirmation what should we do in case there are errors from Product Owner
115 * for now returning 0;
116 *
117 */
118 $result = 0;
119 }
120
121 return $result;
122 }
123
124 return $trans_value;
125 }
126 }
127