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 / tiktok-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 2 weeks ago twitter-counter.php 1 year ago youtube-counter.php 5 years ago
tiktok-counter.php
138 lines
1 <?php
2
3 namespace WP_Social\Lib\Provider\Counter;
4
5 require_once( WSLU_LOGIN_PLUGIN . 'lib/composer/vendor/autoload.php' );
6
7 use TikTok\User\User;
8 use TikTok\Request\Params;
9
10 class Tiktok_Counter extends Counter {
11
12 public static $provider_key = 'tiktok';
13 private $global_options;
14
15 /**
16 * If we need to call legacy function
17 *
18 * @return bool
19 */
20 public function need_to_call_legacy_function() {
21
22 return false;
23 }
24
25 /**
26 * Get transient key
27 *
28 * @return string
29 */
30 public static function get_transient_key() {
31
32 return '_xs_social_tiktok_count_';
33 }
34
35 /**
36 * Get transient timeout key
37 *
38 * @return string
39 */
40 public static function get_transient_timeout_key() {
41
42 return 'timeout_' . self::get_transient_key();
43 }
44
45 /**
46 * Get last cache key
47 *
48 * @return string
49 */
50 public static function get_last_cache_key() {
51
52 return '_xs_social_'.self::$provider_key.'_last_cached';
53 }
54
55 /**
56 * Set config data
57 *
58 * @param array $conf_array
59 *
60 * @return $this
61 */
62 public function set_config_data( $conf_array ) {
63
64 $this->global_options = $conf_array;
65
66 return $this;
67 }
68
69 /**
70 * Get cached count
71 *
72 * @return int
73 */
74 public function get_cached_count() {
75
76 return $this->get_count( $this->cache_time );
77 }
78
79 /**
80 * Get default count
81 *
82 * @return int
83 */
84 public function get_default_fan_count() {
85
86 return empty($this->global_options['data']['value']) ? 0 : $this->global_options['data']['value'];
87 }
88
89 /**
90 * Get follwers count from API
91 *
92 * @param int $global_cache_time
93 *
94 * @return int
95 */
96 public function get_count( $global_cache_time = 43200 ) {
97
98 if( empty( $this->global_options['api'] ) ) {
99
100 // Client does not set up his credential, so just show defaults value
101 return empty($this->global_options['data']['value']) ? 0 : $this->global_options['data']['value'];
102 }
103
104 $access_token = isset( $this->global_options['api'] ) ? $this->global_options['api'] : '';
105 $tran_key = self::get_transient_key( md5( $access_token ) );
106 $trans_value = get_transient( $tran_key );
107
108 if( false === $trans_value ) {
109
110 $config = array( // instantiation config params
111 'access_token' => $access_token
112 );
113
114 // instantiate the user
115 $user = new User( $config );
116
117 $params = Params::getFieldsParam(
118 array(
119 'follower_count', // scope user.info.stats
120 )
121 );
122
123 // get user info
124 $userInfo = $user->getSelf( $params );
125 $followers_count = isset($userInfo['data']['user']['follower_count']) ? $userInfo['data']['user']['follower_count'] : 0;
126
127 //Updating transient cache
128 $expiration_time = empty( $global_cache_time ) ? 43200: intval( $global_cache_time );
129
130 set_transient( $tran_key, $followers_count, $expiration_time );
131 update_option( self::get_last_cache_key(), time() );
132
133 }
134
135 return $trans_value;
136 }
137 }
138