Sidekick - Version 2.6.5

Version Description

  • Performance improvements to multisite activation screens (Thank You Michael @mgyura)
Download this release

Release Info

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

Code changes from version 2.6.4 to 2.6.5

Files changed (5) hide show
  1. js/sidekick_admin.js +106 -162
  2. libs/licensing.php +330 -476
  3. libs/ms_admin_page.php +16 -36
  4. readme.txt +4 -1
  5. sidekick.php +8 -10
js/sidekick_admin.js CHANGED
@@ -13,7 +13,7 @@ var unactivated_count = 0;
13
 
14
 
15
  function updateCounts(e){
16
- jQuery('.site_list').html('');
17
  jQuery('.pagination .start').html(loadOffset+1);
18
  jQuery('.pagination .end').html(e.pages);
19
  jQuery('.stats .unactivated h3').html(e.counts.unactivated);
@@ -39,101 +39,56 @@ function setup_buttons_deactivate(){
39
  });
40
  }
41
 
42
- function load_sites_by_status(status,target){
43
-
44
- activated = 0;
45
-
46
- if (status) {
47
- lastLoadedStatus = status;
48
- } else {
49
- status = lastLoadedStatus;
50
- }
51
-
52
- jQuery('.stats>div').removeClass('selected');
53
- jQuery('.stats .' + status).addClass('selected');
54
- jQuery('.sites h2 span').html(status + ' site list');
55
-
56
- if (parseInt(jQuery(target).find('h3').html(),10) === 0) {
57
- jQuery('.site_list').html('<div class=\'site\'>No Sites</div>');
58
- jQuery('.sites .action').hide();
59
- return false;
60
- } else {
61
- jQuery('.sites .action').show();
62
- }
63
-
64
- var data = {
65
- action: 'sk_load_sites_by_status',
66
- status: status,
67
- offset: (loadOffset) ? loadOffset : 0
68
- };
69
-
70
- jQuery('.site_list .site').fadeTo('fast',0.5);
71
-
72
- jQuery.post(ajaxurl, data, function(e,msg){
73
-
74
- updateCounts(e);
75
-
76
- var button = '<button class="activate">Activate</button></div>';
77
-
78
- if (lastLoadedStatus === 'active') {
79
- button = '<button class="deactivate">Deactivate</button></div>';
80
- }
81
-
82
- if (e.sites && e.sites.length > 0) {
83
 
84
- if (e.sites.length < 25) {
85
- jQuery('.action').hide();
86
- }
87
 
88
- _.each(e.sites,function(site,key){
89
- jQuery('.site_list').append('<div class="site" data-path="' + site.path + '" data-domain="' + site.domain + '" data-userid="' + site.user_id + '" data-blogid="' + site.blog_id + '">' + site.domain + '/' + site.path + button);
90
- });
91
- } else {
92
- jQuery('.site_list').append('<div class="site">No Sites</div>');
93
- jQuery('.activate_all').hide();
94
- jQuery('.action').hide();
95
- }
96
 
97
- setup_buttons();
98
 
99
- },'json');
100
- }
101
 
102
- function setup_buttons_next_prev(){
 
103
 
104
- jQuery('.pagination .next').off('click').click(function(){
105
- jQuery('.pagination .prev').show();
106
 
107
- loadOffset = loadOffset + 1;
108
- load_sites_by_status(null,loadOffset);
109
 
110
- if (loadOffset === parseInt(jQuery('.pagination .end').html(),10)-1) {
111
  jQuery('.pagination .next').hide();
112
  }
 
113
  });
114
 
115
- jQuery('.pagination .prev').off('click').click(function(){
 
 
116
  jQuery('.pagination .next').show();
117
 
118
- loadOffset = loadOffset - 1;
119
- load_sites_by_status(null,loadOffset);
 
 
 
 
 
 
 
 
 
120
 
121
- if (loadOffset === 0) {
122
  jQuery('.pagination .prev').hide();
123
  }
 
 
124
  });
125
  }
126
 
127
- function updateStatCounts(increment){
128
-
129
- var default_increment = 1;
130
- if (increment) {
131
- default_increment = increment;
132
- }
133
-
134
- jQuery('h3','div.' + lastLoadedStatus).html(parseInt(jQuery('h3','div.' + lastLoadedStatus).html(),10)-default_increment);
135
- jQuery('h3','div.active').html(parseInt(jQuery('h3','div.active').html(),10)+default_increment);
136
- }
137
 
138
  function setup_buttons_activate_batch(){
139
  jQuery('.activate_all').off('click').click(function(){
@@ -142,84 +97,65 @@ function setup_buttons_activate_batch(){
142
  action: 'sk_activate_batch'
143
  };
144
 
145
- if (activated > 0) {
146
- var activated_perc = Math.round((activated/unactivated_count)*100,0);
147
- jQuery(this).html('Activating... ' + activated_perc + '%').addClass('loading');
148
- } else {
149
- jQuery(this).html('Activating...').addClass('loading');
150
- }
151
-
152
- jQuery.post(ajaxurl, data, function(e){
153
-
154
- activated += parseInt(e.activated_count,10);
155
- unactivated_count = parseInt(e.unactivated_count,10);
156
 
157
- updateStatCounts(parseInt(e.activated_count,10));
158
- if (parseInt(e.activated_count,10) === parseInt(e.sites_per_page,10)) {
159
- jQuery('.activate_all').trigger('click');
160
- } else {
161
- jQuery('.activate_all').html('Done').removeClass('loading');
162
- window.location.reload();
163
- }
164
 
165
- },'json');
 
 
 
166
 
167
  });
 
168
 
169
- jQuery('.reset_all').off('click').click(function(){
170
-
171
- var sure = confirm('This will reset all the activation keys. Are You Sure?');
172
-
173
- if (sure) {
174
- var data = {
175
- action: 'sk_reset'
176
- };
177
-
178
- jQuery(this).html('Reseting...').addClass('loading');
179
 
180
- jQuery.post(ajaxurl, data, function(){
181
- jQuery('.reset_all').html('Done!').removeClass('loading');
182
- window.location.reload();
183
- },'json');
184
- }
185
 
186
  });
187
-
188
  }
