Sidekick - Version 2.6.6

Version Description

  • Fixes notice error in multisite management page
Download this release

Release Info

Developer raptor235
Plugin Icon 128x128 Sidekick
Version 2.6.6
Comparing to
See all releases

Code changes from version 2.6.5 to 2.6.6

Files changed (5) hide show
  1. js/sidekick_admin.js +12 -4
  2. libs/licensing.php +59 -207
  3. libs/sk_api.php +195 -0
  4. readme.txt +5 -2
  5. sidekick.php +4 -4
js/sidekick_admin.js CHANGED
@@ -24,13 +24,13 @@ function updateCounts(e){
24
  function setup_buttons_deactivate(){
25
  jQuery('.site button.deactivate').off('click').click(function(){
26
 
27
- var data = {
28
  action: 'sk_deactivate_single',
29
  blog_id: jQuery(this).parent().data('blogid'),
30
  user_id: jQuery(this).parent().data('userid'),
31
  domain: jQuery(this).parent().data('domain'),
32
  path: jQuery(this).parent().data('path')
33
- };
34
 
35
  jQuery(this).html('Deactivating...');
36
  jQuery('.single_activation_error').html('').hide();
@@ -168,7 +168,7 @@ function setup_buttons_activate(){
168
  data.action = 'sk_deactivate_single';
169
  jQuery(this).html('Deactivating...');
170
  } else {
171
- jQuery(this).html('Activating...');
172
  }
173
 
174
 
@@ -294,7 +294,7 @@ function drawBuckets(cacheId,data,bucket,key,productWalkthroughs){
294
 
295
  function drawWalkthrough(walkthrough,bucket_id){
296
 
297
- // console.log('drawWalkthrough %o', arguments);
298
 
299
 
300
  var pass = false;
@@ -313,6 +313,11 @@ function drawWalkthrough(walkthrough,bucket_id){
313
  var checked = false;
314
  var selected = false;
315
 
 
 
 
 
 
316
  if (jQuery.inArray(parseInt(walkthrough.id,10),currently_disabled_wts) > -1 || jQuery.inArray(parseInt(walkthrough.id,10),currently_disabled_network_wts) > -1) {
317
  checked = 'CHECKED';
318
  }
@@ -321,6 +326,9 @@ function drawWalkthrough(walkthrough,bucket_id){
321
  selected = 'SELECTED';
322
  }
323
 
 
 
 
324
  jQuery('#sk_bucket_' + bucket_id).find('ul').append('<li class="sk_walkthrough"><span><input type="checkbox" ' + checked + ' value=\'' + walkthrough.id + '\' name=\'disable_wts[]\'></span><span class=\'title\'>' + walkthrough.title + '</span></li>');
325
  jQuery('[name="sk_autostart_walkthrough_id"]').append('<option ' + selected + ' value="' + walkthrough.id + '">' + walkthrough.title + '</option>');
326
 
24
  function setup_buttons_deactivate(){
25
  jQuery('.site button.deactivate').off('click').click(function(){
26
 
27
+ var data = {
28
  action: 'sk_deactivate_single',
29
  blog_id: jQuery(this).parent().data('blogid'),
30
  user_id: jQuery(this).parent().data('userid'),
31
  domain: jQuery(this).parent().data('domain'),
32
  path: jQuery(this).parent().data('path')
33
+ };
34
 
35
  jQuery(this).html('Deactivating...');
36
  jQuery('.single_activation_error').html('').hide();
168
  data.action = 'sk_deactivate_single';
169
  jQuery(this).html('Deactivating...');
170
  } else {
171
+ jQuery(this).html('Activating...');
172
  }
173
 
174
 
294
 
295
  function drawWalkthrough(walkthrough,bucket_id){
296
 
297
+ console.log('drawWalkthrough %o', arguments);
298
 
299
 
300
  var pass = false;
313
  var checked = false;
314
  var selected = false;
315
 
316
+ console.log('sk_config.autostart_walkthrough_id %o', sk_config.autostart_walkthrough_id);
317
+
318
+ console.log('walkthrough.id %o', walkthrough.id);
319
+
320
+
321
  if (jQuery.inArray(parseInt(walkthrough.id,10),currently_disabled_wts) > -1 || jQuery.inArray(parseInt(walkthrough.id,10),currently_disabled_network_wts) > -1) {
322
  checked = 'CHECKED';
323
  }
326
  selected = 'SELECTED';
327
  }
328
 
329
+ console.log('selected %o', selected);
330
+
331
+
332
  jQuery('#sk_bucket_' + bucket_id).find('ul').append('<li class="sk_walkthrough"><span><input type="checkbox" ' + checked + ' value=\'' + walkthrough.id + '\' name=\'disable_wts[]\'></span><span class=\'title\'>' + walkthrough.title + '</span></li>');
333
  jQuery('[name="sk_autostart_walkthrough_id"]').append('<option ' + selected + ' value="' + walkthrough.id + '">' + walkthrough.title + '</option>');
334
 
libs/licensing.php CHANGED
@@ -4,34 +4,28 @@
4
 
5
  if (!class_exists('sidekickMassActivator')) {
6
 
7
- class sidekickMassActivator {
 
 
8
 
9
  var $sites_per_page = 50;
10
  var $offet = 0;
11
 
 
 
 
 
 
12
  function activate($blog_id, $user_id, $domain, $path) {
13
  // mlog("FUNCTION: activate [$blog_id, $user_id, $domain, $path]");
14
 
15
- switch_to_blog($blog_id);
16
- $sk_activation_id = get_option('sk_activation_id');
17
- restore_current_blog();
18
-
19
- if ($sk_activation_id) {
20
- $result = array(
21
- "payload" => array(
22
- "blog" => $blog[0],
23
- "message" => "Already Activated",
24
- ),
25
- );
26
-
27
- return json_encode($result);
28
- }
29
 
30
  $email = '';
31
 
32
  if ($user_id) {
33
- $user = get_user_by('id', $user_id);
34
- $email = ($user) ? $user->user_email : 'unknown';
35
  }
36
  $sk_subscription_id = get_option("sk_subscription_id");
37
  $sk_selected_library = get_option("sk_selected_library");
@@ -42,38 +36,50 @@ if (!class_exists('sidekickMassActivator')) {
42
  $data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
43
  } else {
44
  update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
45
-
46
-
47
  return false;
48
  }
49
 
50
  $result = $this->send_request('post', '/domains', $data);
51
 
52
  if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
 
 
 
 
 
 
53
 
54
- $this->setup_super_admin_key($result->payload->domainKey);
 
55
 
56
- switch_to_blog($blog_id);
57
- update_option('sk_activation_id', $result->payload->domainKey);
58
- update_option('sk_email', $email);
59
- restore_current_blog();
60
-
61
- update_option('sk_last_setup_blog_id', $blog_id);
62
 
63
- delete_option('sk_auto_activation_error');
64
- } else {
65
 
66
- update_option('sk_auto_activation_error', $result->message);
67
- // wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
68
- wp_mail('bart@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
69
- }
70
 
71
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
72
 
 
 
 
73
  }
74
 
75
  function deactivate($blog_id) {
76
- // mlog("FUNCTION: deactivate [$blog_id]");
 
77
 
78
  switch_to_blog($blog_id);
79
  $sk_activation_id = get_option('sk_activation_id');
@@ -82,17 +88,16 @@ if (!class_exists('sidekickMassActivator')) {
82
 
83
  $result = $this->send_request('delete', '/domains', array('domainKey' => $sk_activation_id));
84
 
85
- // mlog('$result',$result);
86
 
87
  if (isset($result) && isset($result->success) && $result->success == true) {
88
  delete_option('sk_auto_activation_error');
89
  } else {
90
  update_option('sk_auto_activation_error', $result->message);
91
  wp_mail('bart@sidekick.pro', 'Failed Domain Deactivation', json_encode($result));
92
- }
93
 
94
  return $result;
95
-
96
  }
97
 
98
  function getAffiliateId(){
@@ -107,17 +112,19 @@ if (!class_exists('sidekickMassActivator')) {
107
  }
108
 
109
  function setup_super_admin_key($domainKey) {
110
- // Use the super admin's site activation key if not set using last activation key
111
  if (!get_option('sk_activation_id')) {
112
  update_option('sk_activation_id', $domainKey);
113
  }
114
  }
115
 
116
  function activate_batch() {
117
-
118
- $count = 0;
 
 
119
  $blogs = $this->get_blogs(true);
120
-
121
  foreach ($blogs as $key => $blog) {
122
 
123
  $userId = null;
@@ -132,172 +139,28 @@ if (!class_exists('sidekickMassActivator')) {
132
  }
133
 
134
  function activate_single() {
 
 
135
  $result = $this->activate($_POST['blog_id'], null, $_POST['domain'], $_POST['path']);
136
  die(json_encode($result));
137
  }
138
 
139
  function deactivate_single() {
140
- // mlog("deactivate_single");
141
 
142
- $blog_id = $_POST['blog_id'];
143
 
144
  if ($this->deactivate($blog_id)){
145
  die('{"success":1}');
146
  } else {
147
  die('{"payload":{"message":"Error #13a"}}');
148
  }
149
-
150
-
151
- }
152
-
153
- function send_request($type, $end_point, $data = null, $second_attempt = null) {
154
-
155
- // mlog("FUNCTION: send_request [$type] -> $end_point");
156
-
157
- $url = SK_API . $end_point;
158
- $sk_token = get_transient('sk_token');
159
-
160
- if (!$sk_token && $end_point !== '/login') {
161
- $this->login();
162
- $sk_token = get_transient('sk_token');
163
- }
164
-
165
- $headers = array('Content-Type' => 'application/json');
166
-
167
- if ($sk_token && $end_point !== '/login') {
168
- $headers['Authorization'] = $sk_token;
169
- }
170
-
171
- $args = array(
172
- 'timeout' => 45,
173
- 'redirection' => 5,
174
- 'httpversion' => '1.0',
175
- 'blocking' => true,
176
- 'headers' => $headers
177
- );
178
-
179
- if (isset($type) && $type == 'post') {
180
- $args['method'] = 'POST';
181
- $args['body'] = json_encode($data);
182
- } else if (isset($type) && $type == 'get') {
183
- $args['method'] = 'GET';
184
- $args['body'] = $data;
185
- } else if (isset($type) && $type == 'delete') {
186
- $args['method'] = 'DELETE';
187
- $url .= '?' . http_build_query($data);
188
- }
189
-
190
- $result = wp_remote_post($url, $args);
191
- // mlog('$result',$result);
192
-
193
- if ($end_point == '/login' && $result['response']['message'] == 'Unauthorized') {
194
- // If tried to login and is unauthorized return;
195
- update_option('sk_auto_activation_error', $result->message);
196
- delete_transient('sk_token');
197
- return array('error' => $result->message);
198
- }
199
-
200
- if ($result['response']['message'] == 'Unauthorized' && !$second_attempt) {
201
- // var_dump('Getting rid of token and trying again');
202
- delete_transient('sk_token');
203
- $this->login();
204
-
205
- return $this->send_request($type, $end_point, $data, true);
206
- }
207
-
208
- return json_decode($result['body']);
209
  }
210
 
211
  function setup_menu() {
212
  add_submenu_page('settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins', 'sidekick-licensing', array(&$this, 'admin_page'));
213
  }
214
 
215
- function login() {
216
- $email = get_option('sk_account');
217
- $password = get_option('sk_password');
218
- delete_option('sk_auto_activation_error');
219
-
220
- if (!$password || !$email) {
221
- return false;
222
- }
223
-
224
- $key = 'hash';
225
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
226
-
227
- $result = $this->send_request('post', '/login', array('email' => $email, 'password' => $decrypted_password));
228
-
229
- if (!isset($result) || !$result->success) {
230
- delete_option('sk_token');
231
-
232
- return array('error' => $result->message);
233
- } else {
234
- set_transient('sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS);
235
- // var_dump($result->payload->token->value);
236
- $this->load_subscriptions($result->payload->token->value);
237
-
238
- return array('success' => true);
239
- }
240
- }
241
-
242
- function load_user_data() {
243
- return $this->send_request('get', '/users/');
244
- }
245
-
246
- function load_subscriptions() {
247
-
248
- $result = $this->send_request('get', '/users/subscriptions');
249
-
250
- if (isset($result->success) && isset($result->payload)) {
251
-
252
- $sub = $result->payload[0];
253
-
254
- if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
255
- $this->logout();
256
- update_option('sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
257
-
258
- return false;
259
- }
260
-
261
- update_option('sk_subscription_id', $sub->id);
262
-
263
- $sub->activeDomainCount = 0;
264
-
265
- if (count($sub->Domains) > 0) {
266
- foreach ($sub->Domains as &$domain) {
267
- if (!$domain->end) {
268
- if (isset($sub->activeDomainCount)) {
269
- $sub->activeDomainCount++;
270
- } else {
271
- $sub->activeDomainCount = 1;
272
- }
273
- }
274
- }
275
- }
276
-
277
- $data['subscriptions'] = $result->payload;
278
- $data['libraries'] = $this->load_libraries();
279
-
280
- return $data;
281
- } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
282
- $this->logout();
283
- update_option('sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
284
- }
285
-
286
- return null;
287
- }
288
-
289
- function get_blog_by_id($id) {
290
- global $wpdb;
291
-
292
- $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
293
- FROM $wpdb->blogs
294
- WHERE blog_id = '%d'
295
- "
296
- , $id));
297
-
298
- return $blogs;
299
- }
300
-
301
  function get_blogs($noCache = false) {
302
  global $wpdb;
303
 
@@ -313,25 +176,9 @@ if (!class_exists('sidekickMassActivator')) {
313
  return $blogs;
314
  }
315
 
316
- function logout() {
317
- delete_option('sk_account');
318
- delete_option('sk_password');
319
- delete_option('sk_subscription_id');
320
- delete_option('sk_selected_library');
321
- }
322
-
323
- function load_libraries() {
324
- $result = $this->send_request('get', '/products');
325
- if ($result->success) {
326
- return $result->payload->products;
327
- }
328
-
329
- return null;
330
- }
331
-
332
  function check_batch_status(){
333
  $blogList = $_POST['blogIdList'];
334
- $activeList = [];
335
 
336
  foreach ($blogList as $blogList_key => $blog_id) {
337
  switch_to_blog($blog_id);
@@ -345,6 +192,9 @@ if (!class_exists('sidekickMassActivator')) {
345
  }
346
 
347
  function admin_page() {
 
 
 
348
  if (isset($_POST['sk_account'])) {
349
 
350
  delete_option('sk_auto_activation_error');
@@ -358,8 +208,8 @@ if (!class_exists('sidekickMassActivator')) {
358
 
359
  update_option('sk_account', $_POST['sk_account']);
360
  update_option('sk_password', $encrypted_password);
361
- $login_status = $this->login();
362
  delete_option('sk_auto_activation_error');
 
363
  }
364
 
365
  if (isset($_POST['sk_auto_activations'])) {
@@ -374,6 +224,8 @@ if (!class_exists('sidekickMassActivator')) {
374
 
375
  }
376
 
 
 
377
  if (!$sk_token = get_transient('sk_token')) {
378
  $login_status = $this->login();
379
  }
4
 
5
  if (!class_exists('sidekickMassActivator')) {
6
 
7
+ require_once('sk_api.php');
8
+
9
+ class sidekickMassActivator extends sk_api{
10
 
11
  var $sites_per_page = 50;
12
  var $offet = 0;
13
 
14
+ function log($msg){
15
+ error_log($msg);
16
+ // file_put_contents('Licensing.log', "$msg\n", FILE_APPEND);
17
+ }
18
+
19
  function activate($blog_id, $user_id, $domain, $path) {
20
  // mlog("FUNCTION: activate [$blog_id, $user_id, $domain, $path]");
21
 
22
+ $this->log("activate: $blog_id, $user_id, $domain, $path");
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  $email = '';
25
 
26
  if ($user_id) {
27
+ $user = get_user_by('id', $user_id);
28
+ $email = ($user) ? $user->user_email : 'unknown';
29
  }
30
  $sk_subscription_id = get_option("sk_subscription_id");
31
  $sk_selected_library = get_option("sk_selected_library");
36
  $data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
37
  } else {
38
  update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
 
 
39
  return false;
40
  }
41
 
42
  $result = $this->send_request('post', '/domains', $data);
43
 
44
  if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
45
+ $this->log("activate: success");
46
+ $this->activationSuccessful($result,$blog_id,$email);
47
+ } else {
48
+ $this->log("activate: error");
49
+ $this->activationError($result);
50
+ }
51
 
52
+ return $result;
53
+ }
54
 
55
+ function activationSuccessful($result,$blog_id,$email){
 
 
 
 
 
56
 
57
+ $this->log("activationSuccessful:" . $result->payload->domainKey);
 
58
 
59
+ $this->setup_super_admin_key($result->payload->domainKey);
 
 
 
60
 
61
+ switch_to_blog($blog_id);
62
+ update_option('sk_activation_id', $result->payload->domainKey);
63
+ update_option('sk_email', $email);
64
+ restore_current_blog();
65
+
66
+ update_option('sk_last_setup_blog_id', $blog_id);
67
+
68
+ delete_option('sk_auto_activation_error');
69
+ }
70
+
71
+ function activationError($result){
72
+
73
+ $this->log("activationError: $result->message");
74
 
75
+ update_option('sk_auto_activation_error', $result->message);
76
+ // wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
77
+ wp_mail('bart@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
78
  }
79
 
80
  function deactivate($blog_id) {
81
+
82
+ $this->log("deactivate: $blog_id");
83
 
84
  switch_to_blog($blog_id);
85
  $sk_activation_id = get_option('sk_activation_id');
88
 
89
  $result = $this->send_request('delete', '/domains', array('domainKey' => $sk_activation_id));
90
 
91
+ $this->log("result: $result->success");
92
 
93
  if (isset($result) && isset($result->success) && $result->success == true) {
94
  delete_option('sk_auto_activation_error');
95
  } else {
96
  update_option('sk_auto_activation_error', $result->message);
97
  wp_mail('bart@sidekick.pro', 'Failed Domain Deactivation', json_encode($result));
98
+ }
99
 
100
  return $result;
 
101
  }
102
 
103
  function getAffiliateId(){
112
  }
113
 
114
  function setup_super_admin_key($domainKey) {
115
+ // Use the super admin's site activation key if not set using last activation key
116
  if (!get_option('sk_activation_id')) {
117
  update_option('sk_activation_id', $domainKey);
118
  }
119
  }
120
 
121
  function activate_batch() {
122
+
123
+ $this->log("activate_batch");
124
+
125
+ $count = 0;
126
  $blogs = $this->get_blogs(true);
127
+
128
  foreach ($blogs as $key => $blog) {
129
 
130
  $userId = null;
139
  }
140
 
141
  function activate_single() {
142
+ $this->log("activate_single {$_POST['blog_id']}");
143
+
144
  $result = $this->activate($_POST['blog_id'], null, $_POST['domain'], $_POST['path']);
145
  die(json_encode($result));
146
  }
147
 
148
  function deactivate_single() {
149
+ $this->log("deactivate_single {$_POST['blog_id']}");
150
 
151
+ $blog_id = $_POST['blog_id'];
152
 
153
  if ($this->deactivate($blog_id)){
154
  die('{"success":1}');
155
  } else {
156
  die('{"payload":{"message":"Error #13a"}}');
157
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
 
160
  function setup_menu() {
161
  add_submenu_page('settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins', 'sidekick-licensing', array(&$this, 'admin_page'));
162
  }
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  function get_blogs($noCache = false) {
165
  global $wpdb;
166
 
176
  return $blogs;
177
  }
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  function check_batch_status(){
180
  $blogList = $_POST['blogIdList'];
181
+ $activeList = array();
182
 
183
  foreach ($blogList as $blogList_key => $blog_id) {
184
  switch_to_blog($blog_id);
192
  }
193
 
194
  function admin_page() {
195
+
196
+ $this->log("admin_page");
197
+
198
  if (isset($_POST['sk_account'])) {
199
 
200
  delete_option('sk_auto_activation_error');
208
 
209
  update_option('sk_account', $_POST['sk_account']);
210
  update_option('sk_password', $encrypted_password);
 
211
  delete_option('sk_auto_activation_error');
212
+ delete_transient('sk_token');
213
  }
214
 
215
  if (isset($_POST['sk_auto_activations'])) {
224
 
225
  }
226
 
227
+ $this->log("admin_page sk_token = " . get_transient('sk_token'));
228
+
229
  if (!$sk_token = get_transient('sk_token')) {
230
  $login_status = $this->login();
231
  }
libs/sk_api.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class sk_api{
4
+ function login_request($data){
5
+ $this->log("SEND_LOGIN_REQUEST");
6
+
7
+ if (!isset($data)) {
8
+ $this->log("login_request: error no data");
9
+ return false;
10
+ }
11
+
12
+ $args = array(
13
+ 'timeout' => 15,
14
+ 'redirection' => 5,
15
+ 'httpversion' => '1.0',
16
+ 'blocking' => true,
17
+ 'method' => 'POST',
18
+ 'body' => json_encode($data),
19
+ 'headers' => array('Content-Type' => 'application/json')
20
+ );
21
+
22
+ $result = wp_remote_post(SK_API . '/login' , $args);
23
+
24
+ if ( is_wp_error( $result ) ) {
25
+ $error_message = $result->get_error_message();
26
+ $this->log("login: error -> $error_message");
27
+ } else {
28
+ return json_decode($result['body']);
29
+ }
30
+
31
+ }
32
+
33
+ function send_request($type, $end_point, $data = null, $second_attempt = null) {
34
+
35
+ $this->log("SEND_REQUEST [$type] -> " . $end_point);
36
+
37
+ if (!$sk_token = get_transient('sk_token')) {
38
+ if (!$login_status = $this->login()) {
39
+ $this->log('send_request: Can\'t send request');
40
+ return false;
41
+ } else {
42
+ $this->log("send_request: logged in");
43
+ }
44
+ } else {
45
+ $this->log("send_request: token found proceeding");
46
+ }
47
+
48
+ $url = SK_API . $end_point;
49
+
50
+ $args = array(
51
+ 'timeout' => 15,
52
+ 'redirection' => 5,
53
+ 'httpversion' => '1.0',
54
+ 'method' => strtoupper($type),
55
+ 'body' => (isset($type) && $type == 'post') ? json_encode($data) : $data,
56
+ 'blocking' => true,
57
+ 'headers' => array(
58
+ 'Content-Type' => 'application/json',
59
+ 'Authorization' => $sk_token
60
+ )
61
+ );
62
+
63
+ if (isset($type) && $type == 'post') {
64
+ $args['method'] = 'POST';
65
+ $args['body'] = json_encode($data);
66
+ } else if (isset($type) && $type == 'get') {
67
+ $args['method'] = 'GET';
68
+ $args['body'] = $data;
69
+ } else if (isset($type) && $type == 'delete') {
70
+ $args['method'] = 'DELETE';
71
+ $url .= '?' . http_build_query($data);
72
+ }
73
+
74
+
75
+ $response = wp_remote_post($url, $args);
76
+ // mlog('$response',$response);
77
+ $this->log("send_request: $url");
78
+ $this->log("send_request: RESPONSE");
79
+ $this->log("send_request: {$response['response']['message']}");
80
+
81
+ if ($response['response']['message'] == 'Unauthorized' && !$second_attempt) {
82
+ // var_dump('Getting rid of token and trying again');
83
+ $this->log('send_request: Getting rid of token and trying again');
84
+ delete_transient('sk_token');
85
+ if ($this->login()) {
86
+ return $this->send_request($type, $end_point, $data, true);
87
+ }
88
+ } else {
89
+ $this->log('send_request: Success!');
90
+ return json_decode($response['body']);
91
+ }
92
+
93
+ }
94
+
95
+ function login() {
96
+
97
+ $this->log("login");
98
+
99
+ $email = get_option('sk_account');
100
+ $password = get_option('sk_password');
101
+ delete_option('sk_auto_activation_error');
102
+
103
+ if (!$password || !$email) {
104
+ return false;
105
+ }
106
+
107
+ $key = 'hash';
108
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
109
+
110
+ $result = $this->login_request(array('email' => $email, 'password' => $decrypted_password));
111
+
112
+ if (!isset($result) || !isset($result->success) || (isset($result->response->message) && $result->response->message == 'Unauthorized')) {
113
+ if (isset($result->message)) {
114
+ update_option('sk_auto_activation_error',$result->message);
115
+ $this->log("login: false -> $result->message");
116
+ } else {
117
+ $this->log("login: false");
118
+ }
119
+ delete_option('sk_token');
120
+ return false;
121
+ } else {
122
+ $this->log("login: true -> saving token " . $result->payload->token->value);
123
+ delete_option('sk_auto_activation_error');
124
+ set_transient('sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS);
125
+ $this->load_subscriptions($result->payload->token->value);
126
+ return $result->payload->token->value;
127
+ }
128
+ }
129
+
130
+ function load_user_data() {
131
+ return $this->send_request('get', '/users/');
132
+ }
133
+
134
+ function load_subscriptions() {
135
+
136
+ $this->log("load_subscriptions");
137
+ $result = $this->send_request('get', '/users/subscriptions');
138
+
139
+ if (isset($result->success) && isset($result->payload)) {
140
+
141
+ $sub = $result->payload[0];
142
+
143
+ // if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
144
+ // $this->logout();
145
+ // update_option('sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
146
+
147
+ // return false;
148
+ // }
149
+
150
+ update_option('sk_subscription_id', $sub->id);
151
+
152
+ $sub->activeDomainCount = 0;
153
+
154
+ if (count($sub->Domains) > 0) {
155
+ foreach ($sub->Domains as &$domain) {
156
+ if (!$domain->end) {
157
+ if (isset($sub->activeDomainCount)) {
158
+ $sub->activeDomainCount++;
159
+ } else {
160
+ $sub->activeDomainCount = 1;
161
+ }
162
+ }
163
+ }
164
+ }
165
+
166
+ $data['subscriptions'] = $result->payload;
167
+ $data['libraries'] = $this->load_libraries();
168
+
169
+ return $data;
170
+ } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
171
+ $this->logout();
172
+ update_option('sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
173
+ }
174
+
175
+ return null;
176
+ }
177
+
178
+ function load_libraries() {
179
+ $result = $this->send_request('get', '/products');
180
+ if ($result->success) {
181
+ return $result->payload->products;
182
+ }
183
+
184
+ return null;
185
+ }
186
+
187
+ function logout() {
188
+ delete_option('sk_account');
189
+ delete_option('sk_password');
190
+ delete_option('sk_subscription_id');
191
+ delete_option('sk_selected_library');
192
+ }
193
+
194
+
195
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.sidekick.pro
4
  Tags: help, tutorial, tutorials,screencast, self-help, training, learn, learning, sidekick, guide, teach, video, manual, videos, wphelp, support, instructions, question, questions, answers, answer, clippy, q&a, wpuniversity, helper, walkthrough
5
  Requires at least: 4.1
6
  Tested up to: 4.3.1
7
- Stable tag: 2.6.5
8
  License: GNU Version 2 or Any Later Version
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -149,7 +149,10 @@ We read and respond to every piece of feedback we get.
149
 
150
  == Changelog ==
151
 
152
- = 2.6.5 =
 
 
 
153
  * Performance improvements to multisite activation screens (Thank You Michael @mgyura)
154
 
155
  = 2.6.4 =
4
  Tags: help, tutorial, tutorials,screencast, self-help, training, learn, learning, sidekick, guide, teach, video, manual, videos, wphelp, support, instructions, question, questions, answers, answer, clippy, q&a, wpuniversity, helper, walkthrough
5
  Requires at least: 4.1
6
  Tested up to: 4.3.1
7
+ Stable tag: 2.6.6
8
  License: GNU Version 2 or Any Later Version
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
149
 
150
  == Changelog ==
151
 
152
+ = 2.6.6 =
153
+ * Fixes notice error in multisite management page
154
+
155
+ = 2.6.5 =
156
  * Performance improvements to multisite activation screens (Thank You Michael @mgyura)
157
 
158
  = 2.6.4 =
sidekick.php CHANGED
@@ -6,7 +6,7 @@ Plugin URL: http://wordpress.org/plugins/sidekick/
6
  Description: Adds a real-time WordPress training walkthroughs right in your Dashboard
7
  Requires at least: 4.1
8
  Tested up to: 4.3.1
9
- Version: 2.6.5
10
  Author: Sidekick.pro
11
  Author URI: http://www.sidekick.pro
12
  */
@@ -24,7 +24,7 @@ if (!class_exists('Sidekick')){
24
 
25
  function __construct(){
26
  if (!defined('SK_API')) define('SK_API','https: //apiv2.sidekick.pro');
27
- if (!defined('SK_CACHE_PREFIX')) define('SK_CACHE_PREFIX',str_replace('.', '_', '2.6.5'));
28
  }
29
 
30
  function enqueue_required(){
@@ -293,7 +293,7 @@ if (!class_exists('Sidekick')){
293
 
294
  // WordPress
295
  "embed_partner_id" => SK_EMBEDDED_PARTNER, // for tracking purposes if sidekick has been embeded in another WordPress plugin or theme
296
- "plugin_version" => '2.6.5', // WordPress plugin version
297
  "site_url" => $sk_config_data->get_domain(),
298
  "domain" => str_replace("http://","",$_SERVER["SERVER_NAME"]),
299
  "plugin_url" => admin_url("admin.php?page=sidekick"),
@@ -349,7 +349,7 @@ if (!class_exists('Sidekick')){
349
  function check_ver(){
350
 
351
  if (isset($_GET['sk_ver_check'])){
352
- $data = json_encode('2.6.5');
353
 
354
  if(array_key_exists('callback', $_GET)){
355
 
6
  Description: Adds a real-time WordPress training walkthroughs right in your Dashboard
7
  Requires at least: 4.1
8
  Tested up to: 4.3.1
9
+ Version: 2.6.6
10
  Author: Sidekick.pro
11
  Author URI: http://www.sidekick.pro
12
  */
24
 
25
  function __construct(){
26
  if (!defined('SK_API')) define('SK_API','https: //apiv2.sidekick.pro');
27
+ if (!defined('SK_CACHE_PREFIX')) define('SK_CACHE_PREFIX',str_replace('.', '_', '2.6.6'));
28
  }
29
 
30
  function enqueue_required(){
293
 
294
  // WordPress
295
  "embed_partner_id" => SK_EMBEDDED_PARTNER, // for tracking purposes if sidekick has been embeded in another WordPress plugin or theme
296
+ "plugin_version" => '2.6.6', // WordPress plugin version
297
  "site_url" => $sk_config_data->get_domain(),
298
  "domain" => str_replace("http://","",$_SERVER["SERVER_NAME"]),
299
  "plugin_url" => admin_url("admin.php?page=sidekick"),
349
  function check_ver(){
350
 
351
  if (isset($_GET['sk_ver_check'])){
352
+ $data = json_encode('2.6.6');
353
 
354
  if(array_key_exists('callback', $_GET)){
355