PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / trunk
Wp Social Login and Register Social Counter vtrunk
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 / instagram-counter.php
wp-social / lib / counter Last commit date
counters-api.php 2 years ago instagram-counter.php 5 years ago
instagram-counter.php
136 lines
1 <?php
2
3 namespace WP_Social\Lib\Counter;
4
5
6 class Instagram_Counter {
7
8 public $enabled = false;
9
10 /**
11 * If user id is empty then expired is false
12 * if transient time is less than time then it is true
13 *
14 * @var bool
15 */
16 public $cache_expired = false;
17
18 public $user_id = '';
19
20 private $debug = '';
21
22
23 public function load() {
24
25 $opt = get_option('xs_counter_providers_data', []);
26
27 if(!empty($opt['social']['instagram']['enable'])) {
28
29 $this->enabled = true;
30
31 if(!empty($opt['social']['instagram']['id'])) {
32
33 $this->user_id = $opt['social']['instagram']['id'];
34
35 $get_transient_time = get_transient(self::get_transient_timeout_key());
36
37 $this->cache_expired = $get_transient_time < time();
38 }
39
40 /**
41 * Also set the def value and label and etc etc, if needed
42 */
43 }
44 }
45
46
47
48 public static function get_last_cache_key() {
49
50 return '_xs_social_instagram_last_cached';
51 }
52
53 public static function get_transient_key() {
54
55 return '_xs_social_instagram_count_';
56 }
57
58
59 public static function get_transient_timeout_key() {
60
61 return 'timeout_' . self::get_transient_key();
62 }
63
64
65 public static function is_expired() {
66
67 $opt = get_option('xs_counter_providers_data', []);
68
69
70 $get_transient_time = get_transient(self::get_transient_timeout_key());
71
72 return $get_transient_time < time();
73 }
74
75
76 public static function get_user_id() {
77
78 $xsc_options_save = get_option('xs_counter_providers_data', []);
79
80 return empty($xsc_options_save['social']['instagram']['id']) ? '' : $xsc_options_save['social']['instagram']['id'];
81 }
82
83
84 /**
85 *
86 * @param $count
87 * @param int $expire - we will cache this for given amount of second
88 *
89 * @return bool
90 */
91 public function cache_instagram_return($count, $expire = 86400) {
92
93 $tran_key = self::get_transient_key();
94
95 $conf['followed_by'] = $count;
96 $conf['fetch_time'] = time();
97
98
99 /**
100 * If every thing goes okay
101 */
102 set_transient($tran_key, $conf, $expire);
103
104 update_option(self::get_last_cache_key(), $count);
105
106 return true;
107 }
108
109
110 function get_count($user_id) {
111
112 $url = 'https://www.instagram.com/' . $user_id . '/?__a=1';
113
114 try {
115 $request = wp_remote_get($url);
116
117 if(!is_wp_error($request)) {
118
119 $body = wp_remote_retrieve_body($request);
120 $dt = json_decode($body);
121 }
122
123 } catch(\Exception $ex) {
124
125 }
126 }
127
128
129 /**
130 * @return string
131 */
132 public function getDebug() {
133 return $this->debug;
134 }
135
136 }