189
 
190
- var activateCallback = function(button){
 
191
  return function(e){
 
192
  if (!e.success) {
193
  jQuery(button).html('Error').addClass('red');
194
- if (e.payload.message === 'Already Activated') {
195
- updateStatCounts();
196
- }
197
  jQuery('.single_activation_error').html(e.payload.message).show();
198
  } else if (e.success) {
199
- updateStatCounts();
200
- jQuery(button).html('Success').addClass('green');
201
- }
202
- };
203
- };
204
 
 
 
 
205
 
206
- var deactivateCallback = function(button){
207
- return function(e){
208
- if (!e.success) {
209
- jQuery(button).html('Error').addClass('red');
210
- if (e.payload.message === 'Already Deactivated') {
211
- updateStatCounts();
212
  }
213
- jQuery('.single_activation_error').html(e.payload.message).show();
214
- } else if (e.success) {
215
- updateStatCounts();
216
- jQuery(button).html('Success').addClass('green');
 
 
217
  }
218
  };
219
  };
220
 
221
  function setup_buttons_activate(){
222
- jQuery('.site button.activate').off('click').click(function(){
 
 
223
  var data = {
224
  action: 'sk_activate_single',
225
  blog_id: jQuery(this).parent().data('blogid'),
@@ -228,16 +164,22 @@ function setup_buttons_activate(){
228
  path: jQuery(this).parent().data('path')
229
  };
230
 
231
- jQuery(this).html('Activating...');
 
 
 
 
 
 
 
232
  jQuery('.single_activation_error').html('').hide();
233
- jQuery.post(ajaxurl, data, activateCallback(this),'json');
234
  });
235
  }
236
 
237
  function setup_buttons(){
238
  setup_buttons_next_prev();
239
  setup_buttons_activate();
240
- setup_buttons_deactivate();
241
  setup_buttons_activate_batch();
242
  }
243
 
@@ -415,8 +357,8 @@ function setup_events(){
415
  // });
416
  // });
417
 
418
- jQuery('.sk_bucket').not(':has(li)').remove();
419
- jQuery('.sk_product').not(':has(li)').remove();
420
 
421
  // Set the disable_wts back to original state
422
  sk_config.disable_wts = currently_disabled_wts;
@@ -487,6 +429,32 @@ function setup_intro_welcome_button(){
487
  });
488
  }
