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 / 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 4 years ago no-provider-counter.php 5 years ago pinterest-counter.php 5 years ago posts-counter.php 5 years ago twitter-counter.php 5 years ago youtube-counter.php 5 years ago
instagram-counter.php
131 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_name']) || 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 $username = $this->global_options['user_name'];
81
82 $url='https://graph.facebook.com/v11.0/'.$user_id.'?fields=business_discovery.username('.$username.'){username,follows_count,followers_count}&access_token=' . $access_token .'';
83
84 try {
85
86 $get_request = wp_remote_get($url, array('timeout' => 40, 'sslverify' => false,));
87
88 if(is_wp_error($get_request)) {
89
90 $result = -1;
91
92 } else {
93
94 $body = wp_remote_retrieve_body($get_request);
95 $dt = json_decode($body);
96
97 /**
98 * todo - this is a temporary fix for immediate release
99 */
100 if(!empty($dt->error)) {
101
102 $result = $this->get_default_fan_count();
103
104 } else {
105
106 $result = empty($dt['business_discovery']['followers_count']) ? 0 : intval($dt['business_discovery']['followers_count']);
107 }
108 }
109
110 $expiration_time = empty($global_cache_time) ? 43200: intval($global_cache_time);
111
112 set_transient($tran_key, $result, $expiration_time);
113 update_option(self::get_last_cache_key(), time());
114
115 } catch(Exception $e) {
116
117 /**
118 * todo - AR; need to get confirmation what should we do in case there are errors from Product Owner
119 * for now returning 0;
120 *
121 */
122 $result = 0;
123 }
124
125 return $result;
126 }
127
128 return $trans_value;
129 }
130 }
131