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
dribbble-counter.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Lib\Provider\Counter; |
| 4 | |
| 5 | |
| 6 | class Dribbble_Counter extends Counter { |
| 7 | |
| 8 | public static $provider_key = 'dribbble'; |
| 9 | |
| 10 | private $global_options; |
| 11 | |
| 12 | public function need_to_call_legacy_function() { |
| 13 | |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | public static function get_transient_key($user = '') { |
| 18 | |
| 19 | return '_xs_social_'.self::$provider_key.'_count_'; |
| 20 | } |
| 21 | |
| 22 | |
| 23 | public static function get_transient_timeout_key() { |
| 24 | |
| 25 | return 'timeout_' . self::get_transient_key(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | public static function get_last_cache_key() { |
| 30 | |
| 31 | return '_xs_social_'.self::$provider_key.'_last_cached'; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | public function set_config_data($conf_array) { |
| 36 | |
| 37 | $this->global_options = $conf_array; |
| 38 | |
| 39 | return $this; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @param int $global_cache_time - default is 12 hours |
| 46 | * @return mixed |
| 47 | */ |
| 48 | public function get_count($global_cache_time = 43200) { |
| 49 | |
| 50 | if(empty($this->global_options['api'])) { |
| 51 | |
| 52 | /** |
| 53 | * Client does not set up his credential, so just show defaults value |
| 54 | */ |
| 55 | |
| 56 | return empty($this->global_options['data']['value']) ? 0 : $this->global_options['data']['value']; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * At this point client has set up his credentials and want to grab show actual values |
| 61 | * |
| 62 | */ |
| 63 | $tran_key = self::get_transient_key(); |
| 64 | $trans_value = get_transient($tran_key); |
| 65 | |
| 66 | |
| 67 | if(false === $trans_value) { |
| 68 | |
| 69 | try { |
| 70 | |
| 71 | $token = get_option('xs_counter_dribbble_token', '') ; |
| 72 | |
| 73 | $data = xsc_remote_get('https://api.dribbble.com/v2/user?access_token='.$token); |
| 74 | |
| 75 | $result = isset($data['followers_count']) ? intval($data['followers_count']) : 0; |
| 76 | |
| 77 | $home_url = isset($data['html_url']) ? $data['html_url'] : 'https://dribbble.com/'; |
| 78 | |
| 79 | $expiration_time = empty($global_cache_time) ? 43200: intval($global_cache_time); |
| 80 | |
| 81 | set_transient($tran_key, $result, $expiration_time); |
| 82 | update_option('home_url_dribbble_count', $home_url); |
| 83 | update_option(self::get_last_cache_key(), time()); |
| 84 | |
| 85 | } catch(Exception $e) { |
| 86 | |
| 87 | /** |
| 88 | * todo - AR; need to get confirmation what should we do in case there are errors from Product Owner |
| 89 | * for now returning 0; |
| 90 | * |
| 91 | */ |
| 92 | $result = 0; |
| 93 | } |
| 94 | |
| 95 | return $result; |
| 96 | } |
| 97 | |
| 98 | return $trans_value; |
| 99 | } |
| 100 | } |