489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  function setup_sk_admin(){
491
  // console.log('setup_sk_admin');
492
  if (jQuery('.sidekick_admin').length === 0) {
@@ -501,7 +469,7 @@ function setup_sk_admin(){
501
  if (typeof window.sk_ms_admin !== 'undefined' && window.sk_ms_admin) {
502
 
503
  // Multisite
504
- load_sites_by_status('unactivated');
505
 
506
  var clicked_button;
507
 
@@ -552,31 +520,7 @@ function setup_sk_admin(){
552
  }
553
  }
554
 
555
- function setupSkHeartBeat(){
556
- console.log('setupSkHeartBeat');
557
- // Hook into the heartbeat-send
558
- jQuery(document).on('heartbeat-send', function(e, data) {
559
- console.log('hb send');
560
- data['sk_hb_data'] = 'removedSites';
561
- });
562
-
563
- // Listen for the custom event "heartbeat-tick" on jQuery(document).
564
- jQuery(document).on( 'heartbeat-tick', function(e, data) {
565
-
566
- console.log('111 data %o', data);
567
-
568
-
569
- // Only proceed if our EDD data is present
570
- if ( ! data['edd-payment-count'] ){
571
- return;
572
- }
573
-
574
-
575
-
576
- });
577
- }
578
-
579
  jQuery(document).ready(function($) {
580
- setupSkHeartBeat();
581
  setup_intro_welcome_button();
582
  });
13
 
14
 
15
  function updateCounts(e){
16
+ // jQuery('.site_list').html('');
17
  jQuery('.pagination .start').html(loadOffset+1);
18
  jQuery('.pagination .end').html(e.pages);
19
  jQuery('.stats .unactivated h3').html(e.counts.unactivated);
39
  });
40
  }
41
 
42
+ function setup_buttons_next_prev(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ jQuery('.pagination .next').off('click').click(function(e){
45
+ e.preventDefault();
 
46
 
47
+ jQuery('.pagination .prev').show();
 
 
 
 
 
 
 
48
 
49
+ var lastVisibleIndex = jQuery('.site_list .site:visible:last').index();
50
 
51
+ var start = lastVisibleIndex+1;
52
+ var end = lastVisibleIndex+1+paginationSize;
53
 
54
+ var oldSites = jQuery('.site_list .site:visible').addClass('hidden');
55
+ var newSites = jQuery('.site_list .site').slice(start,end).removeClass('hidden');
56
 
57
+ console.log('showing %s to %s', start,end);
 
58
 
59
+ var visibleCount = jQuery('.site_list .site:visible').length;
 
60
 
61
+ if (jQuery('.site_list .site:last:visible').length > 0) {
62
  jQuery('.pagination .next').hide();
63
  }
64
+ checkStatusOfVisibleButtons();
65
  });
66
 
67
+ jQuery('.pagination .prev').off('click').click(function(e){
68
+ e.preventDefault();
69
+
70
  jQuery('.pagination .next').show();
71
 
72
+ var firstVisibleSiteIndex = jQuery('.site_list .site:visible:first').index();
73
+ var start = firstVisibleSiteIndex - paginationSize - 1;
74
+ var end = firstVisibleSiteIndex;
75
+ if (start < 0){
76
+ start = 0;
77
+ end = paginationSize;
78
+ }
79
+ var oldSites = jQuery('.site_list .site:visible').addClass('hidden');
80
+ var newSites = jQuery('.site_list .site').slice(start,end).removeClass('hidden');
81
+
82
+ console.log('showing %s to %s', start,end);
83
 
84
+ if (jQuery('.site_list .site:first:visible').length > 0) {
85
  jQuery('.pagination .prev').hide();
86
  }
87
+
88
+ checkStatusOfVisibleButtons();
89
  });
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  function setup_buttons_activate_batch(){
94
  jQuery('.activate_all').off('click').click(function(){
97
  action: 'sk_activate_batch'
98
  };
99
 
100
+ jQuery('.activate_all').html('Activating...').addClass('loading');
 
 
 
 
 
 
 
 
 
 
101
 
102
+ jQuery('.site_list .site').removeClass('hidden');
 
 
 
 
 
 
103
 
104
+ checkStatusOfVisibleButtons(triggerAllActivations)
105
+ .done(function(){
106
+ jQuery('.activate_all').html('Done').removeClass('loading');
107
+ });
108
 
109
  });
110
+ }
111
 
112
+ function triggerAllActivations(){
113
+ var activateTotal = jQuery('.site .activate').length;
114
+ jQuery.each(jQuery('.site .activate'), function(i, el){
115
+ if (activateTotal-1 == i) {
116
+ jQuery('.activate_all').hide().html('Activate All');
117
+ };
118
+ setTimeout(function(){
119
+ jQuery('html, body').animate({scrollTop: jQuery(el).offset().top - 100}, 200);
 
 
120
 
121
+ jQuery(el).trigger('click');
122
+ },500 + ( i * 500 ));
 
 
 
123
 
124
  });
 
125
  }
126
 
127
+ var changeStatusCallback = function(button){
128
+ console.log('changeStatusCallback');
129
  return function(e){
130
+
131
  if (!e.success) {
132
  jQuery(button).html('Error').addClass('red');
 
 
 
133
  jQuery('.single_activation_error').html(e.payload.message).show();
134
  } else if (e.success) {
 
 
 
 
 
135
 
136
+ var newButtonClass = 'deactivate';
137
+ var newButtonName = 'Deactivate';
138
+ var prevButtonClass = 'activate';
139
 
140
+ if (jQuery(button).hasClass('deactivate')) {
141
+ newButtonClass = 'activate';
142
+ newButtonName = 'Activate';
143
+ prevButtonClass = 'deactivate';
 
 
144
  }
145
+
146
+ jQuery(button).html('Success').addClass('green').delay(1000).queue(function(next){
147
+ jQuery(this).html(newButtonName).removeClass(prevButtonClass).removeClass('green').addClass(newButtonClass);
148
+ next();
149
+ });
150
+
151
  }
152
  };
153
  };
154
 
155
  function setup_buttons_activate(){
156
+ console.log('setup_buttons_activate');
157
+ jQuery('.site_list button').off('click').click(function(){
158
+ console.log('click');
159
  var data = {
160
  action: 'sk_activate_single',
161
  blog_id: jQuery(this).parent().data('blogid'),
164
  path: jQuery(this).parent().data('path')
165
  };
166
 
167
+ if (jQuery(this).hasClass('deactivate')) {
168
+ data.action = 'sk_deactivate_single';
169
+ jQuery(this).html('Deactivating...');
170
+ } else {
171
+ jQuery(this).html('Activating...');
172
+ }
173
+
174
+
175
  jQuery('.single_activation_error').html('').hide();
176
+ jQuery.post(ajaxurl, data, changeStatusCallback(this),'json');
177
  });
178
  }
179
 
180
  function setup_buttons(){
181
  setup_buttons_next_prev();
182
  setup_buttons_activate();
 
183
  setup_buttons_activate_batch();
184
  }
185
 
357
  // });
358
  // });
359
 
360
+ jQuery('.sk_bucket').not(':has(li)').remove();
361
+ jQuery('.sk_product').not(':has(li)').remove();
362
 
363
  // Set the disable_wts back to original state
364
  sk_config.disable_wts = currently_disabled_wts;
429
  });
430
  }
431
 
