Sidekick - Version 2.3.0

Version Description

  • Revamp of multisite activation screen and optimizations for activations on large networks
  • Added config options for disabling the composer, configuration buttons in the taskbar
  • Added config option for disabling the "Create your own walkthroughs" message in the drawer
  • Added caching options to db queries (Thank You Joost - @yoast)
  • Changed over from custom cURL requests to utulize wp_remote_post
Download this release

Release Info

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

Code changes from version 2.2.4 to 2.3.0

js/sidekick_admin.js CHANGED
@@ -3,7 +3,204 @@
3
  var currently_disabled_wts;
4
  var currently_disabled_network_wts;
5
  var lastTimeout;
6
- var loadCount = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  function sk_populate(data){
9
 
@@ -40,7 +237,7 @@ function sk_populate(data){
40
 
41
  // Clear out disabled wts so that compatibility doesn't screen out wts from this screen. Put it back after we're done.
42
 
43
- console.groupCollapsed('Checking Compatibilities');
44
 
45
  _.each(data.payload.buckets,function(bucket,key){
46
 
@@ -68,7 +265,7 @@ function sk_populate(data){
68
  return;
69
  }
70
 
71
- if (sidekick.compatibilityModel.check_compatiblity_array(this.all_walkthroughs[key]) || (typeof sk_ms_admin !== 'undefined' && sk_ms_admin)){
72
  // Only check compatibilities for single sites not network admin page
73
  pass = true;
74
  }
@@ -97,7 +294,7 @@ function sk_populate(data){
97
 
98
  jQuery('.configure').show(); //
99
 
100
- console.groupEnd();//
101
 
102
  } else { //
103
  jQuery('#' + this.cacheId).remove();
@@ -108,6 +305,8 @@ function sk_populate(data){
108
  }); //
109
  } //
110
 
 
 
111
  function setup_events(){
112
  // console.log('setup_events');
113
 
@@ -147,6 +346,8 @@ function sk_populate(data){
147
 
148
  function load_sk_library($key){
149
 
 
 
150
  // console.log('BBBB load_sk_library %o', $key);
151
  var sk_url;
152
 
@@ -198,6 +399,14 @@ function sk_populate(data){
198
  return;
199
  }
200
 
 
 
 
 
 
 
 
 
201
  if (typeof sk_ms_admin !== 'undefined' && sk_ms_admin) {
202
 
203
  // Multisite
@@ -213,20 +422,20 @@ function sk_populate(data){
213
  jQuery('.activate_sk').click(function(){
214
 
215
  clicked_button = this;
216
- jQuery('.single_activation_error').html('');
217
 
218
  var data = {
219
  action: 'sk_activate_single',
220
- blog_id: jQuery(this).data('blogid'),
221
- user_id: jQuery(this).data('userid'),
222
- domain: jQuery(this).data('domain'),
223
- path: jQuery(this).data('path')
224
  };
225
 
226
  jQuery.post(ajaxurl, data, function(e){
227
 
228
  if (!e.success) {
229
- jQuery('.single_activation_error').html(e.message);
230
  jQuery(clicked_button).parent().html('- <span class="not_active">Error Activating</span>');
231
  } else if (e.success) {
232
  jQuery(clicked_button).parent().html('- <span class="green">Activated</span>');
@@ -235,18 +444,20 @@ function sk_populate(data){
235
 
236
  });
237
 
238
- if (jQuery('select[name="sk_selected_subscription"]').val().indexOf('roduct') > -1) {
239
- jQuery('.walkthrough_library').show();
240
- }
241
 
242
- jQuery('select[name="sk_selected_subscription"]').on('change',function(){
243
- if (jQuery('select[name="sk_selected_subscription"]').val().indexOf('roduct') > -1) {
244
- jQuery('.walkthrough_library').show();
245
- } else {
246
- jQuery('.walkthrough_library').val(0);
247
- jQuery('.walkthrough_library').hide();
248
- }
249
- });
 
 
 
 
 
250
 
251
  } else {
252
  jQuery(document).ready(function($) {
3
  var currently_disabled_wts;
4
  var currently_disabled_network_wts;
5
  var lastTimeout;
6
+ var loadCount = 0;
7
+ var lastLoadedStatus = null;
8
+ var loadOffset = 0;
9
+ var maxLoadOffset = null;
10
+ var activated = 0;
11
+ var unactivated_count = 0;
12
+
13
+ function load_sites_by_status(status,target){
14
+
15
+ activated = 0;
16
+
17
+ if (status) {
18
+ lastLoadedStatus = status;
19
+ } else {
20
+ status = lastLoadedStatus;
21
+ }
22
+
23
+ jQuery('.stats>div').removeClass('selected');
24
+ jQuery('.stats .' + status).addClass('selected');
25
+ jQuery('.sites h2 span').html(status + ' site list');
26
+
27
+ if (parseInt(jQuery(target).find('h3').html(),10) === 0) {
28
+ jQuery('.site_list').html('<div class="site">No Sites</div>');
29
+ jQuery('.sites .action').hide();
30
+ return false;
31
+ } else {
32
+ jQuery('.sites .action').show();
33
+ }
34
+
35
+ var data = {
36
+ action: 'sk_load_sites_by_status',
37
+ status: status,
38
+ offset: (loadOffset) ? loadOffset : 0
39
+ };
40
+
41
+ // console.log('data %o', data);
42
+ jQuery('.site_list .site').fadeTo('fast',0.5);
43
+
44
+
45
+ jQuery.post(ajaxurl, data, function(e,msg){
46
+
47
+ // console.log('back %o', e);
48
+
49
+ jQuery('.site_list').html('');
50
+
51
+
52
+
53
+ jQuery('.pagination .start').html(loadOffset+1);
54
+ jQuery('.pagination .end').html(e.pages);
55
+
56
+ jQuery('.stats .unactivated h3').html(e.counts.unactivated);
57
+ jQuery('.stats .active h3').html(e.counts.active);
58
+ jQuery('.stats .deactivated h3').html(e.counts.deactivated);
59
+
60
+ var button = '<button class="activate">Activate</button></div>';
61
+
62
+ if (lastLoadedStatus == 'active') {
63
+ button = '<button class="deactivate">Deactivate</button></div>';
64
+ }
65
+
66
+ if (e.sites) {
67
+ _.each(e.sites,function(site,key){
68
+ 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);
69
+ });
70
+ } else {
71
+ jQuery('.site_list').append('<div class="site">No Sites</div>');
72
+ }
73
+
74
+
75
+ setup_buttons();
76
+
77
+ },'json');
78
+ }
79
+
80
+ function setup_buttons(){
81
+ // console.log('setup_buttons');
82
+ setup_buttons_next_prev();
83
+ setup_buttons_activate();
84
+ setup_buttons_deactivate();
85
+ setup_buttons_activate_batch();
86
+ }
87
+
88
+ function setup_buttons_deactivate(){
89
+ jQuery('.site button.deactivate').off('click').click(function(){
90
+ window.open('https://www.sidekick.pro/profile/#/overview','_blank');
91
+ });
92
+ }
93
+
94
+ function setup_buttons_next_prev(){
95
+
96
+ jQuery('.pagination .next').off('click').click(function(){
97
+ // jQuery('.site_list').html('Loading...');
98
+ jQuery('.pagination .prev').show();
99
+
100
+ loadOffset = loadOffset + 1;
101
+ load_sites_by_status(null,loadOffset);
102
+
103
+ if (loadOffset === parseInt(jQuery('.pagination .end').html(),10)-1) {
104
+ jQuery('.pagination .next').hide();
105
+ }
106
+
107
+ });
108
+
109
+ jQuery('.pagination .prev').off('click').click(function(){
110
+ // jQuery('.site_list').html('Loading...');
111
+ jQuery('.pagination .next').show();
112
+
113
+ loadOffset = loadOffset - 1;
114
+ load_sites_by_status(null,loadOffset);
115
+
116
+ if (loadOffset === 0) {
117
+ jQuery('.pagination .prev').hide();
118
+ }
119
+ });
120
+ }
121
+
122
+ function setup_buttons_activate_batch(){
123
+ jQuery('.activate_all').off('click').click(function(){
124
+
125
+ var data = {
126
+ action: 'sk_activate_batch'
127
+ };
128
+
129
+ if (activated > 0) {
130
+ var activated_perc = Math.round((activated/unactivated_count)*100,0);
131
+ jQuery(this).html('Activating... ' + activated_perc + '%').addClass('loading');
132
+ } else {
133
+ jQuery(this).html('Activating...').addClass('loading');
134
+ }
135
+
136
+ jQuery.post(ajaxurl, data, function(e){
137
+
138
+ activated += parseInt(e.activated_count,10);
139
+ unactivated_count = parseInt(e.unactivated_count,10);
140
+
141
+ updateStatCounts(parseInt(e.activated_count,10));
142
+ if (parseInt(e.activated_count,10) === parseInt(e.sites_per_page,10)) {
143
+ jQuery('.activate_all').trigger('click');
144
+ } else {
145
+ jQuery(this).html('Done').removeClass('loading');
146
+ }
147
+
148
+ },'json');
149
+
150
+ });
151
+ }
152
+
153
+ function setup_buttons_activate(){
154
+ jQuery('.site button.activate').off('click').click(function(){
155
+ // console.log('activate');
156
+
157
+ var data = {
158
+ action: 'sk_activate_single',
159
+ blog_id: jQuery(this).parent().data('blogid'),
160
+ user_id: jQuery(this).parent().data('userid'),
161
+ domain: jQuery(this).parent().data('domain'),
162
+ path: jQuery(this).parent().data('path')
163
+ };
164
+
165
+ jQuery(this).html('Activating...');
166
+ jQuery('.single_activation_error').html('').hide();
167
+
168
+ // console.log('data %o', data);
169
+
170
+
171
+ jQuery.post(ajaxurl, data, activateCallback(this),'json');
172
+
173
+ });
174
+ }
175
+
176
+ var activateCallback = function(button){
177
+ return function(e){
178
+
179
+ // console.log('activateCallback back e %o', e);
180
+
181
+ if (!e.success) {
182
+ jQuery(button).html('Error').addClass('red');
183
+ if (e.payload.message == 'Already Activated') {
184
+ updateStatCounts();
185
+ }
186
+ jQuery('.single_activation_error').html(e.payload.message).show();
187
+ } else if (e.success) {
188
+ updateStatCounts();
189
+ jQuery(button).html('Success').addClass('green');
190
+ }
191
+ };
192
+ };
193
+
194
+ function updateStatCounts(increment){
195
+
196
+ var default_increment = 1;
197
+ if (increment) {
198
+ default_increment = increment;
199
+ }
200
+
201
+ jQuery('h3','div.' + lastLoadedStatus).html(parseInt(jQuery('h3','div.' + lastLoadedStatus).html(),10)-default_increment);
202
+ jQuery('h3','div.active').html(parseInt(jQuery('h3','div.active').html(),10)+default_increment);
203
+ }
204
 
205
  function sk_populate(data){
206
 
237
 
238
  // Clear out disabled wts so that compatibility doesn't screen out wts from this screen. Put it back after we're done.
239
 
240
+ // console.groupCollapsed('Checking Compatibilities');
241
 
242
  _.each(data.payload.buckets,function(bucket,key){
243
 
265
  return;
266
  }
267
 
268
+ if (typeof sidekick !== 'undefined' && sidekick.compatibilityModel.check_compatiblity_array(this.all_walkthroughs[key]) || (typeof sk_ms_admin !== 'undefined' && sk_ms_admin)){
269
  // Only check compatibilities for single sites not network admin page
270
  pass = true;
271
  }
294
 
295
  jQuery('.configure').show(); //
296
 
297
+ // console.groupEnd();//
298
 
299
  } else { //
300
  jQuery('#' + this.cacheId).remove();
305
  }); //
306
  } //
307
 
308
+
309
+
310
  function setup_events(){
311
  // console.log('setup_events');
312
 
346
 
347
  function load_sk_library($key){
348
 
349
+ // TODO we need to switch based on library to distribute and load the right library
350
+
351
  // console.log('BBBB load_sk_library %o', $key);
352
  var sk_url;
353
 
399
  return;
400
  }
401
 
402
+ jQuery('.open_composer').click(function(e){
403
+ e.preventDefault();
404
+ jQuery('#toggle_composer').trigger('click');
405
+ });
406
+
407
+ load_sites_by_status('unactivated');
408
+ // return;
409
+
410
  if (typeof sk_ms_admin !== 'undefined' && sk_ms_admin) {
411
 
412
  // Multisite
422
  jQuery('.activate_sk').click(function(){
423
 
424
  clicked_button = this;
425
+ jQuery('.single_activation_error').html('').hide();
426
 
427
  var data = {
428
  action: 'sk_activate_single',
429
+ blog_id: jQuery(this).parent().data('blogid'),
430
+ user_id: jQuery(this).parent().data('userid'),
431
+ domain: jQuery(this).parent().data('domain'),
432
+ path: jQuery(this).parent().data('path')
433
  };
434
 
435
  jQuery.post(ajaxurl, data, function(e){
436
 
437
  if (!e.success) {
438
+ jQuery('.single_activation_error').html(e.message).show();
439
  jQuery(clicked_button).parent().html('- <span class="not_active">Error Activating</span>');
440
  } else if (e.success) {
441
  jQuery(clicked_button).parent().html('- <span class="green">Activated</span>');
444
 
445
  });
446
 
 
 
 
447
 
448
+
449
+ // if (jQuery('select[name="sk_selected_subscription"]').val().indexOf('roduct') > -1) {
450
+ // jQuery('.walkthrough_library').show();
451
+ // }
452
+
453
+ // jQuery('select[name="sk_selected_subscription"]').on('change',function(){
454
+ // if (jQuery('select[name="sk_selected_subscription"]').val().indexOf('roduct') > -1) {
455
+ // jQuery('.walkthrough_library').show();
456
+ // } else {
457
+ // jQuery('.walkthrough_library').val(0);
458
+ // jQuery('.walkthrough_library').hide();
459
+ // }
460
+ // });
461
 
462
  } else {
463
  jQuery(document).ready(function($) {
libs/admin_page.php CHANGED
@@ -47,7 +47,7 @@
47
  <tbody>
48
  <tr valign="top">
49
  <th scope="row" valign="top">Activation ID</th>
50
- <?php if (defined('MULTISITE') && MULTISITE): ?>
51
  <?php if (isset($activation_id) && $activation_id): ?>
52
  <td><input class='regular-text' style='color: gray;' type='text' name='activation_id' value='xxxxxxxx-xxxx-xxxx-xxxx-<?php echo substr($activation_id, 25,20) ?>'></input></td>
53
  <?php else: ?>
@@ -74,13 +74,12 @@
74
  </td>
75
  </tr>
76
 
77
- <tr valign="top" style='display: none'>
78
  <th scope="row" valign="top">
79
  Enable Composer Mode
80
  </th>
81
  <td>
82
- <input name="sk_composer_button" type="checkbox" <?php if (get_option('sk_composer_button')): ?>CHECKED<?php endif ?> />
83
- <label class="description" for="track_data">Enable Walkthrough creation.</label>
84
  </td>
85
  </tr>
86
  </tbody>
@@ -92,7 +91,7 @@
92
  </div>
93
  </div>
94
 
95
- <div class="sk_box composer">
96
  <div class="well">
97
  <h3>Build Your Own Walkthroughs</h3>
98
  <a href='http://www.sidekick.pro/plans/create_wp_walkthroughs/?utm_source=plugin&utm_medium=settings&utm_campaign=composer' target='_blank'><div class='composer_beta_button'>Build Your Own<br/>Walkthroughs</div></a>
47
  <tbody>
48
  <tr valign="top">
49
  <th scope="row" valign="top">Activation ID</th>
50
+ <?php if (is_multisite()): ?>
51
  <?php if (isset($activation_id) && $activation_id): ?>
52
  <td><input class='regular-text' style='color: gray;' type='text' name='activation_id' value='xxxxxxxx-xxxx-xxxx-xxxx-<?php echo substr($activation_id, 25,20) ?>'></input></td>
53
  <?php else: ?>
74
  </td>
75
  </tr>
76
 
77
+ <tr valign="top">
78
  <th scope="row" valign="top">
79
  Enable Composer Mode
80
  </th>
81
  <td>
82
+ <button class='open_composer'>Open Composer</button>
 
83
  </td>
84
  </tr>
85
  </tbody>
91
  </div>
92
  </div>
93
 
94
+ <div class="sk_box composer" style='display: none'>
95
  <div class="well">
96
  <h3>Build Your Own Walkthroughs</h3>
97
  <a href='http://www.sidekick.pro/plans/create_wp_walkthroughs/?utm_source=plugin&utm_medium=settings&utm_campaign=composer' target='_blank'><div class='composer_beta_button'>Build Your Own<br/>Walkthroughs</div></a>
libs/licensing.php CHANGED
@@ -4,296 +4,480 @@
4
 
5
  if (!class_exists('sidekickMassActivator')) {
6
 
7
- class sidekickMassActivator{
8
 
9
- function activate($blog_id, $user_id, $domain, $path){
10
- // mlog('FUNCTION: activate');
11
-
12
- $sk_auto_activations = get_option( 'sk_auto_activations');
13
-
14
- if ($sk_auto_activations) {
15
-
16
- $user = get_user_by('id',$user_id);
17
- $email = ($user) ? $user->user_email : 'unknown';
18
-
19
- // TODO: Send Domain for good measure
20
-
21
- $sk_selected_subscription = get_option("sk_selected_subscription");
22
- $sk_selected_product = get_option("sk_selected_product");
23
-
24
- if (isset($sk_selected_product) && $sk_selected_product) {
25
- $data = array('domainName' => $domain . $path, 'productId' => $sk_selected_product);
26
- } else if (strpos($sk_selected_subscription,'subscription-') !== false) {
27
- $sk_selected_subscription = explode('subscription-',$sk_selected_subscription);
28
- $data = array('domainName' => $domain . $path, 'subscriptionId' => $sk_selected_subscription[1]);
29
- }
30
-
31
- $result = $this->send_request('post','/domains',$data);
32
-
33
- if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
34
-
35
- if (!get_option('sk_activation_id')) {
36
- // Use the first site's activation key for the network key
37
- update_option('sk_activation_id',$result->payload->domainKey);
38
- }
39
-
40
- switch_to_blog($blog_id);
41
- update_option('sk_activation_id',$result->payload->domainKey);
42
- update_option('sk_email',$email);
43
- restore_current_blog();
44
-
45
- $this->track('Mass Activate',array('domain' => $domain,'email' => $email));
46
-
47
- delete_option('sk_auto_activation_error');
48
- } else {
49
-
50
- $this->track('Mass Activate Error',array('domain' => $domain, 'message' => $result->message,'email' => $email));
51
- update_option('sk_auto_activation_error',$result->message);
52
- wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
53
- }
54
- return $result;
55
- }
56
- return false;
57
- }
58
-
59
- function track($event,$data){
60
- if (file_exists(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php')) {
61
- require_once(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php');
62
- $mp = Mixpanel::getInstance("965556434c5ae652a44f24b85b442263");
63
- $domain = str_replace("http://","",$_SERVER["SERVER_NAME"]);
64
-
65
- $mp->track($event, $data);
66
- }
67
- }
68
-
69
- function activate_single(){
70
- die(json_encode($this->activate($_POST['blog_id'], $_POST['user_id'], $_POST['domain'], $_POST['path'])));
71
- }
72
-
73
- function send_request_curl($url, $post){
74
- $ch = curl_init($url);
75
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
76
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
77
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
78
- curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($post));
79
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
80
- $result = curl_exec($ch);
81
- curl_close($ch);
82
- return $result;
83
- }
84
-
85
- function send_request($type,$end_point, $data = null,$second_attempt = null){
86
- // var_dump('send_request');
87
- //var_dump("FUNCTION: send_request");
88
-
89
- if (strpos($_SERVER['SERVER_PROTOCOL'], 'https') === false) {
90
- $protocol = 'http:';
91
- } else {
92
- $protocol = 'https:';
93
- }
94
-
95
- $url = $protocol . SK_API . $end_point;
96
- $sk_token = get_transient('sk_token');
97
-
98
- if (!$sk_token && $end_point !== '/login') {
99
- $this->login();
100
- $sk_token = get_transient('sk_token');
101
- }
102
-
103
- $headers = array('Content-Type:application/json');
104
-
105
- if ($sk_token && $end_point !== '/login') {
106
- $headers[] = "Authorization: $sk_token";
107
- }
108
-
109
- $ch = curl_init($url);
110
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($type));
111
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
112
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
113
- if ($data) {
114
- curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));
115
- }
116
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
117
- $result = curl_exec($ch);
118
- curl_close($ch);
119
-
120
- // echo $result; var_dump($url); var_dump($headers); var_dump($data); var_dump($result); die();
121
-
122
- if ($result == 'HTTP/1.1 401 Unauthorized' && !$second_attempt) {
123
- // var_dump('Getting rid of token and trying again');
124
- $this->login();
125
- delete_transient('sk_token');
126
- $this->send_request('post',$type,$data,true);
127
- }
128
-
129
- return json_decode($result);
130
- }
131
-
132
- function setup_menu(){
133
- add_submenu_page( 'settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins','sidekick-licensing', array(&$this,'admin_page'));
134
- }
135
-
136
- function login(){
137
- global $login_error;
138
-
139
- $email = get_option('sk_account');
140
- $password = get_option('sk_password');
141
- delete_option('sk_auto_activation_error');
142
-
143
- if (!$password || !$email) {
144
- return false;
145
- }
146
-
147
- $string = $password;
148
- $key = 'hash';
149
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
150
-
151
- $result = $this->send_request('post','/login',array('email' => $email, 'password' => $decrypted_password));
152
-
153
- if (!isset($result) || !$result->success) {
154
- delete_option( 'sk_token' );
155
- return array('error' => $result->message);
156
- } else {
157
- set_transient( 'sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS );
158
- $this->load_subscriptions($result->payload->token->value);
159
- return array('success' => true);
160
- }
161
- }
162
-
163
- function load_user_data(){
164
- return $this->send_request('get','/users/');
165
- }
166
-
167
- function load_subscriptions(){
168
-
169
- $result = $this->send_request('get','/users/subscriptions');
170
- $load_products = false;
171
-
172
- if (isset($result->success) && isset($result->payload)) {
173
-
174
- $sub = $result->payload[0];
175
-
176
- if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
177
- $this->logout();
178
- update_option( 'sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
179
- return false;
180
- } if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Private') {
181
- update_option( 'sk_selected_subscription', 'product-' . $sub->id );
182
- } else {
183
- update_option( 'sk_selected_subscription', 'subscription-' . $sub->id );
184
- }
185
-
186
- if (isset($sub->Plan->CreatableProductType) && isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') {
187
- $load_products = true;
188
- }
189
-
190
- if (count($sub->Domains) > 0) {
191
- foreach ($sub->Domains as &$domain) {
192
- if (!$domain->DomainSubscription->end) {
193
- if (isset($sub->activeDomainCount)) {
194
- $sub->activeDomainCount++;
195
- } else {
196
- $sub->activeDomainCount = 1;
197
- }
198
- }
199
- }
200
- } if (count($sub->PrivateProductSubscriptions) > 0) {
201
- foreach ($sub->PrivateProductSubscriptions as &$domain) {
202
- if (isset($sub->activeDomainCount)) {
203
- $sub->activeDomainCount++;
204
- } else {
205
- $sub->activeDomainCount = 1;
206
- }
207
- }
208
- } else {
209
- $sub->activeDomainCount = 0;
210
- }
211
-
212
- $data['subscriptions'] = $result->payload;
213
-
214
- if ($load_products) {
215
- $data['products'] = $this->load_products();
216
- }
217
-
218
- return $data;
219
- } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
220
- $this->logout();
221
- update_option( 'sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
222
- }
223
- return null;
224
- }
225
-
226
- function logout(){
227
- delete_option( 'sk_account');
228
- delete_option( 'sk_password');
229
- delete_option( 'sk_selected_subscription');
230
- delete_option( 'sk_selected_product');
231
- }
232
-
233
- function load_products(){
234
- $result = $this->send_request('get','/products');
235
- if ($result->success) {
236
- return $result->payload->products;
237
- }
238
- return null;
239
- }
240
-
241
- function admin_page(){
242
- if (isset($_POST['sk_account'])) {
243
-
244
- delete_option('sk_auto_activation_error');
245
-
246
- if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
247
- $key = 'hash';
248
- $string = $_POST['sk_password'];
249
-
250
- $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
251
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
252
-
253
- update_option( 'sk_account', $_POST['sk_account'] );
254
- update_option( 'sk_password', $encrypted_password );
255
- $login_status = $this->login();
256
- delete_option('sk_auto_activation_error');
257
- } else {
258
- update_option( 'sk_selected_subscription', $_POST['sk_selected_subscription'] );
259
- }
260
-
261
- if (isset($_POST['sk_auto_activations'])) {
262
- update_option( 'sk_auto_activations', true );
263
- } else {
264
- delete_option( 'sk_auto_activations');
265
- }
266
-
267
- if (isset($_POST['sk_selected_product']) && $_POST['sk_selected_product'] !== '0' && isset($_POST['sk_selected_subscription']) && strpos($_POST['sk_selected_subscription'], 'product') !== false) {
268
- update_option( 'sk_selected_product', $_POST['sk_selected_product'] );
269
- } else {
270
- delete_option( 'sk_selected_product');
271
- }
272
-
273
- }
274
-
275
- $sk_token = get_transient('sk_token');
276
- if (!$sk_token) {
277
- $login_status = $this->login();
278
- }
279
- $sk_subs = $this->load_subscriptions();
280
- $user_data = $this->load_user_data();
281
- $sk_auto_activations = get_option( 'sk_auto_activations');
282
- $sk_auto_activation_error = get_option('sk_auto_activation_error');
283
- $sk_selected_subscription = get_option('sk_selected_subscription');
284
- $sk_selected_product = get_option('sk_selected_product');
285
- $is_ms_admin = true;
286
- $curl = function_exists('curl_version') ? true : false;
287
- $fgets = file_get_contents(__FILE__) ? true : false;
288
- $fgets_url = ini_get('allow_url_fopen') ? true : false;
289
-
290
- if ($curl && (!$fgets || !$fgets_url)) {
291
- $error = "Sorry, SIDEKICK MultiSite activations require <b>CURL</b> or <b>file_get_contents</b> functions enabled in PHP.";
292
- }
293
-
294
- require_once('ms_admin_page.php');
295
- }
296
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  }
298
 
299
  // //licensing.php
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
+ $this->track('Mass Activate', array('domain' => $domain, 'email' => $email));
66
+
67
+ if (isset($checked_blogs['deactivated'][$blog_id])) {
68
+ $checked_blogs['active'][$blog_id] = $checked_blogs['deactivated'][$blog_id];
69
+ unset($checked_blogs['deactivated'][$blog_id]);
70
+ } else if (isset($checked_blogs['unactivated'][$blog_id])) {
71
+ $checked_blogs['active'][$blog_id] = $checked_blogs['unactivated'][$blog_id];
72
+ unset($checked_blogs['unactivated'][$blog_id]);
73
+ }
74
+
75
+ update_option('sk_checked_blogs', $checked_blogs);
76
+ update_option('sk_last_setup_blog_id', $blog_id);
77
+
78
+ delete_option('sk_auto_activation_error');
79
+ } else {
80
+
81
+ $this->track('Mass Activate Error', array('domain' => $domain, 'message' => $result->message, 'email' => $email));
82
+ update_option('sk_auto_activation_error', $result->message);
83
+ // wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
84
+ wp_mail('bart@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
85
+ }
86
+
87
+ return $result;
88
+
89
+ }
90
+
91
+ function setup_super_admin_key($domainKey) {
92
+ // Use the super admin's site activation key if not set using last activation key
93
+ if (!get_option('sk_activation_id')) {
94
+ update_option('sk_activation_id', $domainKey);
95
+ }
96
+ }
97
+
98
+ function track($event, $data) {
99
+ if (file_exists(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php')) {
100
+ require_once(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php');
101
+ $mp = Mixpanel::getInstance("965556434c5ae652a44f24b85b442263");
102
+ $domain = str_replace("http://", "", $_SERVER["SERVER_NAME"]);
103
+
104
+ $mp->track($event, $data);
105
+ }
106
+ }
107
+
108
+ function activate_batch() {
109
+ $checked_blogs = get_option('sk_checked_blogs');
110
+ $count = 0;
111
+
112
+ if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated'])) {
113
+ foreach ($checked_blogs['unactivated'] as $key => $blog) {
114
+ if ($count == $this->sites_per_page) {
115
+ break;
116
+ }
117
+ $this->activate($blog->blog_id, $blog->user_id, $blog->domain, $blog->path);
118
+ $count++;
119
+ }
120
+ }
121
+ //mlog('$checked_blogs',$checked_blogs);
122
+
123
+ $result = array('activated_count' => $count, 'sites_per_page' => $this->sites_per_page, 'unactivated_count' => count($checked_blogs['unactivated']));
124
+ die(json_encode($result));
125
+ }
126
+
127
+ function activate_single() {
128
+ $result = $this->activate($_POST['blog_id'], $_POST['user_id'], $_POST['domain'], $_POST['path']);
129
+ die(json_encode($result));
130
+ }
131
+
132
+ function deactivate_single() {
133
+
134
+ $checked_blogs = get_option('sk_checked_blogs');
135
+ $blog_id = $_POST['blog_id'];
136
+
137
+ if (isset($checked_blogs['active'][$_POST['blog_id']])) {
138
+ $checked_blogs['deactivated'][$blog_id] = $checked_blogs['active'][$blog_id];
139
+ unset($checked_blogs['active'][$blog_id]);
140
+ update_option('sk_checked_blogs', $checked_blogs);
141
+ die('{"success":1}');
142
+ } else {
143
+ die('{"payload":{"message":"Error #13"}}');
144
+ }
145
+ }
146
+
147
+ function send_request($type, $end_point, $data = null, $second_attempt = null) {
148
+
149
+ // var_dump("FUNCTION: send_request [$type] -> $end_point");
150
+
151
+ if (strpos($_SERVER['SERVER_PROTOCOL'], 'https') === false) {
152
+ $protocol = 'http:';
153
+ } else {
154
+ $protocol = 'https:';
155
+ }
156
+
157
+ $url = $protocol . 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
+ }
186
+
187
+ $result = wp_remote_post($url, $args);
188
+
189
+ if ($result['response']['message'] == 'Unauthorized' && !$second_attempt) {
190
+ // var_dump('Getting rid of token and trying again');
191
+ delete_transient('sk_token');
192
+ $this->login();
193
+
194
+ return $this->send_request($type, $end_point, $data, true);
195
+ }
196
+
197
+ return json_decode($result['body']);
198
+ }
199
+
200
+ function setup_menu() {
201
+ add_submenu_page('settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins', 'sidekick-licensing', array(&$this, 'admin_page'));
202
+ }
203
+
204
+ function login() {
205
+ $email = get_option('sk_account');
206
+ $password = get_option('sk_password');
207
+ delete_option('sk_auto_activation_error');
208
+
209
+ if (!$password || !$email) {
210
+ return false;
211
+ }
212
+
213
+ $key = 'hash';
214
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
215
+
216
+ $result = $this->send_request('post', '/login', array('email' => $email, 'password' => $decrypted_password));
217
+
218
+ if (!isset($result) || !$result->success) {
219
+ delete_option('sk_token');
220
+
221
+ return array('error' => $result->message);
222
+ } else {
223
+ set_transient('sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS);
224
+ // var_dump($result->payload->token->value);
225
+ $this->load_subscriptions($result->payload->token->value);
226
+
227
+ return array('success' => true);
228
+ }
229
+ }
230
+
231
+ function load_user_data() {
232
+ return $this->send_request('get', '/users/');
233
+ }
234
+
235
+ function load_subscriptions() {
236
+
237
+ $result = $this->send_request('get', '/users/subscriptions');
238
+
239
+ if (isset($result->success) && isset($result->payload)) {
240
+
241
+ $sub = $result->payload[0];
242
+
243
+ if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
244
+ $this->logout();
245
+ update_option('sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
246
+
247
+ return false;
248
+ }
249
+
250
+ update_option('sk_subscription_id', $sub->id);
251
+
252
+ $sub->activeDomainCount = 0;
253
+
254
+ if (count($sub->Domains) > 0) {
255
+ foreach ($sub->Domains as &$domain) {
256
+ if (!$domain->end) {
257
+ if (isset($sub->activeDomainCount)) {
258
+ $sub->activeDomainCount++;
259
+ } else {
260
+ $sub->activeDomainCount = 1;
261
+ }
262
+ }
263
+ }
264
+ }
265
+
266
+ $data['subscriptions'] = $result->payload;
267
+ $data['libraries'] = $this->load_libraries();
268
+
269
+ return $data;
270
+ } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
271
+ $this->logout();
272
+ update_option('sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
273
+ }
274
+
275
+ return null;
276
+ }
277
+
278
+ function get_blog_by_id($id) {
279
+ global $wpdb;
280
+
281
+ $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
282
+ FROM $wpdb->blogs
283
+ WHERE blog_id = '%d'
284
+ "
285
+ , $id));
286
+
287
+ return $blogs;
288
+ }
289
+
290
+ function get_blogs() {
291
+ global $wpdb;
292
+
293
+ if (false === ($blogs = get_transient('sk_blog_list'))) {
294
+ $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
295
+ FROM $wpdb->blogs
296
+ WHERE spam = '%d' AND deleted = '%d'
297
+ "
298
+ , 0, 0));
299
+ set_transient('sk_blog_list', $blogs, 24 * HOUR_IN_SECONDS);
300
+ }
301
+
302
+ return $blogs;
303
+ }
304
+
305
+ function get_unchecked_blogs($blogs, $checked_blogs) {
306
+ $return = array();
307
+
308
+ foreach ($blogs as $key => $blog) {
309
+
310
+ if (isset($checked_blogs['deactivated']) && is_array($checked_blogs['deactivated']) && isset($checked_blogs['deactivated'][$blog->blog_id])) {
311
+ continue;
312
+ }
313
+
314
+ if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated']) && isset($checked_blogs['unactivated'][$blog->blog_id])) {
315
+ continue;
316
+ }
317
+
318
+ if (isset($checked_blogs['active']) && is_array($checked_blogs['active']) && isset($checked_blogs['active'][$blog->blog_id])) {
319
+ continue;
320
+ }
321
+
322
+ $return[$blog->blog_id] = $blog;
323
+ }
324
+
325
+ return $return;
326
+ }
327
+
328
+ function check_statuses() {
329
+ $checked_blogs = get_option('sk_checked_blogs');
330
+ $blogs = $this->get_blogs();
331
+ $unchecked_blogs = $this->get_unchecked_blogs($blogs, $checked_blogs);
332
+ $count = 0;
333
+
334
+ if (!isset($checked_blogs['unactivated'])) {
335
+ $checked_blogs['unactivated'] = array();
336
+ }
337
+
338
+ if (!isset($checked_blogs['active'])) {
339
+ $checked_blogs['active'] = array();
340
+ }
341
+
342
+ if (!isset($checked_blogs['deactivated'])) {
343
+ $checked_blogs['deactivated'] = array();
344
+ }
345
+
346
+ foreach ($unchecked_blogs as $blog) {
347
+
348
+ // if ($count > $this->sites_per_page) {
349
+ // break;
350
+ // }
351
+
352
+ $blog_id = $blog->blog_id;
353
+ $activation_id = null;
354
+ $count++;
355
+
356
+ switch_to_blog($blog_id);
357
+ if ($user = get_user_by('email', get_option('admin_email'))) {
358
+ $blog->user_id = $user->ID;
359
+ }
360
+ $activation_id = get_site_option('sk_activation_id');
361
+ restore_current_blog();
362
+
363
+ if ($activation_id) {
364
+ $status = 'active';
365
+ } elseif (isset($checked_blogs['deactivated']) && in_array($blog_id, $checked_blogs['deactivated'])) {
366
+ $status = 'deactivated';
367
+ } else {
368
+ $status = 'unactivated';
369
+ }
370
+
371
+ $checked_blogs[$status][$blog_id] = $blog;
372
+
373
+ }
374
+
375
+ update_option('sk_checked_blogs', $checked_blogs);
376
+
377
+ return $checked_blogs;
378
+
379
+ }
380
+
381
+ function load_sites_by_status() {
382
+ global $wpdb;
383
+
384
+ $checked_blogs = $this->check_statuses();
385
+ $status = sanitize_text_field($_POST['status']);
386
+ $this->offet = sanitize_text_field($_POST['offset']);
387
+
388
+ if (isset($checked_blogs[$status]) && is_array($checked_blogs[$status])) {
389
+
390
+ $return['sites'] = array_slice($checked_blogs[$status], $this->offet, $this->sites_per_page);
391
+ $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)));
392
+ $return['counts']['active'] = count($checked_blogs['active']);
393
+ $return['counts']['deactivated'] = count($checked_blogs['deactivated']);
394
+ $return['counts']['unactivated'] = intval($return['counts']['all_blogs']) - intval($return['counts']['active']) - $return['counts']['deactivated'];
395
+
396
+
397
+ $currentStatusCount = intval($return['counts'][$status]);
398
+ $return['pages'] = ceil($currentStatusCount / $this->sites_per_page);
399
+
400
+ // $return['counts'][$status] = count($checked_blogs[$status]);
401
+ } else {
402
+ // $return['counts'][$status] = 0;
403
+ $return[$status]['sites'] = array();
404
+ }
405
+
406
+ die(json_encode($return));
407
+ }
408
+
409
+ function logout() {
410
+ delete_option('sk_account');
411
+ delete_option('sk_password');
412
+ delete_option('sk_subscription_id');
413
+ delete_option('sk_selected_library');
414
+ }
415
+
416
+ function load_libraries() {
417
+ $result = $this->send_request('get', '/products');
418
+ if ($result->success) {
419
+ return $result->payload->products;
420
+ }
421
+
422
+ return null;
423
+ }
424
+
425
+ function schedule(){
426
+ if ( ! wp_next_scheduled( array($this,'check_statuses') ) ) {
427
+ wp_schedule_event( time(), 'hourly', array($this,'check_statuses'));
428
+ wp_schedule_event( time(), 'hourly', array($this,'activate_batch'));
429
+ }
430
+
431
+ }
432
+
433
+ function admin_page() {
434
+ if (isset($_POST['sk_account'])) {
435
+
436
+ delete_option('sk_auto_activation_error');
437
+
438
+ if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
439
+ $key = 'hash';
440
+ $string = $_POST['sk_password'];
441
+
442
+ $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
443
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
444
+
445
+ update_option('sk_account', $_POST['sk_account']);
446
+ update_option('sk_password', $encrypted_password);
447
+ $login_status = $this->login();
448
+ delete_option('sk_auto_activation_error');
449
+ }
450
+
451
+ if (isset($_POST['sk_auto_activations'])) {
452
+ update_option('sk_auto_activations', true);
453
+ } else {
454
+ delete_option('sk_auto_activations');
455
+ }
456
+
457
+ if (isset($_POST['sk_selected_library'])) {
458
+ update_option('sk_selected_library', $_POST['sk_selected_library']);
459
+ }
460
+
461
+ }
462
+
463
+ if (!$sk_token = get_transient('sk_token')) {
464
+ $login_status = $this->login();
465
+ }
466
+
467
+ $sk_subs = $this->load_subscriptions();
468
+ $user_data = $this->load_user_data();
469
+ $sk_auto_activations = get_option('sk_auto_activations');
470
+ $sk_auto_activation_error = get_option('sk_auto_activation_error');
471
+ $sk_subscription_id = get_option('sk_subscription_id');
472
+ $sk_selected_library = get_option('sk_selected_library');
473
+ $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
474
+ $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
475
+ $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
476
+ $is_ms_admin = true;
477
+
478
+ require_once('ms_admin_page.php');
479
+ }
480
+ }
481
  }
482
 
483
  // //licensing.php
libs/ms_admin_page.php CHANGED
@@ -8,7 +8,9 @@
8
  var sk_ms_admin = true;
9
 
10
  jQuery(document).ready(function($) {
11
- mixpanel.track('Network Settings Page Visit - Plugin');
 
 
12
  });
13
 
14
  </script>
@@ -74,73 +76,29 @@
74
  <input class='regular-text' type='password' name='sk_password' placeholder='********'></input>
75
  </td>
76
  </tr>
77
- <tr valign="top" style='display: none'>
78
- <th scope="row" valign="top">Subscription</th>
 
79
  <td>
80
- <select name='sk_selected_subscription'>
81
- <?php if (isset($sk_subs['subscriptions']) && count($sk_subs['subscriptions']) > 0): ?>
82
- <?php foreach ($sk_subs['subscriptions'] as $key => $sub): ?>
83
- <?php
84
- if ($sub->PlanId !== 1 && $sub->Plan->CreatableProductType->name !== 'Private') {
85
- continue;
86
- }
87
-
88
- if (isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') {
89
- $type = 'product';
90
- } else {
91
- $type = 'subscription';
92
- }
93
-
94
-
95
- if ($sk_selected_subscription == ($type . '-' . $sub->id) || !isset($selected_sub)) {
96
- $selected_sub = $sub;
97
- $selected = 'SELECTED';
98
- } else {
99
- $selected = '';
100
- }
101
- ?>
102
- <option <?php echo $selected ?> value='<?php echo (isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') ? "product-" : "subscription-"; echo $sub->id ?>'><?php echo $sub->Plan->name . ' - ' . $sub->CurrentTier->name ?></option>
103
  <?php endforeach ?>
104
- <?php if (!isset($selected_sub)): ?>
105
- <option value='0'>No Compatible Subscriptions</option>
106
- <?php endif ?>
107
- <?php else: ?>
108
- <option>No Subscriptions</option>
109
  <?php endif ?>
 
110
  </select>
111
  </td>
112
  </tr>
113
- <?php if (isset($sk_subs['products'])): ?>
114
-
115
- <tr valign="top" style='display: none' class='walkthrough_library'>
116
- <th scope="row" valign="top">Library</th>
117
- <td>
118
- <select name='sk_selected_product'>
119
- <?php if (isset($sk_subs['products']) && count($sk_subs['products']) > 0): ?>
120
- <?php foreach ($sk_subs['products'] as $key => $product): ?>
121
- <option <?php echo ($sk_selected_product == $product->id) ? 'SELECTED' : '' ?> value='<?php echo $product->id ?>'><?php echo $product->name ?></option>
122
- <?php endforeach ?>
123
- <?php else: ?>
124
- <option style='color: red' value='0'>No Libraries Found!</option>
125
- <?php $no_product = true; delete_option( 'sk_auto_activations') ?>
126
- <?php endif ?>
127
- </select>
128
- </td>
129
- </tr>
130
 
131
- <?php endif ?>
132
 
133
  <tr valign="top">
134
  <th scope="row" valign="top">Enable Auto-Activations</th>
135
  <td>
136
- <?php if (!isset($selected_sub) || isset($no_product)): ?>
137
- <input class='checkbox' type='checkbox' name='sk_auto_activations' DISABLED>
138
- <?php else: ?>
139
- <input class='checkbox' type='checkbox' name='sk_auto_activations' <?php echo ($sk_auto_activations) ? 'CHECKED' : '' ?>>
140
- <?php endif ?>
141
  </td>
142
  </tr>
143
- <?php //var_dump($selected_sub); ?>
144
  <?php if (isset($selected_sub) && !isset($no_product)): ?>
145
  <tr>
146
  <th scope="row" valign="top">Active Domains</th>
@@ -185,46 +143,48 @@
185
 
186
  <div class="sk_box sites">
187
  <div class="well">
188
- <h3>Sidekick Network Activations - (<a class='activate_all' href='#'>Activate All</a>)</h3>
189
-
190
- <p>To manage your complete list of domains please login to your <a href='https://www.sidekick.pro/profile/#' target='_blank'>account center</a>.</p>
191
-
192
- <?php $blogs = wp_get_sites(array('limit' => 10000)) ?>
193
- <ul>
194
- <?php foreach ($blogs as $key => $blog): ?>
195
- <?php
196
-
197
- switch_to_blog($blog['blog_id']);
198
-
199
- if ($user = get_user_by('email', get_option('admin_email'))) {
200
- $user_id = $user->ID;
201
- } else {
202
- $user_id = null;
203
- }
204
-
205
- $key = get_option('sk_activation_id');
206
- if ($key) $last_key = $key;
207
-
208
- $turn_on_button = '';
209
-
210
- if (isset($selected_sub)) {
211
- $turn_on_button = "<button class=\"activate_sk\" data-blogid=\"{$blog["blog_id"]}\" data-userid=\"{$user_id}\" data-domain=\"{$blog["domain"]}\" data-path=\"{$blog["path"]}\">Turn On</button>";
212
- }
213
-
214
- ?>
215
-
216
- <li>
217
- <div class='bold'>
218
- <h3><?php echo ucfirst(str_replace('/', '', $blog['path'])) ?></h3>
219
- <?php echo $blog['domain'] . $blog['path'] ?>
220
- <span><?php echo ($key) ? ' - <span class="green">Active</span>' : " - <span class=\"not_active\">Not Activated</span> $turn_on_button" ?></span>
221
- </div>
222
- </li>
223
- <?php endforeach ?>
224
- </ul>
225
 
226
  <div class="single_activation_error red"></div>
227
 
 
 
 
228
 
229
  </div>
230
  </div>
8
  var sk_ms_admin = true;
9
 
10
  jQuery(document).ready(function($) {
11
+ if (typeof mixpanel !== 'undefined') {
12
+ mixpanel.track('Network Settings Page Visit - Plugin');
13
+ };
14
  });
15
 
16
  </script>
76
  <input class='regular-text' type='password' name='sk_password' placeholder='********'></input>
77
  </td>
78
  </tr>
79
+
80
+ <tr valign="top" class='walkthrough_library'>
81
+ <th scope="row" valign="top">Library to Distribute</th>
82
  <td>
83
+ <select name='sk_selected_library'>
84
+ <?php if (isset($sk_subs['libraries']) && count($sk_subs['libraries']) > 0): ?>
85
+ <?php foreach ($sk_subs['libraries'] as $key => $library): ?>
86
+ <option <?php echo ($sk_selected_library == $library->id) ? 'SELECTED' : '' ?> value='<?php echo $library->id ?>'><?php echo $library->name ?></option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  <?php endforeach ?>
 
 
 
 
 
88
  <?php endif ?>
89
+ <option <?php echo ($sk_selected_library == -1) ? 'SELECTED' : '' ?> value='-1'>WordPress Basics Only</option>
90
  </select>
91
  </td>
92
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
94
 
95
  <tr valign="top">
96
  <th scope="row" valign="top">Enable Auto-Activations</th>
97
  <td>
98
+ <input class='checkbox' type='checkbox' name='sk_auto_activations' <?php echo ($sk_auto_activations) ? 'CHECKED' : '' ?>>
 
 
 
 
99
  </td>
100
  </tr>
101
+
102
  <?php if (isset($selected_sub) && !isset($no_product)): ?>
103
  <tr>
104
  <th scope="row" valign="top">Active Domains</th>
143
 
144
  <div class="sk_box sites">
145
  <div class="well">
146
+ <h3>Sidekick Network Activations</h3>
147
+
148
+ <div class='stats'>
149
+ <div class='active' onclick='load_sites_by_status("active",this)'>
150
+ <i>></i>
151
+ <h3>0</h3>
152
+ <span>Active</span>
153
+ </div>
154
+ <div class='unactivated' onclick='load_sites_by_status("unactivated",this)'>
155
+ <i>></i>
156
+ <h3>0</h3>
157
+ <span>Unactivated</span>
158
+ </div>
159
+ <div class='deactivated' onclick='load_sites_by_status("deactivated",this)'>
160
+ <i>></i>
161
+ <h3>0</h3>
162
+ <span>Deactivated</span>
163
+ </div>
164
+ </div>
165
+
166
+ <div class="status">
167
+
168
+ </div>
169
+
170
+ <h2><span>Loading...</span><button class='activate_all'>Activate All<div class="spinner"></div></button></h2>
171
+
172
+ <div class='action'>
173
+ <div class="pagination">
174
+ <button class='prev'>Prev</button>
175
+ <span>Showing <span class="start">1</span>/<span class='end'>1</span></span>
176
+ <button class='next'>Next</button>
177
+ </div>
178
+ <div class="filter">
179
+ <!-- <input type='text' placeholder='Find'> -->
180
+ </div>
181
+ </div>
 
182
 
183
  <div class="single_activation_error red"></div>
184
 
185
+ <div class="site_list">
186
+ Loading...
187
+ </div>
188
 
189
  </div>
190
  </div>
libs/sk_config_data.php CHANGED
@@ -4,6 +4,9 @@
4
  if (!class_exists('sk_config_data')) {
5
 
6
  class sk_config_data{
 
 
 
7
  function get_domain(){
8
  $site_url = get_site_url();
9
  if(substr($site_url, -1) == '/') {
@@ -13,17 +16,26 @@ if (!class_exists('sk_config_data')) {
13
  return $site_url;
14
  }
15
 
 
 
 
16
  function get_post_types(){
17
  global $wpdb;
18
- $query = "SELECT post_type, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type";
19
- $counts = $wpdb->get_results($query);
20
- $output = '';
21
 
22
- foreach ($counts as $key => $type) {
23
- $type->post_type = str_replace('-', '_', $type->post_type);
24
- $output .= "\n post_type_{$type->post_type} : $type->count,";
 
 
 
 
 
 
 
 
25
  }
26
- return $output;
 
27
  }
28
 
29
  function get_file_editor_enabled(){
@@ -40,72 +52,102 @@ if (!class_exists('sk_config_data')) {
40
  }
41
 
42
  function get_themes(){
43
- $themes = wp_get_themes( array( 'allowed' => true ) );
44
- return count($themes);
 
 
 
 
45
  }
46
 
47
  function get_post_types_and_statuses(){
48
  global $wpdb;
49
- $query = "SELECT post_type, post_status, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type, post_status";
50
- $counts = $wpdb->get_results($query);
51
- $output = '';
52
 
53
- foreach ($counts as $key => $type) {
54
- $type->post_type = str_replace('-', '_', $type->post_type);
55
- $type->post_status = str_replace('-', '_', $type->post_status);
 
 
56
 
57
- $output .= "\n post_type_{$type->post_type}_{$type->post_status} : $type->count,";
58
- }
59
- return $output;
 
 
 
 
 
 
 
60
  }
61
 
62
  function get_taxonomies(){
63
  global $wpdb;
64
- $query = "SELECT count(distinct term_taxonomy_id) as count, taxonomy from {$wpdb->prefix}term_taxonomy group by taxonomy";
65
- $counts = $wpdb->get_results($query);
66
- $output = '';
67
 
68
- foreach ($counts as $key => $taxonomy) {
69
- $taxonomy->taxonomy = str_replace('-', '_', $taxonomy->taxonomy);
70
- $output .= "\n taxonomy_{$taxonomy->taxonomy} : $taxonomy->count,";
71
- }
72
- return $output;
 
 
 
 
 
 
 
 
73
  }
74
 
75
  function get_comments(){
76
  global $wpdb;
77
- $query = "SELECT count(distinct comment_ID) as count from {$wpdb->prefix}comments";
78
- $counts = $wpdb->get_var($query);
79
- if (!$counts) $counts = 0;
80
- return "\n comment_count : $counts,";
 
 
 
 
 
 
81
  }
82
 
83
  function get_post_statuses(){
84
  global $wpdb;
85
- $query = "SELECT post_status, count(ID) as count from {$wpdb->prefix}posts group by post_status";
86
- $counts = $wpdb->get_results($query);
87
- $output = '';
88
 
89
- foreach ($counts as $key => $type) {
90
- $type->post_status = str_replace('-', '_', $type->post_status);
91
- $output .= "\n post_status_{$type->post_status} : $type->count,";
 
 
 
 
 
 
 
92
  }
93
- return $output;
 
94
  }
95
 
96
  function get_user_data(){
97
  global $current_user;
98
 
99
- $data = get_userdata($current_user->ID);
100
- $output = "\n user_id : $current_user->ID,";
 
101
 
102
- foreach ($data->allcaps as $cap => $val) {
103
- $cap = sanitize_title($cap);
104
- $cap = str_replace('-', '_', $cap);
105
- if (!$val) $val = 0;
106
- $output .= "\n cap_{$cap} : $val,";
 
 
107
  }
108
- return $output;
 
109
  }
110
 
111
  function get_framework(){
@@ -164,26 +206,30 @@ if (!class_exists('sk_config_data')) {
164
 
165
  function get_plugins(){
166
 
167
- $active_plugins = wp_get_active_and_valid_plugins();
168
- $mu_plugins = get_mu_plugins();
169
- $output = array();
170
-
171
- if (is_array($active_plugins)) {
172
- foreach ($active_plugins as $plugins_key => $plugin) {
173
- $data = get_plugin_data( $plugin, false, false );
174
- $slug = explode('/',plugin_basename($plugin));
175
- $slug = str_replace('.php', '', $slug[1]);
176
- $output[$slug] = $data['Version'];
 
 
177
  }
178
- }
179
 
180
- if (is_array($mu_plugins)) {
181
- foreach ($mu_plugins as $plugins_key => $plugin) {
182
- $slug = str_replace('.php', '', $plugins_key);
183
- $output[$slug] = '1.0.0';
 
184
  }
 
185
  }
186
- return $output;
 
187
  }
188
 
189
  function get_user_role(){
@@ -207,6 +253,7 @@ if (!class_exists('sk_config_data')) {
207
  }
208
  return $user_role;
209
  }
 
210
  }
211
  }
212
 
4
  if (!class_exists('sk_config_data')) {
5
 
6
  class sk_config_data{
7
+
8
+ var $cache_time = 43200; // 12 Hours
9
+
10
  function get_domain(){
11
  $site_url = get_site_url();
12
  if(substr($site_url, -1) == '/') {
16
  return $site_url;
17
  }
18
 
19
+ // Return list of post types registered in WordPress
20
+ // Transients cleared on post type update, create, delete
21
+
22
  function get_post_types(){
23
  global $wpdb;
 
 
 
24
 
25
+ if ( false === ( $result = get_transient( 'sk_get_post_types' ) ) ) {
26
+
27
+ $query = "SELECT post_type, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type";
28
+ $counts = $wpdb->get_results($query);
29
+ $result = '';
30
+
31
+ foreach ($counts as $key => $type) {
32
+ $type->post_type = str_replace('-', '_', $type->post_type);
33
+ $result .= "\n post_type_{$type->post_type} : $type->count,";
34
+ }
35
+ set_transient( 'sk_get_post_types', $result, $this->cache_time );
36
  }
37
+
38
+ return $result;
39
  }
40
 
41
  function get_file_editor_enabled(){
52
  }
53
 
54
  function get_themes(){
55
+ if ( false === ( $result = get_transient( 'sk_get_themes' ) ) ) {
56
+ $result = wp_get_themes( array( 'allowed' => true ) );
57
+ set_transient( 'sk_get_themes', $result, $this->cache_time );
58
+ }
59
+
60
+ return count($result);
61
  }
62
 
63
  function get_post_types_and_statuses(){
64
  global $wpdb;
 
 
 
65
 
66
+ // Can't find a good method to clear cache for newly registered post types that fires once
67
+ // if ( false === ( $result = get_transient( 'sk_get_post_types_and_statuses' ) ) ) {
68
+ $query = "SELECT post_type, post_status, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type, post_status";
69
+ $counts = $wpdb->get_results($query);
70
+ $result = '';
71
 
72
+ foreach ($counts as $key => $type) {
73
+ $type->post_type = str_replace('-', '_', $type->post_type);
74
+ $type->post_status = str_replace('-', '_', $type->post_status);
75
+
76
+ $result .= "\n post_type_{$type->post_type}_{$type->post_status} : $type->count,";
77
+ }
78
+ set_transient( 'sk_get_post_types_and_statuses', $result, $this->cache_time );
79
+ // }
80
+
81
+ return $result;
82
  }
83
 
84
  function get_taxonomies(){
85
  global $wpdb;
 
 
 
86
 
87
+ // if ( false === ( $result = get_transient( 'sk_get_taxonomies' ) ) ) {
88
+ $query = "SELECT count(distinct term_taxonomy_id) as count, taxonomy from {$wpdb->prefix}term_taxonomy group by taxonomy";
89
+ $counts = $wpdb->get_results($query);
90
+ $result = '';
91
+
92
+ foreach ($counts as $key => $taxonomy) {
93
+ $taxonomy->taxonomy = str_replace('-', '_', $taxonomy->taxonomy);
94
+ $result .= "\n taxonomy_{$taxonomy->taxonomy} : $taxonomy->count,";
95
+ }
96
+ set_transient( 'sk_get_taxonomies', $result, $this->cache_time );
97
+ // }
98
+
99
+ return $result;
100
  }
101
 
102
  function get_comments(){
103
  global $wpdb;
104
+
105
+ if ( false === ( $result = get_transient( 'sk_get_comments' ) ) ) {
106
+ $query = "SELECT count(distinct comment_ID) as count from {$wpdb->prefix}comments";
107
+ $counts = $wpdb->get_var($query);
108
+ if (!$counts) $counts = 0;
109
+ $result = "\n comment_count : $counts,";
110
+ set_transient( 'sk_get_comments', $result, $this->cache_time );
111
+ }
112
+
113
+ return $result;
114
  }
115
 
116
  function get_post_statuses(){
117
  global $wpdb;
 
 
 
118
 
119
+ if ( false === ( $result = get_transient( 'sk_post_statuses' ) ) ) {
120
+ $query = "SELECT post_status, count(ID) as count from {$wpdb->prefix}posts group by post_status";
121
+ $counts = $wpdb->get_results($query);
122
+ $result = '';
123
+
124
+ foreach ($counts as $key => $type) {
125
+ $type->post_status = str_replace('-', '_', $type->post_status);
126
+ $result .= "\n post_status_{$type->post_status} : $type->count,";
127
+ }
128
+ set_transient( 'sk_post_statuses', $result, $this->cache_time );
129
  }
130
+
131
+ return $result;
132
  }
133
 
134
  function get_user_data(){
135
  global $current_user;
136
 
137
+ if ( false === ( $result = get_transient( 'sk_get_user_data' ) ) ) {
138
+ $data = get_userdata($current_user->ID);
139
+ $result = "\n user_id : $current_user->ID,";
140
 
141
+ foreach ($data->allcaps as $cap => $val) {
142
+ $cap = sanitize_title($cap);
143
+ $cap = str_replace('-', '_', $cap);
144
+ if (!$val) $val = 0;
145
+ $result .= "\n cap_{$cap} : $val,";
146
+ }
147
+ set_transient( 'sk_get_user_data', $result, $this->cache_time );
148
  }
149
+
150
+ return $result;
151
  }
152
 
153
  function get_framework(){
206
 
207
  function get_plugins(){
208
 
209
+ if ( false === ( $result = get_transient( 'sk_get_plugins' ) ) ) {
210
+ $active_plugins = wp_get_active_and_valid_plugins();
211
+ $mu_plugins = get_mu_plugins();
212
+ $result = array();
213
+
214
+ if (is_array($active_plugins)) {
215
+ foreach ($active_plugins as $plugins_key => $plugin) {
216
+ $data = get_plugin_data( $plugin, false, false );
217
+ $slug = explode('/',plugin_basename($plugin));
218
+ $slug = str_replace('.php', '', $slug[1]);
219
+ $result[$slug] = $data['Version'];
220
+ }
221
  }
 
222
 
223
+ if (is_array($mu_plugins)) {
224
+ foreach ($mu_plugins as $plugins_key => $plugin) {
225
+ $slug = str_replace('.php', '', $plugins_key);
226
+ $result[$slug] = '1.0.0';
227
+ }
228
  }
229
+ set_transient( 'sk_get_plugins', $result, $this->cache_time );
230
  }
231
+
232
+ return $result;
233
  }
234
 
235
  function get_user_role(){
253
  }
254
  return $user_role;
255
  }
256
+
257
  }
258
  }
259
 
libs/walkthrough_config.php CHANGED
@@ -17,6 +17,51 @@
17
  </div>
18
  </div>
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  <div class="sk_box configure">
21
  <div class="well">
22
  <form method='post'>
17
  </div>
18
  </div>
19
 
20
+ <div class="sk_box configure">
21
+ <div class="well">
22
+ <h3>Configure - Other</h3>
23
+
24
+ <form method="post">
25
+ <?php settings_fields('sk_license'); ?>
26
+ <table class="form-table long_label">
27
+ <tbody>
28
+
29
+ <tr valign="top">
30
+ <th scope="row" valign="top">Hide Composer Button in Taskbar</th>
31
+ <td>
32
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_taskbar_button' <?php echo (isset($sk_hide_composer_taskbar_button) && $sk_hide_composer_taskbar_button) ? 'CHECKED' : '' ?>>
33
+ </td>
34
+ </tr>
35
+ <tr valign="top">
36
+ <th scope="row" valign="top">Hide Config Button in Taskbar</th>
37
+ <td>
38
+ <input class='checkbox' type='checkbox' name='sk_hide_config_taskbar_button' <?php echo (isset($sk_hide_config_taskbar_button) && $sk_hide_config_taskbar_button) ? 'CHECKED' : '' ?>>
39
+ </td>
40
+ </tr>
41
+ <tr valign="top">
42
+ <th scope="row" valign="top">Hide Composer Upgrade Button in Drawer</th>
43
+ <td>
44
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_upgrade_button' <?php echo (isset($sk_hide_composer_upgrade_button) && $sk_hide_composer_upgrade_button) ? 'CHECKED' : '' ?>>
45
+ </td>
46
+ </tr>
47
+ <tr valign="top">
48
+ <th scope="row" valign="top"></th>
49
+ <td>
50
+ <input class='button button-primary' type='submit' value='Save'/>
51
+ </td>
52
+ </tr>
53
+
54
+ <input type='hidden' name='is_ms_admin' value='<?php echo (isset($is_ms_admin)) ? $is_ms_admin : false ?>'/>
55
+ <input type='hidden' name='sk_setting_other' value='true'/>
56
+
57
+ <?php wp_nonce_field( 'update_sk_settings' ); ?>
58
+
59
+ </tbody>
60
+ </table>
61
+ </form>
62
+ </div>
63
+ </div>
64
+
65
  <div class="sk_box configure">
66
  <div class="well">
67
  <form method='post'>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.sidekick.pro
4
  Tags: help, tutorial, 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: 3.7
6
  Tested up to: 4.2
7
- Stable tag: 2.2.4
8
  License: GNU Version 2 or Any Later Version
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -145,6 +145,13 @@ We read and respond to every piece of feedback we get.
145
 
146
  == Changelog ==
147
 
 
 
 
 
 
 
 
148
  = 2.2.4 =
149
  * Adds new compatibilities to check if plugin editor is enabled
150
 
4
  Tags: help, tutorial, 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: 3.7
6
  Tested up to: 4.2
7
+ Stable tag: 2.3.0
8
  License: GNU Version 2 or Any Later Version
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
145
 
146
  == Changelog ==
147
 
148
+ = 2.3.0 =
149
+ * Revamp of multisite activation screen and optimizations for activations on large networks
150
+ * Added config options for disabling the composer, configuration buttons in the taskbar
151
+ * Added config option for disabling the "Create your own walkthroughs" message in the drawer
152
+ * Added caching options to db queries (Thank You Joost - @yoast)
153
+ * Changed over from custom cURL requests to utulize wp_remote_post
154
+
155
  = 2.2.4 =
156
  * Adds new compatibilities to check if plugin editor is enabled
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.0
8
  Tested up to: 4.1.1
9
- Version: 2.2.4
10
  Author: Sidekick.pro
11
  Author URI: http://www.sidekick.pro
12
  */
@@ -46,7 +46,7 @@ if (!class_exists('Sidekick')){
46
  wp_enqueue_script('jquery-ui-droppable' , null, array('jquery-ui-core') );
47
  wp_enqueue_script('jquery-effects-scale' , null, array('jquery-ui-core') );
48
  wp_enqueue_script('jquery-effects-highlight' , null, array('jquery-ui-core') );
49
- wp_enqueue_script('sidekick-admin' , '//assets.sidekick.pro/plugin/tag/latest/js/sidekick_admin.js',array( 'jquery' ));
50
  }
51
 
52
  function enqueue(){
@@ -81,12 +81,6 @@ if (!class_exists('Sidekick')){
81
  delete_option('sk_activation_id');
82
  }
83
 
84
- if (isset($_POST['sk_composer_button'])) {
85
- update_option( 'sk_composer_button', true );
86
- } else {
87
- delete_option('sk_composer_button');
88
- }
89
-
90
  if (isset($_POST['sk_track_data'])) {
91
  update_option( 'sk_track_data', true );
92
  } else {
@@ -99,11 +93,14 @@ if (!class_exists('Sidekick')){
99
 
100
  }
101
 
102
- $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
103
- $sk_track_data = get_option( 'sk_track_data' );
104
- $current_user = wp_get_current_user();
105
- $status = 'Free';
106
- $error = null;
 
 
 
107
 
108
  if (isset($SK_PAID_LIBRARY_FILE) && $activation_id) {
109
  $_POST['activation_id'] = $activation_id;
@@ -143,58 +140,82 @@ if (!class_exists('Sidekick')){
143
 
144
  function set_disabled_wts(){
145
 
146
- if (!check_admin_referer('update_sk_settings')) {
147
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
148
- exit;
149
- }
150
 
151
- $_POST['disable_wts'] = array_map("mysql_real_escape_string",$_POST['disable_wts']);
152
 
153
- if (isset($_POST['disable_wts']) && $_POST['disable_wts']) {
154
- update_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
155
- if (is_network_admin()) {
156
- update_site_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
157
  }
158
- } else {
159
- delete_option('sk_disabled_wts');
160
- if (is_network_admin()) {
161
- delete_site_option('sk_disabled_wts');
 
 
 
 
 
 
 
 
 
162
  }
163
  }
 
164
  }
165
 
166
  function set_autostart_wt(){
167
 
168
- if (!check_admin_referer('update_sk_settings')) {
169
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
170
- exit;
171
- }
172
 
173
- if (isset($_POST['sk_autostart_walkthrough_id']) && intval($_POST['sk_autostart_walkthrough_id']) > 0){
174
- if (is_network_admin()) {
175
- update_site_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
176
  }
177
- update_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
178
- } else {
179
- delete_option('sk_autostart_walkthrough_id');
180
- if (is_network_admin()) {
181
- delete_site_option('sk_autostart_walkthrough_id');
 
 
 
 
 
 
182
  }
183
  }
 
184
  }
185
 
186
- function set_api(){
187
 
188
- if (!check_admin_referer('update_sk_settings')) {
189
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
190
- exit;
191
- }
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
- if (isset($_POST['sk_api'])){
195
- update_option('sk_api',wp_filter_kses($_POST['sk_api']));
196
- update_site_option('sk_api',wp_filter_kses($_POST['sk_api']));
197
  }
 
198
  }
199
 
200
  function footer(){
@@ -206,41 +227,40 @@ if (!class_exists('Sidekick')){
206
  $current_user = wp_get_current_user();
207
  $sk_just_activated = get_option( 'sk_just_activated' );
208
  $sk_track_data = get_option( 'sk_track_data' );
209
- $sk_composer_button = get_option( 'sk_composer_button' );
 
 
210
  $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
211
  $autostart_network_walkthrough_id = (get_site_option('sk_autostart_walkthrough_id') ? get_site_option('sk_autostart_walkthrough_id') : 'null' );
212
  $autostart_walkthrough_id = (get_option('sk_autostart_walkthrough_id') ? get_option('sk_autostart_walkthrough_id') : $autostart_network_walkthrough_id );
213
  $custom_class = (get_option( "sk_custom_class" ) ? get_option( "sk_custom_class" ) : '');
214
  $theme = wp_get_theme();
215
  $not_supported_ie = false;
216
- $user_email = '';
217
- if ($sk_track_data) {
218
- $user_email = $current_user->user_email;
219
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
- $disabled_wts = (!is_network_admin()) ? $sk_config_data->get_disabled_wts() : '[]';
222
- $user_role = $sk_config_data->get_user_role();
223
- $site_url = $sk_config_data->get_domain();
224
- $installed_plugins = $sk_config_data->get_plugins();
225
- $plugin_count = (isset($plugins) && is_array($plugins)) ? count($plugins) : array();
226
- $disabled_network_wts = $sk_config_data->get_disabled_network_wts();
227
- $current_url = $sk_config_data->get_current_url();
228
- $post_types = $sk_config_data->get_post_types();
229
- $taxonomies = $sk_config_data->get_taxonomies();
230
- $user_data = $sk_config_data->get_user_data();
231
- $comments = $sk_config_data->get_comments();
232
- $post_statuses = $sk_config_data->get_post_statuses();
233
- $post_types_and_statuses = $sk_config_data->get_post_types_and_statuses();
234
- $number_of_themes = $sk_config_data->get_themes();
235
- $frameworks = $sk_config_data->get_framework();
236
- $file_editor_enabled = $sk_config_data->get_file_editor_enabled();
237
 
238
  delete_option( 'sk_just_activated' );
239
  if(preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])) $not_supported_ie = true;
240
 
241
  ?>
242
 
243
-
244
  <?php if (!$not_supported_ie): ?>
245
 
246
  <script type="text/javascript">
@@ -265,6 +285,7 @@ if (!class_exists('Sidekick')){
265
  installed_theme: '<?php echo sanitize_title($theme->Name) ?>',
266
  theme_version: '<?php echo $theme->Version ?>',
267
  main_soft_version: '<?php echo get_bloginfo("version") ?>',
 
268
  user_level: '<?php echo $user_role ?>',
269
  main_soft_name: 'WordPress',
270
  file_editor_enabled: <?php echo ($file_editor_enabled) ? $file_editor_enabled: 'null' ?>,
@@ -282,19 +303,20 @@ if (!class_exists('Sidekick')){
282
  auto_open_product: 'default',
283
  disable_wts_in_root_bucket_ids: [5,87],
284
  autostart_walkthrough_id: <?php echo $autostart_walkthrough_id ?>,
285
- sk_composer_button: <?php echo ($sk_composer_button ? "true" : "false") ?>,
286
  track_data: '<?php echo $sk_track_data ?>',
287
  user_email: '<?php echo $user_email ?>',
288
  custom_class: '<?php echo $custom_class ?>',
289
 
290
  // Toggles
291
- path_not_found_continue: true,
292
- show_powered_by: true,
293
- show_powered_by_link: true,
294
- sk_autostart_only_once: true,
295
- use_native_controls: false,
296
- composer_upgrade_off: false,
297
- basics_upgrade: true,
 
 
298
 
299
  // Platform Info
300
  library_version: 2,
@@ -303,9 +325,9 @@ if (!class_exists('Sidekick')){
303
 
304
  // Generic Info
305
  just_activated: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
306
- platform_version: null,
307
- plugin_version: '2.2.4',
308
  show_login: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
 
 
309
 
310
  // SIDEKICK URLS
311
  assets: '<?php echo SK_ASSETS ?>',
@@ -322,7 +344,6 @@ if (!class_exists('Sidekick')){
322
  plugin_url: '<?php echo admin_url("admin.php?page=sidekick") ?>',
323
  base_url: '<?php echo site_url() ?>',
324
  current_url: '<?php echo $current_url ?>'
325
- // fallback_notfication_mp3: '//assets.sidekick.pro/fallback.mp3'
326
  }
327
 
328
  var skc_config = {
@@ -391,23 +412,6 @@ if (!class_exists('Sidekick')){
391
  function activate_plugin(){
392
  update_option( 'sk_firstuse', true );
393
  update_option( 'sk_do_activation_redirect', true );
394
- $data = array(
395
- 'source' => 'plugin',
396
- 'action' => 'track',
397
- 'type' => 'activate'
398
- );
399
- $this->track($data);
400
- }
401
-
402
- function curl_get_data($url){
403
- $ch = curl_init();
404
- $timeout = 5;
405
- curl_setopt($ch, CURLOPT_URL, $url);
406
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
407
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
408
- $data = curl_exec($ch);
409
- curl_close($ch);
410
- return $data;
411
  }
412
 
413
  function redirect(){
@@ -421,25 +425,28 @@ if (!class_exists('Sidekick')){
421
 
422
  function check_ver(){
423
 
424
- $data = json_encode('2.2.4');
 
 
 
425
 
426
- if(array_key_exists('callback', $_GET)){
 
 
 
427
 
428
- header('Content-Type: text/javascript; charset=utf8');
429
- header('Access-Control-Allow-Origin: http://www.example.com/');
430
- header('Access-Control-Max-Age: 3628800');
431
- header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
432
 
433
- $callback = $_GET['callback'];
434
- echo $callback.'('.$data.');';
435
 
436
- }else{
437
- header('Content-Type: application/json; charset=utf8');
438
 
439
- echo $data;
440
  }
441
 
442
- die();
443
  }
444
 
445
  function admin_notice() {
@@ -457,72 +464,81 @@ if (!class_exists('Sidekick')){
457
  }
458
  }
459
 
460
- function deactivate_plugin(){
461
- $data = array(
462
- 'source' => 'plugin',
463
- 'action' => 'track',
464
- 'type' => 'deactivate',
465
- 'user' => get_option( "activation_id" )
466
- );
467
- $this->track($data);
468
- ?>
469
- <script type="text/javascript">
470
- window._gaq = window._gaq || [];
471
- window._gaq.push(['sk._setAccount', 'UA-39283622-1']);
472
-
473
- (function() {
474
- var ga_wpu = document.createElement('script'); ga_sk.type = 'text/javascript'; ga_sk.async = true;
475
- ga_sk.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
476
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga_wpu, s);
477
- })();
478
- window._gaq.push(['sk._trackEvent', 'Plugin - Deactivate', '', null, 0,true]);
479
- </script>
480
- <?php
481
- delete_option( 'sk_activated' );
482
  }
483
- }
484
- $sidekick = new Sidekick;
485
- register_activation_hook( __FILE__, array($sidekick,'activate_plugin') );
486
- register_deactivation_hook( __FILE__, array($sidekick,'deactivate_plugin') );
487
 
488
- // if (isset($_POST['sk_setting_disabled'])) $sidekick->set_disabled_wts();
489
- // if (isset($_POST['sk_setting_autostart'])) $sidekick->set_autostart_wt();
490
- // if (isset($_POST['sk_api'])) $sidekick->set_api();
491
- // if (isset($_GET['sk_ver_check'])) $sidekick->check_ver();
 
492
 
493
- if (isset($_POST['sk_setting_disabled'])) add_action('admin_init', array($sidekick,'set_disabled_wts'));
494
- if (isset($_POST['sk_setting_autostart'])) add_action('admin_init', array($sidekick,'set_autostart_wt'));
495
- if (isset($_POST['sk_api'])) add_action('admin_init', array($sidekick,'set_api'));
496
- if (isset($_GET['sk_ver_check'])) add_action('admin_init', array($sidekick,'check_ver'));
497
 
 
 
 
 
498
 
499
- add_action('admin_menu', array($sidekick,'setup_menu'));
 
 
 
 
 
 
 
 
500
  add_action('admin_init', array($sidekick,'redirect'));
 
 
501
  add_action('wp_ajax_sk_activate', array($sidekick,'activate'));
502
  add_action('wp_ajax_sk_save', array($sidekick,'ajax_save'));
503
  add_action('admin_notices', array($sidekick,'admin_notice'));
504
- add_action('admin_init', array($sidekick,'admin_notice_ignore'));
505
-
506
 
507
-
508
- if (!defined('SK_PLUGIN_DEGBUG'))
509
  require_once('sk_init.php');
 
510
 
511
  if (!(isset($_GET['tab']) && $_GET['tab'] == 'plugin-information') && !defined('IFRAME_REQUEST')) {
512
  add_action('admin_footer', array($sidekick,'footer'));
513
  add_action('customize_controls_print_footer_scripts', array($sidekick,'footer'));
514
  }
515
- }
516
 
 
 
 
 
 
 
 
 
 
 
517
 
 
518
 
519
- // Multisite Licensing
 
 
520
 
521
- if (defined('MULTISITE')) {
522
- require_once('libs/licensing.php');
523
- $sidekickMassActivator = new sidekickMassActivator;
524
- add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
525
- add_action('network_admin_menu', array($sidekickMassActivator,'setup_menu'));
526
- add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
 
 
 
 
 
527
  }
528
 
6
  Description: Adds a real-time WordPress training walkthroughs right in your Dashboard
7
  Requires at least: 4.0
8
  Tested up to: 4.1.1
9
+ Version: 2.3.0
10
  Author: Sidekick.pro
11
  Author URI: http://www.sidekick.pro
12
  */
46
  wp_enqueue_script('jquery-ui-droppable' , null, array('jquery-ui-core') );
47
  wp_enqueue_script('jquery-effects-scale' , null, array('jquery-ui-core') );
48
  wp_enqueue_script('jquery-effects-highlight' , null, array('jquery-ui-core') );
49
+ wp_enqueue_script('sidekick-admin' , '//assets.sidekick.pro/plugin/tag/latest/js/sidekick_admin.js',array( 'jquery' ), null);
50
  }
51
 
52
  function enqueue(){
81
  delete_option('sk_activation_id');
82
  }
83
 
 
 
 
 
 
 
84
  if (isset($_POST['sk_track_data'])) {
85
  update_option( 'sk_track_data', true );
86
  } else {
93
 
94
  }
95
 
96
+ $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
97
+ $sk_track_data = get_option( 'sk_track_data' );
98
+ $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
99
+ $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
100
+ $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
101
+ $current_user = wp_get_current_user();
102
+ $status = 'Free';
103
+ $error = null;
104
 
105
  if (isset($SK_PAID_LIBRARY_FILE) && $activation_id) {
106
  $_POST['activation_id'] = $activation_id;
140
 
141
  function set_disabled_wts(){
142
 
 
 
 
 
143
 
144
+ if (isset($_POST['sk_setting_disabled'])){
145
 
146
+ if (!check_admin_referer('update_sk_settings')) {
147
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
148
+ exit;
 
149
  }
150
+
151
+ $_POST['disable_wts'] = array_map("mysql_real_escape_string",$_POST['disable_wts']);
152
+
153
+ if (isset($_POST['disable_wts']) && $_POST['disable_wts']) {
154
+ update_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
155
+ if (is_network_admin()) {
156
+ update_site_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
157
+ }
158
+ } else {
159
+ delete_option('sk_disabled_wts');
160
+ if (is_network_admin()) {
161
+ delete_site_option('sk_disabled_wts');
162
+ }
163
  }
164
  }
165
+
166
  }
167
 
168
  function set_autostart_wt(){
169
 
170
+ if (isset($_POST['sk_setting_autostart'])){
 
 
 
171
 
172
+ if (!check_admin_referer('update_sk_settings')) {
173
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
174
+ exit;
175
  }
176
+
177
+ if (isset($_POST['sk_autostart_walkthrough_id']) && intval($_POST['sk_autostart_walkthrough_id']) > 0){
178
+ if (is_network_admin()) {
179
+ update_site_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
180
+ }
181
+ update_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
182
+ } else {
183
+ delete_option('sk_autostart_walkthrough_id');
184
+ if (is_network_admin()) {
185
+ delete_site_option('sk_autostart_walkthrough_id');
186
+ }
187
  }
188
  }
189
+
190
  }
191
 
192
+ function set_configure_other(){
193
 
194
+ if (isset($_POST['sk_setting_other'])){
 
 
 
195
 
196
+ if (!check_admin_referer('update_sk_settings')) {
197
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
198
+ exit;
199
+ }
200
+
201
+ $checkboxes = array('sk_hide_composer_taskbar_button','sk_hide_config_taskbar_button','sk_hide_composer_upgrade_button');
202
+
203
+ foreach ($checkboxes as $key => $checkbox) {
204
+ if (isset($_POST[$checkbox])){
205
+ if (is_network_admin()) {
206
+ update_site_option($checkbox,wp_filter_kses($_POST[$checkbox]));
207
+ }
208
+ update_option($checkbox,wp_filter_kses($_POST[$checkbox]));
209
+ } else {
210
+ delete_option($checkbox);
211
+ if (is_network_admin()) {
212
+ delete_site_option($checkbox);
213
+ }
214
+ }
215
+ }
216
 
 
 
 
217
  }
218
+
219
  }
220
 
221
  function footer(){
227
  $current_user = wp_get_current_user();
228
  $sk_just_activated = get_option( 'sk_just_activated' );
229
  $sk_track_data = get_option( 'sk_track_data' );
230
+ $sk_hide_composer_taskbar_button = get_option( 'sk_hide_composer_taskbar_button' );
231
+ $sk_hide_config_taskbar_button = get_option( 'sk_hide_config_taskbar_button' );
232
+ $sk_hide_composer_upgrade_button = get_option( 'sk_hide_composer_upgrade_button' );
233
  $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
234
  $autostart_network_walkthrough_id = (get_site_option('sk_autostart_walkthrough_id') ? get_site_option('sk_autostart_walkthrough_id') : 'null' );
235
  $autostart_walkthrough_id = (get_option('sk_autostart_walkthrough_id') ? get_option('sk_autostart_walkthrough_id') : $autostart_network_walkthrough_id );
236
  $custom_class = (get_option( "sk_custom_class" ) ? get_option( "sk_custom_class" ) : '');
237
  $theme = wp_get_theme();
238
  $not_supported_ie = false;
239
+ $user_email = ($sk_track_data) ? $current_user->user_email : '';
240
+ $disabled_wts = (!is_network_admin()) ? $sk_config_data->get_disabled_wts() : '[]';
241
+ $user_role = $sk_config_data->get_user_role();
242
+ $site_url = $sk_config_data->get_domain();
243
+ $installed_plugins = $sk_config_data->get_plugins();
244
+ $plugin_count = (isset($plugins) && is_array($plugins)) ? count($plugins) : array();
245
+ $disabled_network_wts = $sk_config_data->get_disabled_network_wts();
246
+ $current_url = $sk_config_data->get_current_url();
247
+ $post_types = $sk_config_data->get_post_types();
248
+ $taxonomies = $sk_config_data->get_taxonomies();
249
+ $user_data = $sk_config_data->get_user_data();
250
+ $comments = $sk_config_data->get_comments();
251
+ $post_statuses = $sk_config_data->get_post_statuses();
252
+ $post_types_and_statuses = $sk_config_data->get_post_types_and_statuses();
253
+ $number_of_themes = $sk_config_data->get_themes();
254
+ $frameworks = $sk_config_data->get_framework();
255
+ $file_editor_enabled = $sk_config_data->get_file_editor_enabled();
256
+
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  delete_option( 'sk_just_activated' );
260
  if(preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])) $not_supported_ie = true;
261
 
262
  ?>
263
 
 
264
  <?php if (!$not_supported_ie): ?>
265
 
266
  <script type="text/javascript">
285
  installed_theme: '<?php echo sanitize_title($theme->Name) ?>',
286
  theme_version: '<?php echo $theme->Version ?>',
287
  main_soft_version: '<?php echo get_bloginfo("version") ?>',
288
+ // main_soft_version: '4.5.1',
289
  user_level: '<?php echo $user_role ?>',
290
  main_soft_name: 'WordPress',
291
  file_editor_enabled: <?php echo ($file_editor_enabled) ? $file_editor_enabled: 'null' ?>,
303
  auto_open_product: 'default',
304
  disable_wts_in_root_bucket_ids: [5,87],
305
  autostart_walkthrough_id: <?php echo $autostart_walkthrough_id ?>,
 
306
  track_data: '<?php echo $sk_track_data ?>',
307
  user_email: '<?php echo $user_email ?>',
308
  custom_class: '<?php echo $custom_class ?>',
309
 
310
  // Toggles
311
+ path_not_found_continue: true,
312
+ show_powered_by: true,
313
+ show_powered_by_link: true,
314
+ sk_autostart_only_once: true,
315
+ use_native_controls: false,
316
+ basics_upgrade: true,
317
+ composer_upgrade_off: <?php echo ($sk_hide_composer_upgrade_button ? "true" : "false") ?>,
318
+ hide_taskbar_composer_button: <?php echo ($sk_hide_composer_taskbar_button ? "true" : "false") ?>,
319
+ hide_taskbar_config_button: <?php echo ($sk_hide_config_taskbar_button ? "true" : "false") ?>,
320
 
321
  // Platform Info
322
  library_version: 2,
325
 
326
  // Generic Info
327
  just_activated: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
 
 
328
  show_login: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
329
+ platform_version: null,
330
+ plugin_version: '2.3.0',
331
 
332
  // SIDEKICK URLS
333
  assets: '<?php echo SK_ASSETS ?>',
344
  plugin_url: '<?php echo admin_url("admin.php?page=sidekick") ?>',
345
  base_url: '<?php echo site_url() ?>',
346
  current_url: '<?php echo $current_url ?>'
 
347
  }
348
 
349
  var skc_config = {
412
  function activate_plugin(){
413
  update_option( 'sk_firstuse', true );
414
  update_option( 'sk_do_activation_redirect', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  }
416
 
417
  function redirect(){
425
 
426
  function check_ver(){
427
 
428
+ if (isset($_GET['sk_ver_check'])){
429
+ $data = json_encode('2.3.0');
430
+
431
+ if(array_key_exists('callback', $_GET)){
432
 
433
+ header('Content-Type: text/javascript; charset=utf8');
434
+ header('Access-Control-Allow-Origin: http://www.example.com/');
435
+ header('Access-Control-Max-Age: 3628800');
436
+ header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
437
 
438
+ $callback = $_GET['callback'];
439
+ echo $callback.'('.$data.');';
 
 
440
 
441
+ }else{
442
+ header('Content-Type: application/json; charset=utf8');
443
 
444
+ echo $data;
445
+ }
446
 
447
+ die();
448
  }
449
 
 
450
  }
451
 
452
  function admin_notice() {
464
  }
465
  }
466
 
467
+ // Clear transients for cached sk_config_data
468
+
469
+ function delete_sk_get_comments(){
470
+ mlog("delete_sk_get_comments");
471
+ delete_transient('sk_get_comments');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
472
  }
 
 
 
 
473
 
474
+ function delete_sk_get_post_types(){
475
+ mlog('delete sk_get_post_types');
476
+ delete_transient('sk_get_post_types');
477
+ delete_transient('sk_post_statuses');
478
+ }
479
 
480
+ function delete_sk_get_user_data(){
481
+ mlog('delete sk_get_user_data');
482
+ delete_transient('sk_get_user_data');
483
+ }
484
 
485
+ function delete_sk_get_plugins(){
486
+ mlog('delete sk_get_plugins');
487
+ delete_transient('sk_get_plugins');
488
+ }
489
 
490
+ }
491
+
492
+ $sidekick = new Sidekick;
493
+ register_activation_hook( __FILE__, array($sidekick,'activate_plugin') );
494
+
495
+ add_action('admin_init', array($sidekick,'set_disabled_wts'));
496
+ add_action('admin_init', array($sidekick,'set_autostart_wt'));
497
+ add_action('admin_init', array($sidekick,'set_configure_other'));
498
+ add_action('admin_init', array($sidekick,'check_ver'));
499
  add_action('admin_init', array($sidekick,'redirect'));
500
+ add_action('admin_init', array($sidekick,'admin_notice_ignore'));
501
+ add_action('admin_menu', array($sidekick,'setup_menu'));
502
  add_action('wp_ajax_sk_activate', array($sidekick,'activate'));
503
  add_action('wp_ajax_sk_save', array($sidekick,'ajax_save'));
504
  add_action('admin_notices', array($sidekick,'admin_notice'));
 
 
505
 
506
+ if (!defined('SK_PLUGIN_DEGBUG')){
 
507
  require_once('sk_init.php');
508
+ }
509
 
510
  if (!(isset($_GET['tab']) && $_GET['tab'] == 'plugin-information') && !defined('IFRAME_REQUEST')) {
511
  add_action('admin_footer', array($sidekick,'footer'));
512
  add_action('customize_controls_print_footer_scripts', array($sidekick,'footer'));
513
  }
 
514
 
515
+ add_action('transition_post_status',array($sidekick,'delete_sk_get_post_types_and_statuses'));
516
+ add_action('clean_post_cache',array($sidekick,'delete_sk_get_post_types_and_statuses'));
517
+
518
+ add_action('wp_update_comment_count',array($sidekick,'delete_sk_get_comments'));
519
+
520
+ add_action('set_user_role',array($sidekick,'delete_sk_get_user_data'));
521
+ add_action('edit_user_profile',array($sidekick,'delete_sk_get_user_data'));
522
+
523
+ add_action('activated_plugin',array($sidekick,'delete_sk_get_plugins'));
524
+ add_action('deactivated_plugin',array($sidekick,'delete_sk_get_plugins'));
525
 
526
+ // Multisite Licensing
527
 
528
+ if (is_multisite()) {
529
+ require_once('libs/licensing.php');
530
+ $sidekickMassActivator = new sidekickMassActivator;
531
 
532
+ add_action('network_admin_menu', array($sidekickMassActivator,'setup_menu'));
533
+ add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
534
+ add_action('wp_ajax_sk_activate_batch', array($sidekickMassActivator,'activate_batch'));
535
+ add_action('wp_ajax_sk_load_sites_by_status', array($sidekickMassActivator,'load_sites_by_status'));
536
+
537
+ $sk_auto_activations = get_option( 'sk_auto_activations');
538
+ if ($sk_auto_activations) {
539
+ add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
540
+ add_action('sk_hourly_event',array($sidekickMassActivator,'schedule'),10,6);
541
+ }
542
+ }
543
  }
544
 
sidekick_embed.php CHANGED
@@ -8,7 +8,7 @@ Description: Adds a real-time WordPress training walkthroughs right in your Dash
8
  We recommend not activating SIDEKICK automatically for people but via an Opt-In process when they configure your own theme or plugin.
9
  Requires at least: 4.0
10
  Tested up to: 4.1.1
11
- Version: 2.2.4
12
  Author: Sidekick.pro
13
  Author URI: http://www.sidekick.pro
14
  */
@@ -51,7 +51,7 @@ if (!$sidekick_active && !class_exists('Sidekick')){
51
  wp_enqueue_script('jquery-ui-droppable' , null, array('jquery-ui-core') );
52
  wp_enqueue_script('jquery-effects-scale' , null, array('jquery-ui-core') );
53
  wp_enqueue_script('jquery-effects-highlight' , null, array('jquery-ui-core') );
54
- wp_enqueue_script('sidekick-admin' , '//assets.sidekick.pro/plugin/tag/latest/js/sidekick_admin.js',array( 'jquery' ));
55
  }
56
 
57
  function enqueue(){
@@ -86,12 +86,6 @@ if (!$sidekick_active && !class_exists('Sidekick')){
86
  delete_option('sk_activation_id');
87
  }
88
 
89
- if (isset($_POST['sk_composer_button'])) {
90
- update_option( 'sk_composer_button', true );
91
- } else {
92
- delete_option('sk_composer_button');
93
- }
94
-
95
  if (isset($_POST['sk_track_data'])) {
96
  update_option( 'sk_track_data', true );
97
  } else {
@@ -104,11 +98,14 @@ if (!$sidekick_active && !class_exists('Sidekick')){
104
 
105
  }
106
 
107
- $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
108
- $sk_track_data = get_option( 'sk_track_data' );
109
- $current_user = wp_get_current_user();
110
- $status = 'Free';
111
- $error = null;
 
 
 
112
 
113
  if (isset($SK_PAID_LIBRARY_FILE) && $activation_id) {
114
  $_POST['activation_id'] = $activation_id;
@@ -191,7 +188,7 @@ if (!$sidekick_active && !class_exists('Sidekick')){
191
  <tbody>
192
  <tr valign="top">
193
  <th scope="row" valign="top">Activation ID</th>
194
- <?php if (defined('MULTISITE') && MULTISITE): ?>
195
  <?php if (isset($activation_id) && $activation_id): ?>
196
  <td><input class='regular-text' style='color: gray;' type='text' name='activation_id' value='xxxxxxxx-xxxx-xxxx-xxxx-<?php echo substr($activation_id, 25,20) ?>'></input></td>
197
  <?php else: ?>
@@ -218,13 +215,12 @@ if (!$sidekick_active && !class_exists('Sidekick')){
218
  </td>
219
  </tr>
220
 
221
- <tr valign="top" style='display: none'>
222
  <th scope="row" valign="top">
223
  Enable Composer Mode
224
  </th>
225
  <td>
226
- <input name="sk_composer_button" type="checkbox" <?php if (get_option('sk_composer_button')): ?>CHECKED<?php endif ?> />
227
- <label class="description" for="track_data">Enable Walkthrough creation.</label>
228
  </td>
229
  </tr>
230
  </tbody>
@@ -236,7 +232,7 @@ if (!$sidekick_active && !class_exists('Sidekick')){
236
  </div>
237
  </div>
238
 
239
- <div class="sk_box composer">
240
  <div class="well">
241
  <h3>Build Your Own Walkthroughs</h3>
242
  <a href='http://www.sidekick.pro/plans/create_wp_walkthroughs/?utm_source=plugin&utm_medium=settings&utm_campaign=composer' target='_blank'><div class='composer_beta_button'>Build Your Own<br/>Walkthroughs</div></a>
@@ -317,6 +313,51 @@ if (!$sidekick_active && !class_exists('Sidekick')){
317
  </div>
318
  </div>
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  <div class="sk_box configure">
321
  <div class="well">
322
  <form method='post'>
@@ -362,58 +403,82 @@ if (!$sidekick_active && !class_exists('Sidekick')){
362
 
363
  function set_disabled_wts(){
364
 
365
- if (!check_admin_referer('update_sk_settings')) {
366
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
367
- exit;
368
- }
369
 
370
- $_POST['disable_wts'] = array_map("mysql_real_escape_string",$_POST['disable_wts']);
371
 
372
- if (isset($_POST['disable_wts']) && $_POST['disable_wts']) {
373
- update_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
374
- if (is_network_admin()) {
375
- update_site_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
376
  }
377
- } else {
378
- delete_option('sk_disabled_wts');
379
- if (is_network_admin()) {
380
- delete_site_option('sk_disabled_wts');
 
 
 
 
 
 
 
 
 
381
  }
382
  }
 
383
  }
384
 
385
  function set_autostart_wt(){
386
 
387
- if (!check_admin_referer('update_sk_settings')) {
388
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
389
- exit;
390
- }
391
 
392
- if (isset($_POST['sk_autostart_walkthrough_id']) && intval($_POST['sk_autostart_walkthrough_id']) > 0){
393
- if (is_network_admin()) {
394
- update_site_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
395
  }
396
- update_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
397
- } else {
398
- delete_option('sk_autostart_walkthrough_id');
399
- if (is_network_admin()) {
400
- delete_site_option('sk_autostart_walkthrough_id');
 
 
 
 
 
 
401
  }
402
  }
 
403
  }
404
 
405
- function set_api(){
406
 
407
- if (!check_admin_referer('update_sk_settings')) {
408
- print 'Sorry, your nonce did not verify or you\'re not logged in.';
409
- exit;
410
- }
411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
 
413
- if (isset($_POST['sk_api'])){
414
- update_option('sk_api',wp_filter_kses($_POST['sk_api']));
415
- update_site_option('sk_api',wp_filter_kses($_POST['sk_api']));
416
  }
 
417
  }
418
 
419
  function footer(){
@@ -425,41 +490,40 @@ if (!$sidekick_active && !class_exists('Sidekick')){
425
  $current_user = wp_get_current_user();
426
  $sk_just_activated = get_option( 'sk_just_activated' );
427
  $sk_track_data = get_option( 'sk_track_data' );
428
- $sk_composer_button = get_option( 'sk_composer_button' );
 
 
429
  $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
430
  $autostart_network_walkthrough_id = (get_site_option('sk_autostart_walkthrough_id') ? get_site_option('sk_autostart_walkthrough_id') : 'null' );
431
  $autostart_walkthrough_id = (get_option('sk_autostart_walkthrough_id') ? get_option('sk_autostart_walkthrough_id') : $autostart_network_walkthrough_id );
432
  $custom_class = (get_option( "sk_custom_class" ) ? get_option( "sk_custom_class" ) : '');
433
  $theme = wp_get_theme();
434
  $not_supported_ie = false;
435
- $user_email = '';
436
- if ($sk_track_data) {
437
- $user_email = $current_user->user_email;
438
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
- $disabled_wts = (!is_network_admin()) ? $sk_config_data->get_disabled_wts() : '[]';
441
- $user_role = $sk_config_data->get_user_role();
442
- $site_url = $sk_config_data->get_domain();
443
- $installed_plugins = $sk_config_data->get_plugins();
444
- $plugin_count = (isset($plugins) && is_array($plugins)) ? count($plugins) : array();
445
- $disabled_network_wts = $sk_config_data->get_disabled_network_wts();
446
- $current_url = $sk_config_data->get_current_url();
447
- $post_types = $sk_config_data->get_post_types();
448
- $taxonomies = $sk_config_data->get_taxonomies();
449
- $user_data = $sk_config_data->get_user_data();
450
- $comments = $sk_config_data->get_comments();
451
- $post_statuses = $sk_config_data->get_post_statuses();
452
- $post_types_and_statuses = $sk_config_data->get_post_types_and_statuses();
453
- $number_of_themes = $sk_config_data->get_themes();
454
- $frameworks = $sk_config_data->get_framework();
455
- $file_editor_enabled = $sk_config_data->get_file_editor_enabled();
456
 
457
  delete_option( 'sk_just_activated' );
458
  if(preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])) $not_supported_ie = true;
459
 
460
  ?>
461
 
462
-
463
  <?php if (!$not_supported_ie): ?>
464
 
465
  <script type="text/javascript">
@@ -484,6 +548,7 @@ if (!$sidekick_active && !class_exists('Sidekick')){
484
  installed_theme: '<?php echo sanitize_title($theme->Name) ?>',
485
  theme_version: '<?php echo $theme->Version ?>',
486
  main_soft_version: '<?php echo get_bloginfo("version") ?>',
 
487
  user_level: '<?php echo $user_role ?>',
488
  main_soft_name: 'WordPress',
489
  file_editor_enabled: <?php echo ($file_editor_enabled) ? $file_editor_enabled: 'null' ?>,
@@ -501,19 +566,20 @@ if (!$sidekick_active && !class_exists('Sidekick')){
501
  auto_open_product: 'default',
502
  disable_wts_in_root_bucket_ids: [5,87],
503
  autostart_walkthrough_id: <?php echo $autostart_walkthrough_id ?>,
504
- sk_composer_button: <?php echo ($sk_composer_button ? "true" : "false") ?>,
505
  track_data: '<?php echo $sk_track_data ?>',
506
  user_email: '<?php echo $user_email ?>',
507
  custom_class: '<?php echo $custom_class ?>',
508
 
509
  // Toggles
510
- path_not_found_continue: true,
511
- show_powered_by: true,
512
- show_powered_by_link: true,
513
- sk_autostart_only_once: true,
514
- use_native_controls: false,
515
- composer_upgrade_off: false,
516
- basics_upgrade: true,
 
 
517
 
518
  // Platform Info
519
  library_version: 2,
@@ -522,9 +588,9 @@ if (!$sidekick_active && !class_exists('Sidekick')){
522
 
523
  // Generic Info
524
  just_activated: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
525
- platform_version: null,
526
- plugin_version: '2.2.4',
527
  show_login: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
 
 
528
 
529
  // SIDEKICK URLS
530
  assets: '<?php echo SK_ASSETS ?>',
@@ -541,7 +607,6 @@ if (!$sidekick_active && !class_exists('Sidekick')){
541
  plugin_url: '<?php echo admin_url("admin.php?page=sidekick") ?>',
542
  base_url: '<?php echo site_url() ?>',
543
  current_url: '<?php echo $current_url ?>'
544
- // fallback_notfication_mp3: '//assets.sidekick.pro/fallback.mp3'
545
  }
546
 
547
  var skc_config = {
@@ -610,23 +675,6 @@ if (!$sidekick_active && !class_exists('Sidekick')){
610
  function activate_plugin(){
611
  update_option( 'sk_firstuse', true );
612
  update_option( 'sk_do_activation_redirect', true );
613
- $data = array(
614
- 'source' => 'plugin',
615
- 'action' => 'track',
616
- 'type' => 'activate'
617
- );
618
- $this->track($data);
619
- }
620
-
621
- function curl_get_data($url){
622
- $ch = curl_init();
623
- $timeout = 5;
624
- curl_setopt($ch, CURLOPT_URL, $url);
625
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
626
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
627
- $data = curl_exec($ch);
628
- curl_close($ch);
629
- return $data;
630
  }
631
 
632
  function redirect(){
@@ -640,25 +688,28 @@ if (!$sidekick_active && !class_exists('Sidekick')){
640
 
641
  function check_ver(){
642
 
643
- $data = json_encode('2.2.4');
 
644
 
645
- if(array_key_exists('callback', $_GET)){
646
 
647
- header('Content-Type: text/javascript; charset=utf8');
648
- header('Access-Control-Allow-Origin: http://www.example.com/');
649
- header('Access-Control-Max-Age: 3628800');
650
- header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
651
 
652
- $callback = $_GET['callback'];
653
- echo $callback.'('.$data.');';
654
 
655
- }else{
656
- header('Content-Type: application/json; charset=utf8');
657
 
658
- echo $data;
 
 
 
659
  }
660
 
661
- die();
662
  }
663
 
664
  function admin_notice() {
@@ -676,55 +727,46 @@ if (!$sidekick_active && !class_exists('Sidekick')){
676
  }
677
  }
678
 
679
- function deactivate_plugin(){
680
- $data = array(
681
- 'source' => 'plugin',
682
- 'action' => 'track',
683
- 'type' => 'deactivate',
684
- 'user' => get_option( "activation_id" )
685
- );
686
- $this->track($data);
687
- ?>
688
- <script type="text/javascript">
689
- window._gaq = window._gaq || [];
690
- window._gaq.push(['sk._setAccount', 'UA-39283622-1']);
691
-
692
- (function() {
693
- var ga_wpu = document.createElement('script'); ga_sk.type = 'text/javascript'; ga_sk.async = true;
694
- ga_sk.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
695
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga_wpu, s);
696
- })();
697
- window._gaq.push(['sk._trackEvent', 'Plugin - Deactivate', '', null, 0,true]);
698
- </script>
699
- <?php
700
- delete_option( 'sk_activated' );
701
  }
702
- }
703
- $sidekick = new Sidekick;
704
- register_activation_hook( __FILE__, array($sidekick,'activate_plugin') );
705
- register_deactivation_hook( __FILE__, array($sidekick,'deactivate_plugin') );
706
 
707
- // if (isset($_POST['sk_setting_disabled'])) $sidekick->set_disabled_wts();
708
- // if (isset($_POST['sk_setting_autostart'])) $sidekick->set_autostart_wt();
709
- // if (isset($_POST['sk_api'])) $sidekick->set_api();
710
- // if (isset($_GET['sk_ver_check'])) $sidekick->check_ver();
711
 
712
- if (isset($_POST['sk_setting_disabled'])) add_action('admin_init', array($sidekick,'set_disabled_wts'));
713
- if (isset($_POST['sk_setting_autostart'])) add_action('admin_init', array($sidekick,'set_autostart_wt'));
714
- if (isset($_POST['sk_api'])) add_action('admin_init', array($sidekick,'set_api'));
715
- if (isset($_GET['sk_ver_check'])) add_action('admin_init', array($sidekick,'check_ver'));
716
 
 
717
 
718
- add_action('admin_menu', array($sidekick,'setup_menu'));
 
 
 
 
 
 
719
  add_action('admin_init', array($sidekick,'redirect'));
 
 
720
  add_action('wp_ajax_sk_activate', array($sidekick,'activate'));
721
  add_action('wp_ajax_sk_save', array($sidekick,'ajax_save'));
722
  add_action('admin_notices', array($sidekick,'admin_notice'));
723
- add_action('admin_init', array($sidekick,'admin_notice_ignore'));
724
 
725
-
726
-
727
-
728
 
729
 
730
  if (defined('SK_PLUGIN_DEGBUG')) {
@@ -743,312 +785,505 @@ if (!(isset($_GET['tab']) && $_GET['tab'] == 'plugin-information') && !defined('
743
  }
744
  }
745
 
 
746
 
747
  if (!(isset($_GET['tab']) && $_GET['tab'] == 'plugin-information') && !defined('IFRAME_REQUEST')) {
748
  add_action('admin_footer', array($sidekick,'footer'));
749
  add_action('customize_controls_print_footer_scripts', array($sidekick,'footer'));
750
  }
751
- }
752
 
 
 
753
 
 
754
 
755
- // Multisite Licensing
 
756
 
757
- if (defined('MULTISITE')) {
758
-
 
 
 
 
 
759
 
760
  // licensing.php
761
 
762
  if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
763
 
764
- class sidekickMassActivator{
765
 
766
- function activate($blog_id, $user_id, $domain, $path){
767
- // mlog('FUNCTION: activate');
768
 
769
- $sk_auto_activations = get_option( 'sk_auto_activations');
 
770
 
771
- if ($sk_auto_activations) {
 
 
772
 
773
- $user = get_user_by('id',$user_id);
774
- $email = ($user) ? $user->user_email : 'unknown';
775
 
776
- // TODO: Send Domain for good measure
 
 
 
777
 
778
- $sk_selected_subscription = get_option("sk_selected_subscription");
779
- $sk_selected_product = get_option("sk_selected_product");
780
 
781
- if (isset($sk_selected_product) && $sk_selected_product) {
782
- $data = array('domainName' => $domain . $path, 'productId' => $sk_selected_product);
783
- } else if (strpos($sk_selected_subscription,'subscription-') !== false) {
784
- $sk_selected_subscription = explode('subscription-',$sk_selected_subscription);
785
- $data = array('domainName' => $domain . $path, 'subscriptionId' => $sk_selected_subscription[1]);
786
- }
787
 
788
- $result = $this->send_request('post','/domains',$data);
 
789
 
790
- if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
 
 
 
791
 
792
- if (!get_option('sk_activation_id')) {
793
- // Use the first site's activation key for the network key
794
- update_option('sk_activation_id',$result->payload->domainKey);
795
- }
 
 
796
 
797
- switch_to_blog($blog_id);
798
- update_option('sk_activation_id',$result->payload->domainKey);
799
- update_option('sk_email',$email);
800
- restore_current_blog();
801
 
802
- $this->track('Mass Activate',array('domain' => $domain,'email' => $email));
 
803
 
804
- delete_option('sk_auto_activation_error');
805
- } else {
806
 
807
- $this->track('Mass Activate Error',array('domain' => $domain, 'message' => $result->message,'email' => $email));
808
- update_option('sk_auto_activation_error',$result->message);
809
- wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
810
- }
811
- return $result;
812
- }
813
- return false;
814
- }
815
 
816
- function track($event,$data){
817
- if (file_exists(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php')) {
818
- require_once(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php');
819
- $mp = Mixpanel::getInstance("965556434c5ae652a44f24b85b442263");
820
- $domain = str_replace("http://","",$_SERVER["SERVER_NAME"]);
821
 
822
- $mp->track($event, $data);
823
- }
824
- }
 
825
 
826
- function activate_single(){
827
- die(json_encode($this->activate($_POST['blog_id'], $_POST['user_id'], $_POST['domain'], $_POST['path'])));
828
- }
829
 
830
- function send_request_curl($url, $post){
831
- $ch = curl_init($url);
832
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
833
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
834
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
835
- curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($post));
836
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
837
- $result = curl_exec($ch);
838
- curl_close($ch);
839
- return $result;
840
- }
841
 
842
- function send_request($type,$end_point, $data = null,$second_attempt = null){
843
- // var_dump('send_request');
844
- //var_dump("FUNCTION: send_request");
 
 
845
 
846
- if (strpos($_SERVER['SERVER_PROTOCOL'], 'https') === false) {
847
- $protocol = 'http:';
848
- } else {
849
- $protocol = 'https:';
850
- }
 
 
851
 
852
- $url = $protocol . SK_API . $end_point;
853
- $sk_token = get_transient('sk_token');
 
 
 
 
 
 
 
 
 
 
 
 
854
 
855
- if (!$sk_token && $end_point !== '/login') {
856
- $this->login();
857
- $sk_token = get_transient('sk_token');
858
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
859
 
860
- $headers = array('Content-Type:application/json');
861
 
862
- if ($sk_token && $end_point !== '/login') {
863
- $headers[] = "Authorization: $sk_token";
864
- }
865
 
866
- $ch = curl_init($url);
867
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($type));
868
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
869
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
870
- if ($data) {
871
- curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));
872
- }
873
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
874
- $result = curl_exec($ch);
875
- curl_close($ch);
876
 
877
- // echo $result; var_dump($url); var_dump($headers); var_dump($data); var_dump($result); die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
878
 
879
- if ($result == 'HTTP/1.1 401 Unauthorized' && !$second_attempt) {
880
- // var_dump('Getting rid of token and trying again');
881
- $this->login();
882
- delete_transient('sk_token');
883
- $this->send_request('post',$type,$data,true);
884
- }
885
 
886
- return json_decode($result);
887
- }
 
 
 
888
 
889
- function setup_menu(){
890
- add_submenu_page( 'settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins','sidekick-licensing', array(&$this,'admin_page'));
891
- }
892
 
893
- function login(){
894
- global $login_error;
 
895
 
896
- $email = get_option('sk_account');
897
- $password = get_option('sk_password');
898
- delete_option('sk_auto_activation_error');
899
 
900
- if (!$password || !$email) {
901
- return false;
902
- }
903
 
904
- $string = $password;
905
- $key = 'hash';
906
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
907
 
908
- $result = $this->send_request('post','/login',array('email' => $email, 'password' => $decrypted_password));
909
 
910
- if (!isset($result) || !$result->success) {
911
- delete_option( 'sk_token' );
912
- return array('error' => $result->message);
913
- } else {
914
- set_transient( 'sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS );
915
- $this->load_subscriptions($result->payload->token->value);
916
- return array('success' => true);
917
- }
918
- }
919
 
920
- function load_user_data(){
921
- return $this->send_request('get','/users/');
922
- }
923
 
924
- function load_subscriptions(){
925
 
926
- $result = $this->send_request('get','/users/subscriptions');
927
- $load_products = false;
928
 
929
- if (isset($result->success) && isset($result->payload)) {
 
 
 
 
 
 
 
 
 
 
930
 
931
- $sub = $result->payload[0];
 
 
 
 
 
 
 
932
 
933
- if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
934
- $this->logout();
935
- update_option( 'sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
936
- return false;
937
- } if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Private') {
938
- update_option( 'sk_selected_subscription', 'product-' . $sub->id );
939
- } else {
940
- update_option( 'sk_selected_subscription', 'subscription-' . $sub->id );
941
- }
942
 
943
- if (isset($sub->Plan->CreatableProductType) && isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') {
944
- $load_products = true;
945
- }
946
 
947
- if (count($sub->Domains) > 0) {
948
- foreach ($sub->Domains as &$domain) {
949
- if (!$domain->DomainSubscription->end) {
950
- if (isset($sub->activeDomainCount)) {
951
- $sub->activeDomainCount++;
952
- } else {
953
- $sub->activeDomainCount = 1;
954
- }
955
- }
956
- }
957
- } if (count($sub->PrivateProductSubscriptions) > 0) {
958
- foreach ($sub->PrivateProductSubscriptions as &$domain) {
959
- if (isset($sub->activeDomainCount)) {
960
- $sub->activeDomainCount++;
961
- } else {
962
- $sub->activeDomainCount = 1;
963
- }
964
- }
965
- } else {
966
- $sub->activeDomainCount = 0;
967
- }
968
 
969
- $data['subscriptions'] = $result->payload;
 
970
 
971
- if ($load_products) {
972
- $data['products'] = $this->load_products();
973
- }
974
 
975
- return $data;
976
- } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
977
- $this->logout();
978
- update_option( 'sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
979
- }
980
- return null;
981
- }
 
982
 
983
- function logout(){
984
- delete_option( 'sk_account');
985
- delete_option( 'sk_password');
986
- delete_option( 'sk_selected_subscription');
987
- delete_option( 'sk_selected_product');
988
- }
989
 
990
- function load_products(){
991
- $result = $this->send_request('get','/products');
992
- if ($result->success) {
993
- return $result->payload->products;
994
- }
995
- return null;
996
- }
997
 
998
- function admin_page(){
999
- if (isset($_POST['sk_account'])) {
1000
 
1001
- delete_option('sk_auto_activation_error');
 
 
1002
 
1003
- if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
1004
- $key = 'hash';
1005
- $string = $_POST['sk_password'];
1006
 
1007
- $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
1008
- $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
 
1009
 
1010
- update_option( 'sk_account', $_POST['sk_account'] );
1011
- update_option( 'sk_password', $encrypted_password );
1012
- $login_status = $this->login();
1013
- delete_option('sk_auto_activation_error');
1014
- } else {
1015
- update_option( 'sk_selected_subscription', $_POST['sk_selected_subscription'] );
1016
- }
1017
 
1018
- if (isset($_POST['sk_auto_activations'])) {
1019
- update_option( 'sk_auto_activations', true );
1020
- } else {
1021
- delete_option( 'sk_auto_activations');
1022
- }
1023
 
1024
- if (isset($_POST['sk_selected_product']) && $_POST['sk_selected_product'] !== '0' && isset($_POST['sk_selected_subscription']) && strpos($_POST['sk_selected_subscription'], 'product') !== false) {
1025
- update_option( 'sk_selected_product', $_POST['sk_selected_product'] );
1026
- } else {
1027
- delete_option( 'sk_selected_product');
1028
- }
1029
 
1030
- }
 
 
1031
 
1032
- $sk_token = get_transient('sk_token');
1033
- if (!$sk_token) {
1034
- $login_status = $this->login();
1035
- }
1036
- $sk_subs = $this->load_subscriptions();
1037
- $user_data = $this->load_user_data();
1038
- $sk_auto_activations = get_option( 'sk_auto_activations');
1039
- $sk_auto_activation_error = get_option('sk_auto_activation_error');
1040
- $sk_selected_subscription = get_option('sk_selected_subscription');
1041
- $sk_selected_product = get_option('sk_selected_product');
1042
- $is_ms_admin = true;
1043
- $curl = function_exists('curl_version') ? true : false;
1044
- $fgets = file_get_contents(__FILE__) ? true : false;
1045
- $fgets_url = ini_get('allow_url_fopen') ? true : false;
1046
-
1047
- if ($curl && (!$fgets || !$fgets_url)) {
1048
- $error = "Sorry, SIDEKICK MultiSite activations require <b>CURL</b> or <b>file_get_contents</b> functions enabled in PHP.";
1049
- }
1050
 
1051
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1052
  ?> <!-- ms_admin_page.php -->
1053
 
1054
  <script type="text/javascript">
@@ -1059,7 +1294,9 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1059
  var sk_ms_admin = true;
1060
 
1061
  jQuery(document).ready(function($) {
1062
- mixpanel.track('Network Settings Page Visit - Plugin');
 
 
1063
  });
1064
 
1065
  </script>
@@ -1125,73 +1362,29 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1125
  <input class='regular-text' type='password' name='sk_password' placeholder='********'></input>
1126
  </td>
1127
  </tr>
1128
- <tr valign="top" style='display: none'>
1129
- <th scope="row" valign="top">Subscription</th>
 
1130
  <td>
1131
- <select name='sk_selected_subscription'>
1132
- <?php if (isset($sk_subs['subscriptions']) && count($sk_subs['subscriptions']) > 0): ?>
1133
- <?php foreach ($sk_subs['subscriptions'] as $key => $sub): ?>
1134
- <?php
1135
- if ($sub->PlanId !== 1 && $sub->Plan->CreatableProductType->name !== 'Private') {
1136
- continue;
1137
- }
1138
-
1139
- if (isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') {
1140
- $type = 'product';
1141
- } else {
1142
- $type = 'subscription';
1143
- }
1144
-
1145
-
1146
- if ($sk_selected_subscription == ($type . '-' . $sub->id) || !isset($selected_sub)) {
1147
- $selected_sub = $sub;
1148
- $selected = 'SELECTED';
1149
- } else {
1150
- $selected = '';
1151
- }
1152
- ?>
1153
- <option <?php echo $selected ?> value='<?php echo (isset($sub->Plan->CreatableProductType->name) && $sub->Plan->CreatableProductType->name == 'Private') ? "product-" : "subscription-"; echo $sub->id ?>'><?php echo $sub->Plan->name . ' - ' . $sub->CurrentTier->name ?></option>
1154
  <?php endforeach ?>
1155
- <?php if (!isset($selected_sub)): ?>
1156
- <option value='0'>No Compatible Subscriptions</option>
1157
- <?php endif ?>
1158
- <?php else: ?>
1159
- <option>No Subscriptions</option>
1160
  <?php endif ?>
 
1161
  </select>
1162
  </td>
1163
  </tr>
1164
- <?php if (isset($sk_subs['products'])): ?>
1165
 
1166
- <tr valign="top" style='display: none' class='walkthrough_library'>
1167
- <th scope="row" valign="top">Library</th>
1168
- <td>
1169
- <select name='sk_selected_product'>
1170
- <?php if (isset($sk_subs['products']) && count($sk_subs['products']) > 0): ?>
1171
- <?php foreach ($sk_subs['products'] as $key => $product): ?>
1172
- <option <?php echo ($sk_selected_product == $product->id) ? 'SELECTED' : '' ?> value='<?php echo $product->id ?>'><?php echo $product->name ?></option>
1173
- <?php endforeach ?>
1174
- <?php else: ?>
1175
- <option style='color: red' value='0'>No Libraries Found!</option>
1176
- <?php $no_product = true; delete_option( 'sk_auto_activations') ?>
1177
- <?php endif ?>
1178
- </select>
1179
- </td>
1180
- </tr>
1181
-
1182
- <?php endif ?>
1183
 
1184
  <tr valign="top">
1185
  <th scope="row" valign="top">Enable Auto-Activations</th>
1186
  <td>
1187
- <?php if (!isset($selected_sub) || isset($no_product)): ?>
1188
- <input class='checkbox' type='checkbox' name='sk_auto_activations' DISABLED>
1189
- <?php else: ?>
1190
- <input class='checkbox' type='checkbox' name='sk_auto_activations' <?php echo ($sk_auto_activations) ? 'CHECKED' : '' ?>>
1191
- <?php endif ?>
1192
  </td>
1193
  </tr>
1194
- <?php //var_dump($selected_sub); ?>
1195
  <?php if (isset($selected_sub) && !isset($no_product)): ?>
1196
  <tr>
1197
  <th scope="row" valign="top">Active Domains</th>
@@ -1236,46 +1429,48 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1236
 
1237
  <div class="sk_box sites">
1238
  <div class="well">
1239
- <h3>Sidekick Network Activations - (<a class='activate_all' href='#'>Activate All</a>)</h3>
1240
-
1241
- <p>To manage your complete list of domains please login to your <a href='https://www.sidekick.pro/profile/#' target='_blank'>account center</a>.</p>
1242
-
1243
- <?php $blogs = wp_get_sites(array('limit' => 10000)) ?>
1244
- <ul>
1245
- <?php foreach ($blogs as $key => $blog): ?>
1246
- <?php
1247
-
1248
- switch_to_blog($blog['blog_id']);
1249
-
1250
- if ($user = get_user_by('email', get_option('admin_email'))) {
1251
- $user_id = $user->ID;
1252
- } else {
1253
- $user_id = null;
1254
- }
1255
-
1256
- $key = get_option('sk_activation_id');
1257
- if ($key) $last_key = $key;
1258
-
1259
- $turn_on_button = '';
1260
 
1261
- if (isset($selected_sub)) {
1262
- $turn_on_button = "<button class=\"activate_sk\" data-blogid=\"{$blog["blog_id"]}\" data-userid=\"{$user_id}\" data-domain=\"{$blog["domain"]}\" data-path=\"{$blog["path"]}\">Turn On</button>";
1263
- }
1264
 
1265
- ?>
1266
 
1267
- <li>
1268
- <div class='bold'>
1269
- <h3><?php echo ucfirst(str_replace('/', '', $blog['path'])) ?></h3>
1270
- <?php echo $blog['domain'] . $blog['path'] ?>
1271
- <span><?php echo ($key) ? ' - <span class="green">Active</span>' : " - <span class=\"not_active\">Not Activated</span> $turn_on_button" ?></span>
1272
- </div>
1273
- </li>
1274
- <?php endforeach ?>
1275
- </ul>
 
 
 
1276
 
1277
  <div class="single_activation_error red"></div>
1278
 
 
 
 
1279
 
1280
  </div>
1281
  </div>
@@ -1309,6 +1504,51 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1309
  </div>
1310
  </div>
1311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1312
  <div class="sk_box configure">
1313
  <div class="well">
1314
  <form method='post'>
@@ -1339,15 +1579,24 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1339
 
1340
  <?php
1341
 
1342
- }
1343
- }
1344
  }
1345
 
1346
  // //licensing.php
1347
- $sidekickMassActivator = new sidekickMassActivator;
1348
- add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
1349
- add_action('network_admin_menu', array($sidekickMassActivator,'setup_menu'));
1350
- add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
 
 
 
 
 
 
 
 
 
1351
  }
1352
 
1353
 
@@ -1356,6 +1605,9 @@ if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
1356
  if (!$sidekick_active && !class_exists('sk_config_data')) {
1357
 
1358
  class sk_config_data{
 
 
 
1359
  function get_domain(){
1360
  $site_url = get_site_url();
1361
  if(substr($site_url, -1) == '/') {
@@ -1365,17 +1617,26 @@ if (!$sidekick_active && !class_exists('sk_config_data')) {
1365
  return $site_url;
1366
  }
1367
 
 
 
 
1368
  function get_post_types(){
1369
  global $wpdb;
1370
- $query = "SELECT post_type, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type";
1371
- $counts = $wpdb->get_results($query);
1372
- $output = '';
1373
 
1374
- foreach ($counts as $key => $type) {
1375
- $type->post_type = str_replace('-', '_', $type->post_type);
1376
- $output .= "\n post_type_{$type->post_type} : $type->count,";
 
 
 
 
 
 
 
 
1377
  }
1378
- return $output;
 
1379
  }
1380
 
1381
  function get_file_editor_enabled(){
@@ -1392,72 +1653,102 @@ if (!$sidekick_active && !class_exists('sk_config_data')) {
1392
  }
1393
 
1394
  function get_themes(){
1395
- $themes = wp_get_themes( array( 'allowed' => true ) );
1396
- return count($themes);
 
 
 
 
1397
  }
1398
 
1399
  function get_post_types_and_statuses(){
1400
  global $wpdb;
1401
- $query = "SELECT post_type, post_status, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type, post_status";
1402
- $counts = $wpdb->get_results($query);
1403
- $output = '';
1404
 
1405
- foreach ($counts as $key => $type) {
1406
- $type->post_type = str_replace('-', '_', $type->post_type);
1407
- $type->post_status = str_replace('-', '_', $type->post_status);
 
 
1408
 
1409
- $output .= "\n post_type_{$type->post_type}_{$type->post_status} : $type->count,";
1410
- }
1411
- return $output;
 
 
 
 
 
 
 
1412
  }
1413
 
1414
  function get_taxonomies(){
1415
  global $wpdb;
1416
- $query = "SELECT count(distinct term_taxonomy_id) as count, taxonomy from {$wpdb->prefix}term_taxonomy group by taxonomy";
1417
- $counts = $wpdb->get_results($query);
1418
- $output = '';
1419
 
1420
- foreach ($counts as $key => $taxonomy) {
1421
- $taxonomy->taxonomy = str_replace('-', '_', $taxonomy->taxonomy);
1422
- $output .= "\n taxonomy_{$taxonomy->taxonomy} : $taxonomy->count,";
1423
- }
1424
- return $output;
 
 
 
 
 
 
 
 
1425
  }
1426
 
1427
  function get_comments(){
1428
  global $wpdb;
1429
- $query = "SELECT count(distinct comment_ID) as count from {$wpdb->prefix}comments";
1430
- $counts = $wpdb->get_var($query);
1431
- if (!$counts) $counts = 0;
1432
- return "\n comment_count : $counts,";
 
 
 
 
 
 
1433
  }
1434
 
1435
  function get_post_statuses(){
1436
  global $wpdb;
1437
- $query = "SELECT post_status, count(ID) as count from {$wpdb->prefix}posts group by post_status";
1438
- $counts = $wpdb->get_results($query);
1439
- $output = '';
1440
 
1441
- foreach ($counts as $key => $type) {
1442
- $type->post_status = str_replace('-', '_', $type->post_status);
1443
- $output .= "\n post_status_{$type->post_status} : $type->count,";
 
 
 
 
 
 
 
1444
  }
1445
- return $output;
 
1446
  }
1447
 
1448
  function get_user_data(){
1449
  global $current_user;
1450
 
1451
- $data = get_userdata($current_user->ID);
1452
- $output = "\n user_id : $current_user->ID,";
 
1453
 
1454
- foreach ($data->allcaps as $cap => $val) {
1455
- $cap = sanitize_title($cap);
1456
- $cap = str_replace('-', '_', $cap);
1457
- if (!$val) $val = 0;
1458
- $output .= "\n cap_{$cap} : $val,";
 
 
1459
  }
1460
- return $output;
 
1461
  }
1462
 
1463
  function get_framework(){
@@ -1516,26 +1807,30 @@ if (!$sidekick_active && !class_exists('sk_config_data')) {
1516
 
1517
  function get_plugins(){
1518
 
1519
- $active_plugins = wp_get_active_and_valid_plugins();
1520
- $mu_plugins = get_mu_plugins();
1521
- $output = array();
1522
-
1523
- if (is_array($active_plugins)) {
1524
- foreach ($active_plugins as $plugins_key => $plugin) {
1525
- $data = get_plugin_data( $plugin, false, false );
1526
- $slug = explode('/',plugin_basename($plugin));
1527
- $slug = str_replace('.php', '', $slug[1]);
1528
- $output[$slug] = $data['Version'];
 
 
1529
  }
1530
- }
1531
 
1532
- if (is_array($mu_plugins)) {
1533
- foreach ($mu_plugins as $plugins_key => $plugin) {
1534
- $slug = str_replace('.php', '', $plugins_key);
1535
- $output[$slug] = '1.0.0';
 
1536
  }
 
1537
  }
1538
- return $output;
 
1539
  }
1540
 
1541
  function get_user_role(){
@@ -1559,6 +1854,7 @@ if (!$sidekick_active && !class_exists('sk_config_data')) {
1559
  }
1560
  return $user_role;
1561
  }
 
1562
  }
1563
  }
1564
 
8
  We recommend not activating SIDEKICK automatically for people but via an Opt-In process when they configure your own theme or plugin.
9
  Requires at least: 4.0
10
  Tested up to: 4.1.1
11
+ Version: 2.3.0
12
  Author: Sidekick.pro
13
  Author URI: http://www.sidekick.pro
14
  */
51
  wp_enqueue_script('jquery-ui-droppable' , null, array('jquery-ui-core') );
52
  wp_enqueue_script('jquery-effects-scale' , null, array('jquery-ui-core') );
53
  wp_enqueue_script('jquery-effects-highlight' , null, array('jquery-ui-core') );
54
+ wp_enqueue_script('sidekick-admin' , '//assets.sidekick.pro/plugin/tag/latest/js/sidekick_admin.js',array( 'jquery' ), null);
55
  }
56
 
57
  function enqueue(){
86
  delete_option('sk_activation_id');
87
  }
88
 
 
 
 
 
 
 
89
  if (isset($_POST['sk_track_data'])) {
90
  update_option( 'sk_track_data', true );
91
  } else {
98
 
99
  }
100
 
101
+ $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
102
+ $sk_track_data = get_option( 'sk_track_data' );
103
+ $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
104
+ $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
105
+ $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
106
+ $current_user = wp_get_current_user();
107
+ $status = 'Free';
108
+ $error = null;
109
 
110
  if (isset($SK_PAID_LIBRARY_FILE) && $activation_id) {
111
  $_POST['activation_id'] = $activation_id;
188
  <tbody>
189
  <tr valign="top">
190
  <th scope="row" valign="top">Activation ID</th>
191
+ <?php if (is_multisite()): ?>
192
  <?php if (isset($activation_id) && $activation_id): ?>
193
  <td><input class='regular-text' style='color: gray;' type='text' name='activation_id' value='xxxxxxxx-xxxx-xxxx-xxxx-<?php echo substr($activation_id, 25,20) ?>'></input></td>
194
  <?php else: ?>
215
  </td>
216
  </tr>
217
 
218
+ <tr valign="top">
219
  <th scope="row" valign="top">
220
  Enable Composer Mode
221
  </th>
222
  <td>
223
+ <button class='open_composer'>Open Composer</button>
 
224
  </td>
225
  </tr>
226
  </tbody>
232
  </div>
233
  </div>
234
 
235
+ <div class="sk_box composer" style='display: none'>
236
  <div class="well">
237
  <h3>Build Your Own Walkthroughs</h3>
238
  <a href='http://www.sidekick.pro/plans/create_wp_walkthroughs/?utm_source=plugin&utm_medium=settings&utm_campaign=composer' target='_blank'><div class='composer_beta_button'>Build Your Own<br/>Walkthroughs</div></a>
313
  </div>
314
  </div>
315
 
316
+ <div class="sk_box configure">
317
+ <div class="well">
318
+ <h3>Configure - Other</h3>
319
+
320
+ <form method="post">
321
+ <?php settings_fields('sk_license'); ?>
322
+ <table class="form-table long_label">
323
+ <tbody>
324
+
325
+ <tr valign="top">
326
+ <th scope="row" valign="top">Hide Composer Button in Taskbar</th>
327
+ <td>
328
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_taskbar_button' <?php echo (isset($sk_hide_composer_taskbar_button) && $sk_hide_composer_taskbar_button) ? 'CHECKED' : '' ?>>
329
+ </td>
330
+ </tr>
331
+ <tr valign="top">
332
+ <th scope="row" valign="top">Hide Config Button in Taskbar</th>
333
+ <td>
334
+ <input class='checkbox' type='checkbox' name='sk_hide_config_taskbar_button' <?php echo (isset($sk_hide_config_taskbar_button) && $sk_hide_config_taskbar_button) ? 'CHECKED' : '' ?>>
335
+ </td>
336
+ </tr>
337
+ <tr valign="top">
338
+ <th scope="row" valign="top">Hide Composer Upgrade Button in Drawer</th>
339
+ <td>
340
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_upgrade_button' <?php echo (isset($sk_hide_composer_upgrade_button) && $sk_hide_composer_upgrade_button) ? 'CHECKED' : '' ?>>
341
+ </td>
342
+ </tr>
343
+ <tr valign="top">
344
+ <th scope="row" valign="top"></th>
345
+ <td>
346
+ <input class='button button-primary' type='submit' value='Save'/>
347
+ </td>
348
+ </tr>
349
+
350
+ <input type='hidden' name='is_ms_admin' value='<?php echo (isset($is_ms_admin)) ? $is_ms_admin : false ?>'/>
351
+ <input type='hidden' name='sk_setting_other' value='true'/>
352
+
353
+ <?php wp_nonce_field( 'update_sk_settings' ); ?>
354
+
355
+ </tbody>
356
+ </table>
357
+ </form>
358
+ </div>
359
+ </div>
360
+
361
  <div class="sk_box configure">
362
  <div class="well">
363
  <form method='post'>
403
 
404
  function set_disabled_wts(){
405
 
 
 
 
 
406
 
407
+ if (isset($_POST['sk_setting_disabled'])){
408
 
409
+ if (!check_admin_referer('update_sk_settings')) {
410
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
411
+ exit;
 
412
  }
413
+
414
+ $_POST['disable_wts'] = array_map("mysql_real_escape_string",$_POST['disable_wts']);
415
+
416
+ if (isset($_POST['disable_wts']) && $_POST['disable_wts']) {
417
+ update_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
418
+ if (is_network_admin()) {
419
+ update_site_option('sk_disabled_wts',json_encode($_POST['disable_wts']));
420
+ }
421
+ } else {
422
+ delete_option('sk_disabled_wts');
423
+ if (is_network_admin()) {
424
+ delete_site_option('sk_disabled_wts');
425
+ }
426
  }
427
  }
428
+
429
  }
430
 
431
  function set_autostart_wt(){
432
 
433
+ if (isset($_POST['sk_setting_autostart'])){
 
 
 
434
 
435
+ if (!check_admin_referer('update_sk_settings')) {
436
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
437
+ exit;
438
  }
439
+
440
+ if (isset($_POST['sk_autostart_walkthrough_id']) && intval($_POST['sk_autostart_walkthrough_id']) > 0){
441
+ if (is_network_admin()) {
442
+ update_site_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
443
+ }
444
+ update_option('sk_autostart_walkthrough_id',wp_filter_kses($_POST['sk_autostart_walkthrough_id']));
445
+ } else {
446
+ delete_option('sk_autostart_walkthrough_id');
447
+ if (is_network_admin()) {
448
+ delete_site_option('sk_autostart_walkthrough_id');
449
+ }
450
  }
451
  }
452
+
453
  }
454
 
455
+ function set_configure_other(){
456
 
457
+ if (isset($_POST['sk_setting_other'])){
 
 
 
458
 
459
+ if (!check_admin_referer('update_sk_settings')) {
460
+ print 'Sorry, your nonce did not verify or you\'re not logged in.';
461
+ exit;
462
+ }
463
+
464
+ $checkboxes = array('sk_hide_composer_taskbar_button','sk_hide_config_taskbar_button','sk_hide_composer_upgrade_button');
465
+
466
+ foreach ($checkboxes as $key => $checkbox) {
467
+ if (isset($_POST[$checkbox])){
468
+ if (is_network_admin()) {
469
+ update_site_option($checkbox,wp_filter_kses($_POST[$checkbox]));
470
+ }
471
+ update_option($checkbox,wp_filter_kses($_POST[$checkbox]));
472
+ } else {
473
+ delete_option($checkbox);
474
+ if (is_network_admin()) {
475
+ delete_site_option($checkbox);
476
+ }
477
+ }
478
+ }
479
 
 
 
 
480
  }
481
+
482
  }
483
 
484
  function footer(){
490
  $current_user = wp_get_current_user();
491
  $sk_just_activated = get_option( 'sk_just_activated' );
492
  $sk_track_data = get_option( 'sk_track_data' );
493
+ $sk_hide_composer_taskbar_button = get_option( 'sk_hide_composer_taskbar_button' );
494
+ $sk_hide_config_taskbar_button = get_option( 'sk_hide_config_taskbar_button' );
495
+ $sk_hide_composer_upgrade_button = get_option( 'sk_hide_composer_upgrade_button' );
496
  $activation_id = (get_option( "sk_activation_id" ) ? get_option( "sk_activation_id" ) : '');
497
  $autostart_network_walkthrough_id = (get_site_option('sk_autostart_walkthrough_id') ? get_site_option('sk_autostart_walkthrough_id') : 'null' );
498
  $autostart_walkthrough_id = (get_option('sk_autostart_walkthrough_id') ? get_option('sk_autostart_walkthrough_id') : $autostart_network_walkthrough_id );
499
  $custom_class = (get_option( "sk_custom_class" ) ? get_option( "sk_custom_class" ) : '');
500
  $theme = wp_get_theme();
501
  $not_supported_ie = false;
502
+ $user_email = ($sk_track_data) ? $current_user->user_email : '';
503
+ $disabled_wts = (!is_network_admin()) ? $sk_config_data->get_disabled_wts() : '[]';
504
+ $user_role = $sk_config_data->get_user_role();
505
+ $site_url = $sk_config_data->get_domain();
506
+ $installed_plugins = $sk_config_data->get_plugins();
507
+ $plugin_count = (isset($plugins) && is_array($plugins)) ? count($plugins) : array();
508
+ $disabled_network_wts = $sk_config_data->get_disabled_network_wts();
509
+ $current_url = $sk_config_data->get_current_url();
510
+ $post_types = $sk_config_data->get_post_types();
511
+ $taxonomies = $sk_config_data->get_taxonomies();
512
+ $user_data = $sk_config_data->get_user_data();
513
+ $comments = $sk_config_data->get_comments();
514
+ $post_statuses = $sk_config_data->get_post_statuses();
515
+ $post_types_and_statuses = $sk_config_data->get_post_types_and_statuses();
516
+ $number_of_themes = $sk_config_data->get_themes();
517
+ $frameworks = $sk_config_data->get_framework();
518
+ $file_editor_enabled = $sk_config_data->get_file_editor_enabled();
519
+
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
 
522
  delete_option( 'sk_just_activated' );
523
  if(preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT'])) $not_supported_ie = true;
524
 
525
  ?>
526
 
 
527
  <?php if (!$not_supported_ie): ?>
528
 
529
  <script type="text/javascript">
548
  installed_theme: '<?php echo sanitize_title($theme->Name) ?>',
549
  theme_version: '<?php echo $theme->Version ?>',
550
  main_soft_version: '<?php echo get_bloginfo("version") ?>',
551
+ // main_soft_version: '4.5.1',
552
  user_level: '<?php echo $user_role ?>',
553
  main_soft_name: 'WordPress',
554
  file_editor_enabled: <?php echo ($file_editor_enabled) ? $file_editor_enabled: 'null' ?>,
566
  auto_open_product: 'default',
567
  disable_wts_in_root_bucket_ids: [5,87],
568
  autostart_walkthrough_id: <?php echo $autostart_walkthrough_id ?>,
 
569
  track_data: '<?php echo $sk_track_data ?>',
570
  user_email: '<?php echo $user_email ?>',
571
  custom_class: '<?php echo $custom_class ?>',
572
 
573
  // Toggles
574
+ path_not_found_continue: true,
575
+ show_powered_by: true,
576
+ show_powered_by_link: true,
577
+ sk_autostart_only_once: true,
578
+ use_native_controls: false,
579
+ basics_upgrade: true,
580
+ composer_upgrade_off: <?php echo ($sk_hide_composer_upgrade_button ? "true" : "false") ?>,
581
+ hide_taskbar_composer_button: <?php echo ($sk_hide_composer_taskbar_button ? "true" : "false") ?>,
582
+ hide_taskbar_config_button: <?php echo ($sk_hide_config_taskbar_button ? "true" : "false") ?>,
583
 
584
  // Platform Info
585
  library_version: 2,
588
 
589
  // Generic Info
590
  just_activated: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
 
 
591
  show_login: <?php echo ($sk_just_activated) ? "true" : "false" ?>,
592
+ platform_version: null,
593
+ plugin_version: '2.3.0',
594
 
595
  // SIDEKICK URLS
596
  assets: '<?php echo SK_ASSETS ?>',
607
  plugin_url: '<?php echo admin_url("admin.php?page=sidekick") ?>',
608
  base_url: '<?php echo site_url() ?>',
609
  current_url: '<?php echo $current_url ?>'
 
610
  }
611
 
612
  var skc_config = {
675
  function activate_plugin(){
676
  update_option( 'sk_firstuse', true );
677
  update_option( 'sk_do_activation_redirect', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
  }
679
 
680
  function redirect(){
688
 
689
  function check_ver(){
690
 
691
+ if (isset($_GET['sk_ver_check'])){
692
+ $data = json_encode('2.3.0');
693
 
694
+ if(array_key_exists('callback', $_GET)){
695
 
696
+ header('Content-Type: text/javascript; charset=utf8');
697
+ header('Access-Control-Allow-Origin: http://www.example.com/');
698
+ header('Access-Control-Max-Age: 3628800');
699
+ header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
700
 
701
+ $callback = $_GET['callback'];
702
+ echo $callback.'('.$data.');';
703
 
704
+ }else{
705
+ header('Content-Type: application/json; charset=utf8');
706
 
707
+ echo $data;
708
+ }
709
+
710
+ die();
711
  }
712
 
 
713
  }
714
 
715
  function admin_notice() {
727
  }
728
  }
729
 
730
+ // Clear transients for cached sk_config_data
731
+
732
+ function delete_sk_get_comments(){
733
+ mlog("delete_sk_get_comments");
734
+ delete_transient('sk_get_comments');
735
+ }
736
+
737
+ function delete_sk_get_post_types(){
738
+ mlog('delete sk_get_post_types');
739
+ delete_transient('sk_get_post_types');
740
+ delete_transient('sk_post_statuses');
 
 
 
 
 
 
 
 
 
 
 
741
  }
 
 
 
 
742
 
743
+ function delete_sk_get_user_data(){
744
+ mlog('delete sk_get_user_data');
745
+ delete_transient('sk_get_user_data');
746
+ }
747
 
748
+ function delete_sk_get_plugins(){
749
+ mlog('delete sk_get_plugins');
750
+ delete_transient('sk_get_plugins');
751
+ }
752
 
753
+ }
754
 
755
+ $sidekick = new Sidekick;
756
+ register_activation_hook( __FILE__, array($sidekick,'activate_plugin') );
757
+
758
+ add_action('admin_init', array($sidekick,'set_disabled_wts'));
759
+ add_action('admin_init', array($sidekick,'set_autostart_wt'));
760
+ add_action('admin_init', array($sidekick,'set_configure_other'));
761
+ add_action('admin_init', array($sidekick,'check_ver'));
762
  add_action('admin_init', array($sidekick,'redirect'));
763
+ add_action('admin_init', array($sidekick,'admin_notice_ignore'));
764
+ add_action('admin_menu', array($sidekick,'setup_menu'));
765
  add_action('wp_ajax_sk_activate', array($sidekick,'activate'));
766
  add_action('wp_ajax_sk_save', array($sidekick,'ajax_save'));
767
  add_action('admin_notices', array($sidekick,'admin_notice'));
 
768
 
769
+ {
 
 
770
 
771
 
772
  if (defined('SK_PLUGIN_DEGBUG')) {
785
  }
786
  }
787
 
788
+ }
789
 
790
  if (!(isset($_GET['tab']) && $_GET['tab'] == 'plugin-information') && !defined('IFRAME_REQUEST')) {
791
  add_action('admin_footer', array($sidekick,'footer'));
792
  add_action('customize_controls_print_footer_scripts', array($sidekick,'footer'));
793
  }
 
794
 
795
+ add_action('transition_post_status',array($sidekick,'delete_sk_get_post_types_and_statuses'));
796
+ add_action('clean_post_cache',array($sidekick,'delete_sk_get_post_types_and_statuses'));
797
 
798
+ add_action('wp_update_comment_count',array($sidekick,'delete_sk_get_comments'));
799
 
800
+ add_action('set_user_role',array($sidekick,'delete_sk_get_user_data'));
801
+ add_action('edit_user_profile',array($sidekick,'delete_sk_get_user_data'));
802
 
803
+ add_action('activated_plugin',array($sidekick,'delete_sk_get_plugins'));
804
+ add_action('deactivated_plugin',array($sidekick,'delete_sk_get_plugins'));
805
+
806
+ // Multisite Licensing
807
+
808
+ if (is_multisite()) {
809
+
810
 
811
  // licensing.php
812
 
813
  if (!$sidekick_active && !class_exists('sidekickMassActivator')) {
814
 
815
+ class sidekickMassActivator {
816
 
817
+ var $sites_per_page = 25;
818
+ var $offet = 0;
819
 
820
+ function activate($blog_id, $user_id, $domain, $path) {
821
+ mlog("FUNCTION: activate [$blog_id, $user_id, $domain, $path]");
822
 
823
+ switch_to_blog($blog_id);
824
+ $sk_activation_id = get_option('sk_activation_id');
825
+ restore_current_blog();
826
 
827
+ $checked_blogs = get_option('sk_checked_blogs');
 
828
 
829
+ if (isset($checked_blogs['active'][$blog_id]) || $sk_activation_id) {
830
+ unset($checked_blogs['unactivated'][$blog_id]);
831
+ $blog = $this->get_blog_by_id($blog_id);
832
+ $checked_blogs['active'][$blog_id] = $blog[0];
833
 
834
+ update_option('sk_checked_blogs', $checked_blogs);
 
835
 
836
+ $result = array(
837
+ "payload" => array(
838
+ "blog" => $blog[0],
839
+ "message" => "Already Activated",
840
+ ),
841
+ );
842
 
843
+ return json_encode($result);
844
+ }
845
 
846
+ $user = get_user_by('id', $user_id);
847
+ $email = ($user) ? $user->user_email : 'unknown';
848
+ $sk_subscription_id = get_option("sk_subscription_id");
849
+ $sk_selected_library = get_option("sk_selected_library");
850
 
851
+ if (isset($sk_selected_library) && $sk_selected_library && $sk_selected_library !== -1 && $sk_selected_library !== '-1') {
852
+ $data = array('domainName' => $domain . '/' . $path, 'productId' => $sk_selected_library);
853
+ } elseif (isset($sk_subscription_id) && intval($sk_subscription_id)) {
854
+ $data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
855
+ } else {
856
+ update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
857
 
 
 
 
 
858
 
859
+ return false;
860
+ }
861
 
862
+ $result = $this->send_request('post', '/domains', $data);
 
863
 
864
+ if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
 
 
 
 
 
 
 
865
 
866
+ $this->setup_super_admin_key($result->payload->domainKey);
 
 
 
 
867
 
868
+ switch_to_blog($blog_id);
869
+ update_option('sk_activation_id', $result->payload->domainKey);
870
+ update_option('sk_email', $email);
871
+ restore_current_blog();
872
 
873
+ $this->track('Mass Activate', array('domain' => $domain, 'email' => $email));
 
 
874
 
875
+ if (isset($checked_blogs['deactivated'][$blog_id])) {
876
+ $checked_blogs['active'][$blog_id] = $checked_blogs['deactivated'][$blog_id];
877
+ unset($checked_blogs['deactivated'][$blog_id]);
878
+ } else if (isset($checked_blogs['unactivated'][$blog_id])) {
879
+ $checked_blogs['active'][$blog_id] = $checked_blogs['unactivated'][$blog_id];
880
+ unset($checked_blogs['unactivated'][$blog_id]);
881
+ }
 
 
 
 
882
 
883
+ update_option('sk_checked_blogs', $checked_blogs);
884
+ update_option('sk_last_setup_blog_id', $blog_id);
885
+
886
+ delete_option('sk_auto_activation_error');
887
+ } else {
888
 
889
+ $this->track('Mass Activate Error', array('domain' => $domain, 'message' => $result->message, 'email' => $email));
890
+ update_option('sk_auto_activation_error', $result->message);
891
+ // wp_mail( 'support@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
892
+ wp_mail('bart@sidekick.pro', 'Failed Mass Domain Add', json_encode($result));
893
+ }
894
+
895
+ return $result;
896
 
897
+ }
898
+
899
+ function setup_super_admin_key($domainKey) {
900
+ // Use the super admin's site activation key if not set using last activation key
901
+ if (!get_option('sk_activation_id')) {
902
+ update_option('sk_activation_id', $domainKey);
903
+ }
904
+ }
905
+
906
+ function track($event, $data) {
907
+ if (file_exists(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php')) {
908
+ require_once(realpath(dirname(__FILE__)) . '/mixpanel/Mixpanel.php');
909
+ $mp = Mixpanel::getInstance("965556434c5ae652a44f24b85b442263");
910
+ $domain = str_replace("http://", "", $_SERVER["SERVER_NAME"]);
911
 
912
+ $mp->track($event, $data);
913
+ }
914
+ }
915
+
916
+ function activate_batch() {
917
+ $checked_blogs = get_option('sk_checked_blogs');
918
+ $count = 0;
919
+
920
+ if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated'])) {
921
+ foreach ($checked_blogs['unactivated'] as $key => $blog) {
922
+ if ($count == $this->sites_per_page) {
923
+ break;
924
+ }
925
+ $this->activate($blog->blog_id, $blog->user_id, $blog->domain, $blog->path);
926
+ $count++;
927
+ }
928
+ }
929
+ //mlog('$checked_blogs',$checked_blogs);
930
+
931
+ $result = array('activated_count' => $count, 'sites_per_page' => $this->sites_per_page, 'unactivated_count' => count($checked_blogs['unactivated']));
932
+ die(json_encode($result));
933
+ }
934
+
935
+ function activate_single() {
936
+ $result = $this->activate($_POST['blog_id'], $_POST['user_id'], $_POST['domain'], $_POST['path']);
937
+ die(json_encode($result));
938
+ }
939
+
940
+ function deactivate_single() {
941
+
942
+ $checked_blogs = get_option('sk_checked_blogs');
943
+ $blog_id = $_POST['blog_id'];
944
+
945
+ if (isset($checked_blogs['active'][$_POST['blog_id']])) {
946
+ $checked_blogs['deactivated'][$blog_id] = $checked_blogs['active'][$blog_id];
947
+ unset($checked_blogs['active'][$blog_id]);
948
+ update_option('sk_checked_blogs', $checked_blogs);
949
+ die('{"success":1}');
950
+ } else {
951
+ die('{"payload":{"message":"Error #13"}}');
952
+ }
953
+ }
954
 
955
+ function send_request($type, $end_point, $data = null, $second_attempt = null) {
956
 
957
+ // var_dump("FUNCTION: send_request [$type] -> $end_point");
 
 
958
 
959
+ if (strpos($_SERVER['SERVER_PROTOCOL'], 'https') === false) {
960
+ $protocol = 'http:';
961
+ } else {
962
+ $protocol = 'https:';
963
+ }
 
 
 
 
 
964
 
965
+ $url = $protocol . SK_API . $end_point;
966
+ $sk_token = get_transient('sk_token');
967
+
968
+ if (!$sk_token && $end_point !== '/login') {
969
+ $this->login();
970
+ $sk_token = get_transient('sk_token');
971
+ }
972
+
973
+ $headers = array('Content-Type' => 'application/json');
974
+
975
+ if ($sk_token && $end_point !== '/login') {
976
+ $headers['Authorization'] = $sk_token;
977
+ }
978
+
979
+ $args = array(
980
+ 'timeout' => 45,
981
+ 'redirection' => 5,
982
+ 'httpversion' => '1.0',
983
+ 'blocking' => true,
984
+ 'headers' => $headers
985
+ );
986
+
987
+ if (isset($type) && $type == 'post') {
988
+ $args['method'] = 'POST';
989
+ $args['body'] = json_encode($data);
990
+ } else if (isset($type) && $type == 'get') {
991
+ $args['method'] = 'GET';
992
+ $args['body'] = $data;
993
+ }
994
+
995
+ $result = wp_remote_post($url, $args);
996
+
997
+ if ($result['response']['message'] == 'Unauthorized' && !$second_attempt) {
998
+ // var_dump('Getting rid of token and trying again');
999
+ delete_transient('sk_token');
1000
+ $this->login();
1001
+
1002
+ return $this->send_request($type, $end_point, $data, true);
1003
+ }
1004
+
1005
+ return json_decode($result['body']);
1006
+ }
1007
+
1008
+ function setup_menu() {
1009
+ add_submenu_page('settings.php', 'Sidekick - Licensing', 'Sidekick - Licensing', 'activate_plugins', 'sidekick-licensing', array(&$this, 'admin_page'));
1010
+ }
1011
+
1012
+ function login() {
1013
+ $email = get_option('sk_account');
1014
+ $password = get_option('sk_password');
1015
+ delete_option('sk_auto_activation_error');
1016
+
1017
+ if (!$password || !$email) {
1018
+ return false;
1019
+ }
1020
+
1021
+ $key = 'hash';
1022
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
1023
+
1024
+ $result = $this->send_request('post', '/login', array('email' => $email, 'password' => $decrypted_password));
1025
 
1026
+ if (!isset($result) || !$result->success) {
1027
+ delete_option('sk_token');
 
 
 
 
1028
 
1029
+ return array('error' => $result->message);
1030
+ } else {
1031
+ set_transient('sk_token', $result->payload->token->value, 24 * HOUR_IN_SECONDS);
1032
+ // var_dump($result->payload->token->value);
1033
+ $this->load_subscriptions($result->payload->token->value);
1034
 
1035
+ return array('success' => true);
1036
+ }
1037
+ }
1038
 
1039
+ function load_user_data() {
1040
+ return $this->send_request('get', '/users/');
1041
+ }
1042
 
1043
+ function load_subscriptions() {
 
 
1044
 
1045
+ $result = $this->send_request('get', '/users/subscriptions');
 
 
1046
 
1047
+ if (isset($result->success) && isset($result->payload)) {
 
 
1048
 
1049
+ $sub = $result->payload[0];
1050
 
1051
+ if (isset($sub->Plan->CreatableProductType) && $sub->Plan->CreatableProductType->name == 'Public') {
1052
+ $this->logout();
1053
+ update_option('sk_auto_activation_error', 'Public accounts are not compatible with MultiSite activations.');
 
 
 
 
 
 
1054
 
1055
+ return false;
1056
+ }
 
1057
 
1058
+ update_option('sk_subscription_id', $sub->id);
1059
 
1060
+ $sub->activeDomainCount = 0;
 
1061
 
1062
+ if (count($sub->Domains) > 0) {
1063
+ foreach ($sub->Domains as &$domain) {
1064
+ if (!$domain->end) {
1065
+ if (isset($sub->activeDomainCount)) {
1066
+ $sub->activeDomainCount++;
1067
+ } else {
1068
+ $sub->activeDomainCount = 1;
1069
+ }
1070
+ }
1071
+ }
1072
+ }
1073
 
1074
+ $data['subscriptions'] = $result->payload;
1075
+ $data['libraries'] = $this->load_libraries();
1076
+
1077
+ return $data;
1078
+ } else if (isset($result->message) && strpos($result->message, 'Invalid Token') !== false) {
1079
+ $this->logout();
1080
+ update_option('sk_auto_activation_error', 'Please authorize SIDEKICK by logging in.');
1081
+ }
1082
 
1083
+ return null;
1084
+ }
 
 
 
 
 
 
 
1085
 
1086
+ function get_blog_by_id($id) {
1087
+ global $wpdb;
 
1088
 
1089
+ $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
1090
+ FROM $wpdb->blogs
1091
+ WHERE blog_id = '%d'
1092
+ "
1093
+ , $id));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1094
 
1095
+ return $blogs;
1096
+ }
1097
 
1098
+ function get_blogs() {
1099
+ global $wpdb;
 
1100
 
1101
+ if (false === ($blogs = get_transient('sk_blog_list'))) {
1102
+ $blogs = $wpdb->get_results($wpdb->prepare("SELECT *
1103
+ FROM $wpdb->blogs
1104
+ WHERE spam = '%d' AND deleted = '%d'
1105
+ "
1106
+ , 0, 0));
1107
+ set_transient('sk_blog_list', $blogs, 24 * HOUR_IN_SECONDS);
1108
+ }
1109
 
1110
+ return $blogs;
1111
+ }
 
 
 
 
1112
 
1113
+ function get_unchecked_blogs($blogs, $checked_blogs) {
1114
+ $return = array();
 
 
 
 
 
1115
 
1116
+ foreach ($blogs as $key => $blog) {
 
1117
 
1118
+ if (isset($checked_blogs['deactivated']) && is_array($checked_blogs['deactivated']) && isset($checked_blogs['deactivated'][$blog->blog_id])) {
1119
+ continue;
1120
+ }
1121
 
1122
+ if (isset($checked_blogs['unactivated']) && is_array($checked_blogs['unactivated']) && isset($checked_blogs['unactivated'][$blog->blog_id])) {
1123
+ continue;
1124
+ }
1125
 
1126
+ if (isset($checked_blogs['active']) && is_array($checked_blogs['active']) && isset($checked_blogs['active'][$blog->blog_id])) {
1127
+ continue;
1128
+ }
1129
 
1130
+ $return[$blog->blog_id] = $blog;
1131
+ }
 
 
 
 
 
1132
 
1133
+ return $return;
1134
+ }
 
 
 
1135
 
1136
+ function check_statuses() {
1137
+ $checked_blogs = get_option('sk_checked_blogs');
1138
+ $blogs = $this->get_blogs();
1139
+ $unchecked_blogs = $this->get_unchecked_blogs($blogs, $checked_blogs);
1140
+ $count = 0;
1141
 
1142
+ if (!isset($checked_blogs['unactivated'])) {
1143
+ $checked_blogs['unactivated'] = array();
1144
+ }
1145
 
1146
+ if (!isset($checked_blogs['active'])) {
1147
+ $checked_blogs['active'] = array();
1148
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1149
 
1150
+ if (!isset($checked_blogs['deactivated'])) {
1151
+ $checked_blogs['deactivated'] = array();
1152
+ }
1153
+
1154
+ foreach ($unchecked_blogs as $blog) {
1155
+
1156
+ // if ($count > $this->sites_per_page) {
1157
+ // break;
1158
+ // }
1159
+
1160
+ $blog_id = $blog->blog_id;
1161
+ $activation_id = null;
1162
+ $count++;
1163
+
1164
+ switch_to_blog($blog_id);
1165
+ if ($user = get_user_by('email', get_option('admin_email'))) {
1166
+ $blog->user_id = $user->ID;
1167
+ }
1168
+ $activation_id = get_site_option('sk_activation_id');
1169
+ restore_current_blog();
1170
+
1171
+ if ($activation_id) {
1172
+ $status = 'active';
1173
+ } elseif (isset($checked_blogs['deactivated']) && in_array($blog_id, $checked_blogs['deactivated'])) {
1174
+ $status = 'deactivated';
1175
+ } else {
1176
+ $status = 'unactivated';
1177
+ }
1178
+
1179
+ $checked_blogs[$status][$blog_id] = $blog;
1180
+
1181
+ }
1182
+
1183
+ update_option('sk_checked_blogs', $checked_blogs);
1184
+
1185
+ return $checked_blogs;
1186
+
1187
+ }
1188
+
1189
+ function load_sites_by_status() {
1190
+ global $wpdb;
1191
+
1192
+ $checked_blogs = $this->check_statuses();
1193
+ $status = sanitize_text_field($_POST['status']);
1194
+ $this->offet = sanitize_text_field($_POST['offset']);
1195
+
1196
+ if (isset($checked_blogs[$status]) && is_array($checked_blogs[$status])) {
1197
+
1198
+ $return['sites'] = array_slice($checked_blogs[$status], $this->offet, $this->sites_per_page);
1199
+ $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)));
1200
+ $return['counts']['active'] = count($checked_blogs['active']);
1201
+ $return['counts']['deactivated'] = count($checked_blogs['deactivated']);
1202
+ $return['counts']['unactivated'] = intval($return['counts']['all_blogs']) - intval($return['counts']['active']) - $return['counts']['deactivated'];
1203
+
1204
+
1205
+ $currentStatusCount = intval($return['counts'][$status]);
1206
+ $return['pages'] = ceil($currentStatusCount / $this->sites_per_page);
1207
+
1208
+ // $return['counts'][$status] = count($checked_blogs[$status]);
1209
+ } else {
1210
+ // $return['counts'][$status] = 0;
1211
+ $return[$status]['sites'] = array();
1212
+ }
1213
+
1214
+ die(json_encode($return));
1215
+ }
1216
+
1217
+ function logout() {
1218
+ delete_option('sk_account');
1219
+ delete_option('sk_password');
1220
+ delete_option('sk_subscription_id');
1221
+ delete_option('sk_selected_library');
1222
+ }
1223
+
1224
+ function load_libraries() {
1225
+ $result = $this->send_request('get', '/products');
1226
+ if ($result->success) {
1227
+ return $result->payload->products;
1228
+ }
1229
+
1230
+ return null;
1231
+ }
1232
+
1233
+ function schedule(){
1234
+ if ( ! wp_next_scheduled( array($this,'check_statuses') ) ) {
1235
+ wp_schedule_event( time(), 'hourly', array($this,'check_statuses'));
1236
+ wp_schedule_event( time(), 'hourly', array($this,'activate_batch'));
1237
+ }
1238
+
1239
+ }
1240
+
1241
+ function admin_page() {
1242
+ if (isset($_POST['sk_account'])) {
1243
+
1244
+ delete_option('sk_auto_activation_error');
1245
+
1246
+ if (isset($_POST['sk_password']) && $_POST['sk_password'] && isset($_POST['sk_account']) && $_POST['sk_account']) {
1247
+ $key = 'hash';
1248
+ $string = $_POST['sk_password'];
1249
+
1250
+ $encrypted_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
1251
+ $decrypted_password = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted_password), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
1252
+
1253
+ update_option('sk_account', $_POST['sk_account']);
1254
+ update_option('sk_password', $encrypted_password);
1255
+ $login_status = $this->login();
1256
+ delete_option('sk_auto_activation_error');
1257
+ }
1258
+
1259
+ if (isset($_POST['sk_auto_activations'])) {
1260
+ update_option('sk_auto_activations', true);
1261
+ } else {
1262
+ delete_option('sk_auto_activations');
1263
+ }
1264
+
1265
+ if (isset($_POST['sk_selected_library'])) {
1266
+ update_option('sk_selected_library', $_POST['sk_selected_library']);
1267
+ }
1268
+
1269
+ }
1270
+
1271
+ if (!$sk_token = get_transient('sk_token')) {
1272
+ $login_status = $this->login();
1273
+ }
1274
+
1275
+ $sk_subs = $this->load_subscriptions();
1276
+ $user_data = $this->load_user_data();
1277
+ $sk_auto_activations = get_option('sk_auto_activations');
1278
+ $sk_auto_activation_error = get_option('sk_auto_activation_error');
1279
+ $sk_subscription_id = get_option('sk_subscription_id');
1280
+ $sk_selected_library = get_option('sk_selected_library');
1281
+ $sk_hide_composer_taskbar_button = get_option('sk_hide_composer_taskbar_button');
1282
+ $sk_hide_config_taskbar_button = get_option('sk_hide_config_taskbar_button');
1283
+ $sk_hide_composer_upgrade_button = get_option('sk_hide_composer_upgrade_button');
1284
+ $is_ms_admin = true;
1285
+
1286
+ ?>
1287
  ?> <!-- ms_admin_page.php -->
1288
 
1289
  <script type="text/javascript">
1294
  var sk_ms_admin = true;
1295
 
1296
  jQuery(document).ready(function($) {
1297
+ if (typeof mixpanel !== 'undefined') {
1298
+ mixpanel.track('Network Settings Page Visit - Plugin');
1299
+ };
1300
  });
1301
 
1302
  </script>
1362
  <input class='regular-text' type='password' name='sk_password' placeholder='********'></input>
1363
  </td>
1364
  </tr>
1365
+
1366
+ <tr valign="top" class='walkthrough_library'>
1367
+ <th scope="row" valign="top">Library to Distribute</th>
1368
  <td>
1369
+ <select name='sk_selected_library'>
1370
+ <?php if (isset($sk_subs['libraries']) && count($sk_subs['libraries']) > 0): ?>
1371
+ <?php foreach ($sk_subs['libraries'] as $key => $library): ?>
1372
+ <option <?php echo ($sk_selected_library == $library->id) ? 'SELECTED' : '' ?> value='<?php echo $library->id ?>'><?php echo $library->name ?></option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1373
  <?php endforeach ?>
 
 
 
 
 
1374
  <?php endif ?>
1375
+ <option <?php echo ($sk_selected_library == -1) ? 'SELECTED' : '' ?> value='-1'>WordPress Basics Only</option>
1376
  </select>
1377
  </td>
1378
  </tr>
 
1379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1380
 
1381
  <tr valign="top">
1382
  <th scope="row" valign="top">Enable Auto-Activations</th>
1383
  <td>
1384
+ <input class='checkbox' type='checkbox' name='sk_auto_activations' <?php echo ($sk_auto_activations) ? 'CHECKED' : '' ?>>
 
 
 
 
1385
  </td>
1386
  </tr>
1387
+
1388
  <?php if (isset($selected_sub) && !isset($no_product)): ?>
1389
  <tr>
1390
  <th scope="row" valign="top">Active Domains</th>
1429
 
1430
  <div class="sk_box sites">
1431
  <div class="well">
1432
+ <h3>Sidekick Network Activations</h3>
1433
+
1434
+ <div class='stats'>
1435
+ <div class='active' onclick='load_sites_by_status("active",this)'>
1436
+ <i>></i>
1437
+ <h3>0</h3>
1438
+ <span>Active</span>
1439
+ </div>
1440
+ <div class='unactivated' onclick='load_sites_by_status("unactivated",this)'>
1441
+ <i>></i>
1442
+ <h3>0</h3>
1443
+ <span>Unactivated</span>
1444
+ </div>
1445
+ <div class='deactivated' onclick='load_sites_by_status("deactivated",this)'>
1446
+ <i>></i>
1447
+ <h3>0</h3>
1448
+ <span>Deactivated</span>
1449
+ </div>
1450
+ </div>
 
 
1451
 
1452
+ <div class="status">
 
 
1453
 
1454
+ </div>
1455
 
1456
+ <h2><span>Loading...</span><button class='activate_all'>Activate All<div class="spinner"></div></button></h2>
1457
+
1458
+ <div class='action'>
1459
+ <div class="pagination">
1460
+ <button class='prev'>Prev</button>
1461
+ <span>Showing <span class="start">1</span>/<span class='end'>1</span></span>
1462
+ <button class='next'>Next</button>
1463
+ </div>
1464
+ <div class="filter">
1465
+ <!-- <input type='text' placeholder='Find'> -->
1466
+ </div>
1467
+ </div>
1468
 
1469
  <div class="single_activation_error red"></div>
1470
 
1471
+ <div class="site_list">
1472
+ Loading...
1473
+ </div>
1474
 
1475
  </div>
1476
  </div>
1504
  </div>
1505
  </div>
1506
 
1507
+ <div class="sk_box configure">
1508
+ <div class="well">
1509
+ <h3>Configure - Other</h3>
1510
+
1511
+ <form method="post">
1512
+ <?php settings_fields('sk_license'); ?>
1513
+ <table class="form-table long_label">
1514
+ <tbody>
1515
+
1516
+ <tr valign="top">
1517
+ <th scope="row" valign="top">Hide Composer Button in Taskbar</th>
1518
+ <td>
1519
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_taskbar_button' <?php echo (isset($sk_hide_composer_taskbar_button) && $sk_hide_composer_taskbar_button) ? 'CHECKED' : '' ?>>
1520
+ </td>
1521
+ </tr>
1522
+ <tr valign="top">
1523
+ <th scope="row" valign="top">Hide Config Button in Taskbar</th>
1524
+ <td>
1525
+ <input class='checkbox' type='checkbox' name='sk_hide_config_taskbar_button' <?php echo (isset($sk_hide_config_taskbar_button) && $sk_hide_config_taskbar_button) ? 'CHECKED' : '' ?>>
1526
+ </td>
1527
+ </tr>
1528
+ <tr valign="top">
1529
+ <th scope="row" valign="top">Hide Composer Upgrade Button in Drawer</th>
1530
+ <td>
1531
+ <input class='checkbox' type='checkbox' name='sk_hide_composer_upgrade_button' <?php echo (isset($sk_hide_composer_upgrade_button) && $sk_hide_composer_upgrade_button) ? 'CHECKED' : '' ?>>
1532
+ </td>
1533
+ </tr>
1534
+ <tr valign="top">
1535
+ <th scope="row" valign="top"></th>
1536
+ <td>
1537
+ <input class='button button-primary' type='submit' value='Save'/>
1538
+ </td>
1539
+ </tr>
1540
+
1541
+ <input type='hidden' name='is_ms_admin' value='<?php echo (isset($is_ms_admin)) ? $is_ms_admin : false ?>'/>
1542
+ <input type='hidden' name='sk_setting_other' value='true'/>
1543
+
1544
+ <?php wp_nonce_field( 'update_sk_settings' ); ?>
1545
+
1546
+ </tbody>
1547
+ </table>
1548
+ </form>
1549
+ </div>
1550
+ </div>
1551
+
1552
  <div class="sk_box configure">
1553
  <div class="well">
1554
  <form method='post'>
1579
 
1580
  <?php
1581
 
1582
+ }
1583
+ }
1584
  }
1585
 
1586
  // //licensing.php
1587
+ $sidekickMassActivator = new sidekickMassActivator;
1588
+
1589
+ add_action('network_admin_menu', array($sidekickMassActivator,'setup_menu'));
1590
+ add_action('wp_ajax_sk_activate_single', array($sidekickMassActivator,'activate_single'));
1591
+ add_action('wp_ajax_sk_activate_batch', array($sidekickMassActivator,'activate_batch'));
1592
+ add_action('wp_ajax_sk_load_sites_by_status', array($sidekickMassActivator,'load_sites_by_status'));
1593
+
1594
+ $sk_auto_activations = get_option( 'sk_auto_activations');
1595
+ if ($sk_auto_activations) {
1596
+ add_action('wpmu_new_blog',array($sidekickMassActivator,'activate'),10,6);
1597
+ add_action('sk_hourly_event',array($sidekickMassActivator,'schedule'),10,6);
1598
+ }
1599
+ }
1600
  }
1601
 
1602
 
1605
  if (!$sidekick_active && !class_exists('sk_config_data')) {
1606
 
1607
  class sk_config_data{
1608
+
1609
+ var $cache_time = 43200; // 12 Hours
1610
+
1611
  function get_domain(){
1612
  $site_url = get_site_url();
1613
  if(substr($site_url, -1) == '/') {
1617
  return $site_url;
1618
  }
1619
 
1620
+ // Return list of post types registered in WordPress
1621
+ // Transients cleared on post type update, create, delete
1622
+
1623
  function get_post_types(){
1624
  global $wpdb;
 
 
 
1625
 
1626
+ if ( false === ( $result = get_transient( 'sk_get_post_types' ) ) ) {
1627
+
1628
+ $query = "SELECT post_type, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type";
1629
+ $counts = $wpdb->get_results($query);
1630
+ $result = '';
1631
+
1632
+ foreach ($counts as $key => $type) {
1633
+ $type->post_type = str_replace('-', '_', $type->post_type);
1634
+ $result .= "\n post_type_{$type->post_type} : $type->count,";
1635
+ }
1636
+ set_transient( 'sk_get_post_types', $result, $this->cache_time );
1637
  }
1638
+
1639
+ return $result;
1640
  }
1641
 
1642
  function get_file_editor_enabled(){
1653
  }
1654
 
1655
  function get_themes(){
1656
+ if ( false === ( $result = get_transient( 'sk_get_themes' ) ) ) {
1657
+ $result = wp_get_themes( array( 'allowed' => true ) );
1658
+ set_transient( 'sk_get_themes', $result, $this->cache_time );
1659
+ }
1660
+
1661
+ return count($result);
1662
  }
1663
 
1664
  function get_post_types_and_statuses(){
1665
  global $wpdb;
 
 
 
1666
 
1667
+ // Can't find a good method to clear cache for newly registered post types that fires once
1668
+ // if ( false === ( $result = get_transient( 'sk_get_post_types_and_statuses' ) ) ) {
1669
+ $query = "SELECT post_type, post_status, count(distinct ID) as count from {$wpdb->prefix}posts group by post_type, post_status";
1670
+ $counts = $wpdb->get_results($query);
1671
+ $result = '';
1672
 
1673
+ foreach ($counts as $key => $type) {
1674
+ $type->post_type = str_replace('-', '_', $type->post_type);
1675
+ $type->post_status = str_replace('-', '_', $type->post_status);
1676
+
1677
+ $result .= "\n post_type_{$type->post_type}_{$type->post_status} : $type->count,";
1678
+ }
1679
+ set_transient( 'sk_get_post_types_and_statuses', $result, $this->cache_time );
1680
+ // }
1681
+
1682
+ return $result;
1683
  }
1684
 
1685
  function get_taxonomies(){
1686
  global $wpdb;
 
 
 
1687
 
1688
+ // if ( false === ( $result = get_transient( 'sk_get_taxonomies' ) ) ) {
1689
+ $query = "SELECT count(distinct term_taxonomy_id) as count, taxonomy from {$wpdb->prefix}term_taxonomy group by taxonomy";
1690
+ $counts = $wpdb->get_results($query);
1691
+ $result = '';
1692
+
1693
+ foreach ($counts as $key => $taxonomy) {
1694
+ $taxonomy->taxonomy = str_replace('-', '_', $taxonomy->taxonomy);
1695
+ $result .= "\n taxonomy_{$taxonomy->taxonomy} : $taxonomy->count,";
1696
+ }
1697
+ set_transient( 'sk_get_taxonomies', $result, $this->cache_time );
1698
+ // }
1699
+
1700
+ return $result;
1701
  }
1702
 
1703
  function get_comments(){
1704
  global $wpdb;
1705
+
1706
+ if ( false === ( $result = get_transient( 'sk_get_comments' ) ) ) {
1707
+ $query = "SELECT count(distinct comment_ID) as count from {$wpdb->prefix}comments";
1708
+ $counts = $wpdb->get_var($query);
1709
+ if (!$counts) $counts = 0;
1710
+ $result = "\n comment_count : $counts,";
1711
+ set_transient( 'sk_get_comments', $result, $this->cache_time );
1712
+ }
1713
+
1714
+ return $result;
1715
  }
1716
 
1717
  function get_post_statuses(){
1718
  global $wpdb;
 
 
 
1719
 
1720
+ if ( false === ( $result = get_transient( 'sk_post_statuses' ) ) ) {
1721
+ $query = "SELECT post_status, count(ID) as count from {$wpdb->prefix}posts group by post_status";
1722
+ $counts = $wpdb->get_results($query);
1723
+ $result = '';
1724
+
1725
+ foreach ($counts as $key => $type) {
1726
+ $type->post_status = str_replace('-', '_', $type->post_status);
1727
+ $result .= "\n post_status_{$type->post_status} : $type->count,";
1728
+ }
1729
+ set_transient( 'sk_post_statuses', $result, $this->cache_time );
1730
  }
1731
+
1732
+ return $result;
1733
  }
1734
 
1735
  function get_user_data(){
1736
  global $current_user;
1737
 
1738
+ if ( false === ( $result = get_transient( 'sk_get_user_data' ) ) ) {
1739
+ $data = get_userdata($current_user->ID);
1740
+ $result = "\n user_id : $current_user->ID,";
1741
 
1742
+ foreach ($data->allcaps as $cap => $val) {
1743
+ $cap = sanitize_title($cap);
1744
+ $cap = str_replace('-', '_', $cap);
1745
+ if (!$val) $val = 0;
1746
+ $result .= "\n cap_{$cap} : $val,";
1747
+ }
1748
+ set_transient( 'sk_get_user_data', $result, $this->cache_time );
1749
  }
1750
+
1751
+ return $result;
1752
  }
1753
 
1754
  function get_framework(){
1807
 
1808
  function get_plugins(){
1809
 
1810
+ if ( false === ( $result = get_transient( 'sk_get_plugins' ) ) ) {
1811
+ $active_plugins = wp_get_active_and_valid_plugins();
1812
+ $mu_plugins = get_mu_plugins();
1813
+ $result = array();
1814
+
1815
+ if (is_array($active_plugins)) {
1816
+ foreach ($active_plugins as $plugins_key => $plugin) {
1817
+ $data = get_plugin_data( $plugin, false, false );
1818
+ $slug = explode('/',plugin_basename($plugin));
1819
+ $slug = str_replace('.php', '', $slug[1]);
1820
+ $result[$slug] = $data['Version'];
1821
+ }
1822
  }
 
1823
 
1824
+ if (is_array($mu_plugins)) {
1825
+ foreach ($mu_plugins as $plugins_key => $plugin) {
1826
+ $slug = str_replace('.php', '', $plugins_key);
1827
+ $result[$slug] = '1.0.0';
1828
+ }
1829
  }
1830
+ set_transient( 'sk_get_plugins', $result, $this->cache_time );
1831
  }
1832
+
1833
+ return $result;
1834
  }
1835
 
1836
  function get_user_role(){
1854
  }
1855
  return $user_role;
1856
  }
1857
+
1858
  }
1859
  }
1860