PluginProbe
Countdown Timer Block – build urgency for events and launches / 1.2.2
Countdown Timer Block – build urgency for events and launches v1.2.2
1.3.3 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 32 releases
countdown-time / bplugins_sdk / inc / Base / Freemius_Lite.php

Freemius_Lite.php in Countdown Timer Block – build urgency for events and launches 1.2.2, at bplugins_sdk/inc/Base/Freemius_Lite.php

142 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!class_exists('Freemius_Lite')){
4 class Freemius_Lite {
5 protected $api_endpoint = 'https://api.bplugins.com/wp-json/freemius/v1/middleware/timde';
6 // protected $api_endpoint = 'http://localhost/freemius/wp-json/freemius/v1/middleware/time';
7 public $api = null;
8 protected $_scope = null;
9 public $headers = [];
10 function __construct($scope = null, $id = null, $public_key = null, $secret_key = null){
11 if($scope && $id && $public_key){
12 $this->headers = $this->generate_authorization_header('', $scope, $id, $public_key, $secret_key);
13 }
14 }
15
16 public function get_site(){
17 $result = $this->FS_Api('?sdk_version=2.5.12&fields=site_id,plugin_id,user_id,title,url,version,language,platform_version,sdk_version,programming_language_version,plan_id,license_id,trial_plan_id,trial_ends,is_premium,is_disconnected,is_active,is_uninstalled,is_beta,public_key,secret_key,id,updated,created,_is_updated');
18
19 if(!$result->success){
20 return false;
21 }
22 return $result->data;
23 }
24
25 public function plugin_deactivated($path,$uid){
26 return $this->FS_Api($path, 'PUT', wp_json_encode([
27 'is_active' => false,
28 'uid' => $uid
29 ]));
30 }
31
32 public function plugin_uninstall($path,$uid){
33 return $this->FS_Api($path, 'PUT', wp_json_encode([
34 'is_active' => false,
35 'is_uninstalled' => true,
36 'uid' => $uid
37 ]));
38 }
39
40 public function plugin_activated($path, $uid, $version){
41 $user = wp_get_current_user();
42 global $wp_version;
43 return $this->FS_Api($path, 'PUT', wp_json_encode([
44 "sdk_version" => "2.5.12",
45 "platform_version" => $wp_version,
46 "programming_language_version" => phpversion(),
47 "url" => site_url(),
48 "language" => "en-US",
49 "title" => get_bloginfo('name'),
50 "version" => $version,
51 "is_premium" => false,
52 "is_active" => true,
53 "is_uninstalled" => false,
54 "uid" => $uid,
55 ]));
56 }
57
58 public function Api($method = 'GET', $params = [], $headers = []){
59 try {
60 $response = wp_remote_request($this->api_endpoint, [
61 'method' => $method,
62 'headers' => $headers,
63 'body' => $params
64 ]);
65 $body = json_decode(wp_remote_retrieve_body($response));
66 return $body;
67 } catch (\Throwable $th) {
68 throw new Exception('Something went wrong!');
69 }
70 }
71
72 public function FS_Api($path = '', $method="GET", $params = []){
73 $this->headers['path'] = $path;
74 $result = $this->Api($method, $params, $this->headers );
75 return $result;
76 }
77
78 function permission_update($fs_accounts, $config, $params = null){
79 $site = isset($fs_accounts['sites'][$config->slug]) && $fs_accounts['sites'][$config->slug] ? (object) $fs_accounts['sites'][$config->slug] : null;
80 // return $fs_accounts;
81 if(!is_object($site) || gettype($site->public_key) === NULL || $params === null || $site === null) {
82 $fs_accounts['plugin_data'][$config->slug]['is_anonymous'] = [
83 'is' => true,
84 'timestamp' => time()
85 ];
86 update_option('fs_accounts', $fs_accounts);
87 return false;
88 }
89
90 if(!$site->public_key || !$site->secret_key || !$site->install_id) {
91 return false;
92 }
93
94 $headers = $this->generate_authorization_header('/permissions.json?sdk_version=2.5.12&url='.site_url(), 'install', $site->install_id, $site->public_key, $site->secret_key);
95
96 $result = $this->_permission_update($params, $headers);
97
98 if( isset($result->data->error) || (isset($result->data->code) && ($result->data->code === 'rest_invalid_json' || $result->data->code === 'unauthorized_access'))){
99 return [
100 'success' => false,
101 'message' => isset($result->data->message) ? $result->data->message : 'error line 96'
102 ];
103 }
104
105 if(isset($result->data->permissions)){
106 $fs_accounts['plugin_data'][$config->slug]['is_user_tracking_allowed'] = $result->data->permissions->user;
107 $fs_accounts['plugin_data'][$config->slug]['is_site_tracking_allowed'] = $result->data->permissions->site;
108 $fs_accounts['plugin_data'][$config->slug]['is_events_tracking_allowed'] = $result->data->permissions->site;
109 $fs_accounts['plugin_data'][$config->slug]['is_extensions_tracking_allowed'] = $result->data->permissions->extensions;
110 update_option('fs_accounts', $fs_accounts);
111 return [
112 'success' => true,
113 'data' => $result
114 ];
115 }
116
117 return false;
118 }
119
120 function _permission_update($params, $headers){
121 $result = $this->Api('PUT', wp_json_encode($params), $headers);
122 return $result;
123 }
124
125 private function generate_authorization_header($path, $scope, $id, $public_key, $secret_key) {
126 $headers = array(
127 'path' => $path,
128 'scope' => $scope,
129 'id' => $id,
130 'public-key' => $public_key,
131 'secret-key' => $secret_key,
132 'Content-Type' => 'application/json'
133 );
134 return $headers;
135 }
136
137 }
138
139 }
140
141
142