432
+ function checkStatusOfVisibleButtons(callback){
433
+
434
+
435
+ var blogIdList = jQuery('button.checking:visible').closest('.site').map(function(){
436
+ return jQuery(this).data('blogid');
437
+ }).get();
438
+
439
+ var data = {
440
+ action: 'sk_check_batch_status',
441
+ blogIdList: blogIdList
442
+ };
443
+
444
+ return jQuery.post(ajaxurl, data, function(e){
445
+
446
+ jQuery.each(e,function(key,blogId){
447
+ jQuery('div[data-blogid="' + blogId + '"] button').removeClass('checking').addClass('deactivate').html('Deactivate');
448
+ });
449
+ jQuery('button.checking:visible').removeClass('checking').addClass('activate').html('Activate');
450
+ if (callback) {
451
+ callback();
452
+ };
453
+
454
+ },'json');
455
+
456
+ }
457
+
458
  function setup_sk_admin(){
459
  // console.log('setup_sk_admin');
460
  if (jQuery('.sidekick_admin').length === 0) {
469
  if (typeof window.sk_ms_admin !== 'undefined' && window.sk_ms_admin) {
470
 
471
  // Multisite
472
+ checkStatusOfVisibleButtons();
473
 
474
  var clicked_button;
475
 
520
  }
521
  }
522
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  jQuery(document).ready(function($) {
524
+ setup_buttons();
525
  setup_intro_welcome_button();
526
  });
libs/licensing.php CHANGED
@@ -4,542 +4,396 @@
4
 
5
  if (!class_exists('sidekickMassActivator')) {
6
 
7
- class sidekickMassActivator {
8
 
9
- var $sites_per_page = 25;
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
- $checked_blogs = get_option('sk_checked_blogs');
 
 
 
 
 
 
20
 
21
- if (isset($checked_blogs['active'][$blog_id]) || $sk_activation_id) {
22
- unset($checked_blogs['unactivated'][$blog_id]);
23
- $blog = $this->get_blog_by_id($blog_id);
24
- $checked_blogs['active'][$blog_id] = $blog[0];
25
 
26
- update_option('sk_checked_blogs', $checked_blogs);
27
 
28
- $result = array(
29
- "payload" => array(
30
- "blog" => $blog[0],
31
- "message" => "Already Activated",
32
- ),
33
- );
34
 
35
- return json_encode($result);
36
- }
 
 
 
 
37
 
38
- $user = get_user_by('id', $user_id);
39
- $email = ($user) ? $user->user_email : 'unknown';
40
- $sk_subscription_id = get_option("sk_subscription_id");
41
- $sk_selected_library = get_option("sk_selected_library");
42
 
43
- if (isset($sk_selected_library) && $sk_selected_library && $sk_selected_library !== -1 && $sk_selected_library !== '-1') {
44
- $data = array('domainName' => $domain . '/' . $path, 'productId' => $sk_selected_library);
45
- } elseif (isset($sk_subscription_id) && intval($sk_subscription_id)) {
46
- $data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
47
- } else {
48
- update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
49
 
 
50
 
51
- return false;
52
- }
53
 
54
- $result = $this->send_request('post', '/domains', $data);
55
 
56
- if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
 
 
 
 
 
57
 
58
- $this->setup_super_admin_key($result->payload->domainKey);
 
59
 
60
- switch_to_blog($blog_id);
61
- update_option('sk_activation_id', $result->payload->domainKey);
62
- update_option('sk_email', $email);
63
- restore_current_blog();
64
-
65
- if (isset($checked_blogs['deactivated'][$blog_id])) {
66
- $checked_blogs['active'][$blog_id] = $checked_blogs['deactivated'][$blog_id];
67
- unset($checked_blogs['deactivated'][$blog_id]);
68
- } else if (isset($checked_blogs['unactivated'][$blog_id])) {
69
- $checked_blogs['active'][$blog_id] = $checked_blogs['unactivated'][$blog_id];
70
- unset($checked_blogs['unactivated'][$blog_id]);
71
- }
72
-
73
- update_option('sk_checked_blogs', $checked_blogs);
74
- update_option('sk_last_setup_blog_id', $blog_id);
75
-
76
- delete_option('sk_auto_activation_error');
77
- } else {
78
-
79
- update_option('sk_auto_activation_error', $result->message);
80
  // wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
81
- wp_mail('bart@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
82
- }
83
 
84
- return $result;
85
 
86
- }
87
 
88
- function deactivate($blog_id) {
89
- mlog("FUNCTION: deactivate [$blog_id]");
90
 
91
- switch_to_blog($blog_id);
92
- $sk_activation_id = get_option('sk_activation_id');
93
- delete_option('sk_activation_id');
94
- restore_current_blog();
95
 
96
- $result = $this->send_request('delete', '/domains', array('domainKey' => $sk_activation_id));
97
 
98
- mlog('$result',$result);
99
 
100
- if (isset($result) && isset($result->success) && $result->success == true) {
101
- delete_option('sk_auto_activation_error');
102
- } else {
103
- update_option('sk_auto_activation_error', $result->message);
104
- wp_mail('bart@sidekick.pro', 'Failed Domain Deactivation', json_encode($result));
105
- }
106
 
107
- return $result;
108
 
109
- }
110
 
111
- function getAffiliateId(){
112
- if (defined('SK_AFFILIATE_ID')) {
113
- $affiliate_id = intval(SK_AFFILIATE_ID);
114
- } else if (get_option( "sk_affiliate_id")){
115
- $affiliate_id = intval(get_option( "sk_affiliate_id"));
116
- } else {
117
- $affiliate_id = '';
118
- }
119
- return $affiliate_id;
120
- }
121
 
122
- function setup_super_admin_key($domainKey) {
123
  // Use the super admin's site activation key if not set using last activation key
124
- if (!get_option('sk_activation_id')) {
125
- update_option('sk_activation_id', $domainKey);
126
- }
127
- }
128
-
129
- function activate_batch() {
130
- $checked_blogs = get_option('sk_checked_blogs');
131
- $count = 0;
132
-
133
- if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated'])) {
134
- foreach ($checked_blogs['unactivated'] as $key => $blog) {
135
- if ($count == $this->sites_per_page) {
136
- break;
137
- }
138
- mlog('$blog',$blog);
139
-
140
- $userId = null;
141
- if (isset($blog->user_id)) {
142
- $userId = $blog->user_id;
143
- }
144
-
145
- $this->activate($blog->blog_id, $userId, $blog->domain, $blog->path);
146
- $count++;
147
- }
148
- }
149
- //mlog('$checked_blogs',$checked_blogs);
150
-
151
- $result = array('activated_count' => $count, 'sites_per_page' => $this->sites_per_page, 'unactivated_count' => count($checked_blogs['unactivated']));
152
- mlog('123$result',$result);
153
- die(json_encode($result));
154
- }
155
-
156
- function activate_single() {
157
- $result = $this->activate($_POST['blog_id'], $_POST['user_id'], $_POST['domain'], $_POST['path']);
158
- die(json_encode($result));
159
- }
160
-
161
- function resetCacheAndClearActivationIDs(){
162
- mlog('resetCacheAndClearActivationIDs');
163
- $sites = wp_get_sites();
164
-
165
- delete_option('sk_checked_blogs');
166
-
167
- foreach ($sites as $sites_key => $site) {
168
- $this->deactivate($site['blog_id']);
169
- }
170
-
171
- die('1');
172
- }
173
-
174
- function deactivate_single() {
175
-
176
- $checked_blogs = get_option('sk_checked_blogs');
177
- $blog_id = $_POST['blog_id'];
178
-
179
- if (isset($checked_blogs['active'][$blog_id])) {
180
-
181
- if ($this->deactivate($blog_id)){
182
- die('{"success":1}');
183
- } else {
184
- die('{"payload":{"message":"Error #13a"}}');
185
- }
186
-
187
- } else {
188
- die('{"payload":{"message":"Error #13b"}}');
189
- }
190
- }
191
-
192
- function heartbeat_received($data){
193
- // Make sure we only run our query if the edd_heartbeat key is present
194
- mlog('$_POST',$_POST);
195
- mlog('$_GET',$_GET);
196
- if( $_POST['data']['sk_hb_data'] == 'removedSites' ) {
197
-
198
- $response['bart'] = 'test';
199
-
200
- }
201
- return $response;
202
- }
203
-
204
- function send_request($type, $end_point, $data = null, $second_attempt = null) {
205
-
206
- mlog("FUNCTION: send_request [$type] -> $end_point");
207
-
208
- $url = SK_API . $end_point;
209
- $sk_token = get_transient('sk_token');
210
-
211
- if (!$sk_token && $end_point !== '/login') {
212
- $this->login();
213
- $sk_token = get_transient('sk_token');
214
- }
215
-
216
- $headers = array('Content-Type' => 'application/json');
217
-
218
- if ($sk_token && $end_point !== '/login') {
219
- $headers['Authorization'] = $sk_token;
220
- }
221
-
222
- $args = array(
223
- 'timeout' => 45,
224
- 'redirection' => 5,
225
- 'httpversion' => '1.0',
226
- 'blocking' => true,
227
- 'headers' => $headers
228
- );
229
-
230
- if (isset($type) && $type == 'post') {
231
- $args['method'] = 'POST';
232
- $args['body'] = json_encode($data);
233
- } else if (isset($type) && $type == 'get') {
234
- $args['method'] = 'GET';
235
- $args['body'] = $data;
236
- } else if (isset($type) && $type == 'delete') {
237
- $args['method'] = 'DELETE';
238
- $url .= '?' . http_build_query($data);
239
- }
240
-
241
- $result = wp_remote_post($url, $args);
242
-
243
- if ($end_point == '/login' && $result['response']['message'] == 'Unauthorized') {
244
- // If tried to login and is unauthorized return;
245
- update_option('sk_auto_activation_error', $result->message);
246
- delete_transient('sk_token');
247
- return array('error' => $result->message);
248
- }
249
-
250
- if ($result['response']['message'] == 'Unauthorized' && !$second_attempt) {
251
- // var_dump('Getting rid of token and trying again');
252
- delete_transient('sk_token');
253
- $this->login();
254
-
255
- return $this->send_request($type, $end_point, $data, true);
256
- }
257
-
258
- return json_decode($result['body']);
259
- }
260
-
261
- function setup_menu() {
262
- add_submenu_page('settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins', 'sidekick-licensing', array(&$this, 'admin_page'));
263
- }
264
-
265
- function login() {
266
- $email = get_option('sk_account');
267
- $password = get_option('sk_password');
268
- delete_option('sk_auto_activation_error');
269
-
270
- if (!$password || !$email) {
271
- return false;
272
- }
273
-
274
- $key = 'hash';
275
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
276
-
277
- $result = $this->send_request('post', '/login', array('email' => $email, 'password' => $decrypted_password));
278
-
279
- if (!isset($result) || !$result->success) {
280
- delete_option('sk_token');
281
-
282
- return array('error' => $result->message);
283
- } else {
284
- set_transient('sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS);
285
- // var_dump($result->payload->token->value);
286
- $this->load_subscriptions($result->payload->token->value);
287
-
288
- return array('success' => true);
289
- }
290
- }
291
-
292
- function load_user_data() {
293
- return $this->send_request('get', '/users/');
294
- }
295
-
296
- function load_subscriptions() {
297
-
298
- $result = $this->send_request('get', '/users/subscriptions');
299
-
300
- if (isset($result->success) && isset($result->payload)) {
301
-
302
- $sub = $result->payload[0];
303
-
304
- if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
305
- $this->logout();
306
- update_option('sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
307
-
308
- return false;
309
- }
310
 
311
- update_option('sk_subscription_id', $sub->id);
 
 
 
 
 
312
 
313
- $sub->activeDomainCount = 0;
 
 
 
314
 
315
- if (count($sub->Domains) > 0) {
316
- foreach ($sub->Domains as &$domain) {
317
- if (!$domain->end) {
318
- if (isset($sub->activeDomainCount)) {
319
- $sub->activeDomainCount++;
320
- } else {
321
- $sub->activeDomainCount = 1;
322
- }
323
- }
324
- }
325
- }
326
 
327
- $data['subscriptions'] = $result->payload;
328
- $data['libraries'] = $this->load_libraries();
329
 
330
- return $data;
331
- } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
332
- $this->logout();
333
- update_option('sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
334
- }
335
 
336
- return null;
337
- }
338
 
339
- function get_blog_by_id($id) {
340
- global $wpdb;
341
 
342
- $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
343
- FROM $wpdb->blogs
344
- WHERE blog_id = '%d'
345
- "
346
- , $id));
347
 
348
- return $blogs;
349
- }
350
 
351
- function get_blogs() {
352
- global $wpdb;
353
 
354
- if (false === ($blogs = get_transient('sk_blog_list'))) {
355
- $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
356
- FROM $wpdb->blogs
357
- WHERE spam = '%d' AND deleted = '%d'
358
- "
359
- , 0, 0));
360
- set_transient('sk_blog_list', $blogs, 24 * HOUR_IN_SECONDS);
361
- }
362
 
363
- return $blogs;
364
- }
365
 
366
- function get_unchecked_blogs($blogs, $checked_blogs) {
367
- $return = array();
368
 
369
- foreach ($blogs as $key => $blog) {
 
 
 
370
 
371
- if (isset($checked_blogs['deactivated']) && is_array($checked_blogs['deactivated']) && isset($checked_blogs['deactivated'][$blog->blog_id])) {
372
- continue;
373
- }
374
 
375
- if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated']) && isset($checked_blogs['unactivated'][$blog->blog_id])) {
376
- continue;
377
- }
378
 
379
- if (isset($checked_blogs['active']) && is_array($checked_blogs['active']) && isset($checked_blogs['active'][$blog->blog_id])) {
380
- continue;
381
- }
 
 
 
 
382
 
383
- $return[$blog->blog_id] = $blog;
384
- }
 
 
 
 
 
 
 
 
385
 
386
- return $return;
387
- }
388
 
389
- function check_statuses() {
390
- $checked_blogs = get_option('sk_checked_blogs');
391
- $blogs = $this->get_blogs();
392
- $unchecked_blogs = $this->get_unchecked_blogs($blogs, $checked_blogs);
393
- $count = 0;
394
-
395
- if (!isset($checked_blogs['unactivated'])) {
396
- $checked_blogs['unactivated'] = array();
397
- }
398
-
399
- if (!isset($checked_blogs['active'])) {
400
- $checked_blogs['active'] = array();
401
- }
402
-
403
- if (!isset($checked_blogs['deactivated'])) {
404
- $checked_blogs['deactivated'] = array();
405
- }
406
-
407
- foreach ($unchecked_blogs as $blog) {
408
-
409
- // if ($count > $this->sites_per_page) {
410
- // break;
411
- // }
412
-
413
- $blog_id = $blog->blog_id;
414
- $activation_id = null;
415
- $count++;
416
-
417
- switch_to_blog($blog_id);
418
- if ($user = get_user_by('email', get_option('admin_email'))) {
419
- $blog->user_id = $user->ID;
420
- }
421
- $activation_id = get_site_option('sk_activation_id');
422
- restore_current_blog();
423
-
424
- if ($activation_id) {
425
- $status = 'active';
426
- } elseif (isset($checked_blogs['deactivated']) && in_array($blog_id, $checked_blogs['deactivated'])) {
427
- $status = 'deactivated';
428
- } else {
429
- $status = 'unactivated';
430
- }
431
-
432
- $checked_blogs[$status][$blog_id] = $blog;
433
-
434
- }
435
-
436
- update_option('sk_checked_blogs', $checked_blogs);
437
-
438
- return $checked_blogs;
439
-
440
- }
441
-
442
- function load_sites_by_status() {
443
- global $wpdb;
444
-
445
- $checked_blogs = $this->check_statuses();
446
- $status = sanitize_text_field($_POST['status']);
447
- $this->offet = sanitize_text_field($_POST['offset']);
448
-
449
- if (isset($checked_blogs[$status]) && is_array($checked_blogs[$status])) {
450
-
451
- $return['sites'] = array_slice($checked_blogs[$status], $this->offet, $this->sites_per_page);
452
- $return['counts']['all_blogs'] = intval($wpdb->get_var($wpdb->prepare("SELECT count(blog_id) as count FROM $wpdb->blogs WHERE spam = '%d' AND deleted = '%d'", 0, 0)));
453
- $return['counts']['active'] = count($checked_blogs['active']);
454
- $return['counts']['deactivated'] = count($checked_blogs['deactivated']);
455
- $return['counts']['unactivated'] = intval($return['counts']['all_blogs']) - intval($return['counts']['active']) - $return['counts']['deactivated'];
456
-
457
-
458
- $currentStatusCount = intval($return['counts'][$status]);
459
- $return['pages'] = ceil($currentStatusCount / $this->sites_per_page);
460
-
461
- // $return['counts'][$status] = count($checked_blogs[$status]);
462
- } else {
463
- // $return['counts'][$status] = 0;
464
- $return[$status]['sites'] = array();
465
- }
466
-
467
- die(json_encode($return));
468
- }
469
-
470
- function logout() {
471
- delete_option('sk_account');
472
- delete_option('sk_password');
473
- delete_option('sk_subscription_id');
474
- delete_option('sk_selected_library');
475
- }
476
 
477
- function load_libraries() {
478
- $result = $this->send_request('get', '/products');
479
- if ($result->success) {
480
- return $result->payload->products;
481
- }
482
 
483
- return null;
484
- }
485
 
486
- function schedule(){
487
- if ( ! wp_next_scheduled( array($this,'check_statuses') ) ) {
488
- wp_schedule_event( time(), 'hourly', array($this,'check_statuses'));
489
- wp_schedule_event( time(), 'hourly', array($this,'activate_batch'));
490
- }
491
-
492
- }
493
 
494
- function admin_page() {
495
- if (isset($_POST['sk_account'])) {
 
496
 
497
- delete_option('sk_auto_activation_error');
 
 
 
498
 
499
- if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
500
- $key = 'hash';
501
- $string = $_POST['sk_password'];
502
 
503
- $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
504
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
505
 
506
- update_option('sk_account', $_POST['sk_account']);
507
- update_option('sk_password', $encrypted_password);
508
- $login_status = $this->login();
509
- delete_option('sk_auto_activation_error');
510
- }
511
-
512
- if (isset($_POST['sk_auto_activations'])) {
513
- update_option('sk_auto_activations', true);
514
- } else {
515
- delete_option('sk_auto_activations');
516
- }
517
-
518
- if (isset($_POST['sk_selected_library'])) {
519
- update_option('sk_selected_library', $_POST['sk_selected_library']);
520
- }
521
 
522
- }
 
523
 
524
- if (!$sk_token = get_transient('sk_token')) {
525
- $login_status = $this->login();
526
- }
 
 
527
 
528
- $sk_subs = $this->load_subscriptions();
529
- $user_data = $this->load_user_data();
530
- $sk_auto_activations = get_option('sk_auto_activations');
531
- $sk_auto_activation_error = get_option('sk_auto_activation_error');
532
- $sk_subscription_id = get_option('sk_subscription_id');
533
- $sk_selected_library = get_option('sk_selected_library');
534
- $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
535
- $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
536
- $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
537
- $is_ms_admin = true;
538
- $affiliate_id = $this->getAffiliateId();
539
-
540
- require_once('ms_admin_page.php');
541
- }
542
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  }
544
 
545
  // //licensing.php
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");
38
 
39
+ if (isset($sk_selected_library) && $sk_selected_library && $sk_selected_library !== -1 && $sk_selected_library !== '-1') {
40
+ $data = array('domainName' => $domain . '/' . $path, 'productId' => $sk_selected_library);
41
+ } elseif (isset($sk_subscription_id) && intval($sk_subscription_id)) {
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');
80
+ delete_option('sk_activation_id');
81
+ restore_current_blog();
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(){
99
+ if (defined('SK_AFFILIATE_ID')) {
100
+ $affiliate_id = intval(SK_AFFILIATE_ID);
101
+ } else if (get_option( "sk_affiliate_id")){
102
+ $affiliate_id = intval(get_option( "sk_affiliate_id"));
103
+ } else {
104
+ $affiliate_id = '';
105
+ }
106
+ return $affiliate_id;
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;
124
+ if (isset($blog->user_id)) {
125
+ $userId = $blog->user_id;
126
+ }
127
 
128
+ $this->activate($blog->blog_id, $userId, $blog->domain, $blog->path);
129
+ }
 
 
 
 
 
 
 
 
 
130
 
131
+ die();
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
+
304
+ if ($noCache || false === ($blogs = get_transient('sk_blog_list'))) {
305
+ $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
306
+ FROM $wpdb->blogs
307
+ WHERE spam = '%d' AND deleted = '%d'
308
+ "
309
+ , 0, 0));
310
+ set_transient('sk_blog_list', $blogs, 24 * HOUR_IN_SECONDS);
311
+ }
312
+
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);
338
+ $sk_activation_id = get_option('sk_activation_id');
339
+ if ($sk_activation_id) {
340
+ $activeList[] = $blog_id;
341
+ }
342
+ restore_current_blog();
343
+ }
344
+ die(json_encode($activeList));
345
+ }
346
+
347
+ function admin_page() {
348
+ if (isset($_POST['sk_account'])) {
349
+
350
+ delete_option('sk_auto_activation_error');
351
+
352
+ if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
353
+ $key = 'hash';
354
+ $string = $_POST['sk_password'];
355
+
356
+ $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
357
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
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'])) {
366
+ update_option('sk_auto_activations', true);
367
+ } else {
368
+ delete_option('sk_auto_activations');
369
+ }
370
+
371
+ if (isset($_POST['sk_selected_library'])) {
372
+ update_option('sk_selected_library', $_POST['sk_selected_library']);
373
+ }
374
+
375
+ }
376
+
377
+ if (!$sk_token = get_transient('sk_token')) {
378
+ $login_status = $this->login();
379
+ }
380
+
381
+ $sk_subs = $this->load_subscriptions();
382
+ $user_data = $this->load_user_data();
383
+ $sk_auto_activations = get_option('sk_auto_activations');
384
+ $sk_auto_activation_error = get_option('sk_auto_activation_error');
385
+ $sk_subscription_id = get_option('sk_subscription_id');
386
+ $sk_selected_library = get_option('sk_selected_library');
387
+ $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
388
+ $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
389
+ $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
390
+ $is_ms_admin = true;
391
+ $affiliate_id = $this->getAffiliateId();
392
+ $all_sites = $this->get_blogs(true);
393
+
394
+ require_once('ms_admin_page.php');
395
+ }
396
+ }
397
  }
398
 
399
  // //licensing.php
libs/ms_admin_page.php CHANGED
@@ -4,8 +4,9 @@
4
  if (typeof ajax_url === 'undefined') {
5
  ajax_url = '<?php echo admin_url() ?>admin-ajax.php';
6
  }
7
- var last_site_key = null;
8
- var sk_ms_admin = true;
 
9
 
10
  </script>
11
 
@@ -129,7 +130,7 @@
129
  <tr>
130
  <th></th>
131
  <td><?php submit_button('Update'); ?>
132
- <p>**Please make sure you click the update button above before activating any network websites below.</p>
133
  </td>
134
  </tr>
135
  </tbody>
@@ -144,49 +145,28 @@
144
  <div class="well">
145
  <h3>Sidekick Network Activations</h3>
146
 
147
- <div class='stats'>
148
- <div class='active' onclick='load_sites_by_status("active",this)'>
149
- <i>></i>
150
- <h3>0</h3>
151
- <span>Active</span>
152
- </div>
153
- <div class='unactivated' onclick='load_sites_by_status("unactivated",this)'>
154
- <i>></i>
155
- <h3>0</h3>
156
- <span>Unactivated</span>
157
- </div>
158
- <div class='deactivated' onclick='load_sites_by_status("deactivated",this)'>
159
- <i>></i>
160
- <h3>0</h3>
161
- <span>Deactivated</span>
162
- </div>
163
- </div>
164
-
165
  <div class="status">
166
 
167
  </div>
168
 
169
- <h2><span>Loading...</span><button class='activate_all'>Activate All<div class="spinner"></div></button></h2>
170
-
171
- <div class='action'>
172
- <div class="pagination">
173
- <button class='prev'>Prev</button>
174
- <span>Showing <span class="start">1</span>/<span class='end'>1</span></span>
175
- <button class='next'>Next</button>
176
- </div>
177
- <div class="filter">
178
- <!-- <input type='text' placeholder='Find'> -->
179
- </div>
180
- </div>
181
 
182
  <div class="single_activation_error red"></div>
183
 
184
  <div class="site_list">
185
- Loading...
 
 
186
  </div>
187
 
188
- <button class='reset_all'>Reset All<div class="spinner"></div></button>
189
-
190
  </div>
191
  </div>
192
 
4
  if (typeof ajax_url === 'undefined') {
5
  ajax_url = '<?php echo admin_url() ?>admin-ajax.php';
6
  }
7
+ var last_site_key = null;
8
+ var sk_ms_admin = true;
9
+ var paginationSize = <?php echo $this->sites_per_page ?>;
10
 
11
  </script>
12
 
130
  <tr>
131
  <th></th>
132
  <td><?php submit_button('Update'); ?>
133
+ <p>**Please make sure you click the update button above before activating any network websites below.</p>
134
  </td>
135
  </tr>
136
  </tbody>
145
  <div class="well">
146
  <h3>Sidekick Network Activations</h3>
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  <div class="status">
149
 
150
  </div>
151
 
152
+ <h2>
153
+ <button class='activate_all'>Activate All<div class="spinner"></div></button>
154
+ <?php if ($this->sites_per_page < count($all_sites)): ?>
155
+ <div class="pagination">
156
+ <button class='prev'>Prev</button>
157
+ <button class='next'>Next</button>
158
+ </div>
159
+ <?php endif ?>
160
+ </h2>
 
 
 
161
 
162
  <div class="single_activation_error red"></div>
163
 
164
  <div class="site_list">
165
+ <?php foreach ($all_sites as $key => $site): ?>
166
+ <div class="site <?php if ($key >= $this->sites_per_page): ?>hidden<?php endif ?>" data-path="<?php echo $site->path ?>" data-domain="<?php echo $site->domain ?>" data-blogid="<?php echo $site->blog_id ?>"> <?php echo "{$site->domain}{$site->path}" ?> <button class="checking">Checking Status...<div class="spinner"></div></button></div>
167
+ <?php endforeach ?>
168
  </div>
169
 
 
 
170
  </div>
171
  </div>
172
 
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.4
8
  License: GNU Version 2 or Any Later Version
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -149,6 +149,9 @@ We read and respond to every piece of feedback we get.
149
 
150
  == Changelog ==
151
 
 
 
 
152
  = 2.6.4 =
153
  * Added ability to reset activation keys for a full multisite network
154
 
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
 
150
  == Changelog ==
151
 
152
+ = 2.6.5 =
153
+ * Performance improvements to multisite activation screens (Thank You Michael @mgyura)
154
+
155
  = 2.6.4 =
156
  * Added ability to reset activation keys for a full multisite network
157
 
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.4
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.4'));
28
  }
29
 
30
  function enqueue_required(){
@@ -52,16 +52,16 @@ if (!class_exists('Sidekick')){
52
  }
53
 
54
  function activate($return = false){
55
- mlog("activate");
56
  if (isset($_POST['activation_id']) && current_user_can('install_plugins')) {
57
- mlog("activate2");
58
  update_option('sk_activation_id',$_POST['activation_id']);
59
  return true;
60
  }
61
  }
62
 
63
  function upgrade(){
64
- mlog("upgrade");
65
 
66
  if (!isset($_POST['authorization']) || !wp_verify_nonce($_POST['authorization'], 'sk_upgrade')) {
67
  die('-1');
@@ -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.4', // 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.4');
353
 
354
  if(array_key_exists('callback', $_GET)){
355
 
@@ -461,13 +461,11 @@ if (!class_exists('Sidekick')){
461
  add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
462
  add_action('wp_ajax_sk_deactivate_single', array($sidekickMassActivator,'deactivate_single'));
463
  add_action('wp_ajax_sk_activate_batch', array($sidekickMassActivator,'activate_batch'));
464
- add_action('wp_ajax_sk_load_sites_by_status', array($sidekickMassActivator,'load_sites_by_status'));
465
- add_action('wp_ajax_sk_reset', array($sidekickMassActivator,'resetCacheAndClearActivationIDs'));
466
 
467
  $sk_auto_activations = get_option( 'sk_auto_activations');
468
  if ($sk_auto_activations) {
469
  add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
470
- add_action('sk_hourly_event',array($sidekickMassActivator,'schedule'),10,6);
471
  }
472
  }
473
  }
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
 
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(){
52
  }
53
 
54
  function activate($return = false){
55
+ // mlog("activate");
56
  if (isset($_POST['activation_id']) && current_user_can('install_plugins')) {
57
+ // mlog("activate2");
58
  update_option('sk_activation_id',$_POST['activation_id']);
59
  return true;
60
  }
61
  }
62
 
63
  function upgrade(){
64
+ // mlog("upgrade");
65
 
66
  if (!isset($_POST['authorization']) || !wp_verify_nonce($_POST['authorization'], 'sk_upgrade')) {
67
  die('-1');
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
  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
 
461
  add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
462
  add_action('wp_ajax_sk_deactivate_single', array($sidekickMassActivator,'deactivate_single'));
463
  add_action('wp_ajax_sk_activate_batch', array($sidekickMassActivator,'activate_batch'));
464
+ add_action('wp_ajax_sk_check_batch_status', array($sidekickMassActivator,'check_batch_status'));
 
465
 
466
  $sk_auto_activations = get_option( 'sk_auto_activations');
467
  if ($sk_auto_activations) {
468
  add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
 
469
  }
470
  }
471
  }