Skip to content

Commit 022d407

Browse files
committed
fix select all and alert messages
1 parent bd86f83 commit 022d407

File tree

5 files changed

+66
-42
lines changed

5 files changed

+66
-42
lines changed

index.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
Plugin Name: Accelerator by Membucket.io
44
Description: A plugin that improves the performance of WordPress
55
Author: Membucket.io, LLC
6-
Version: 0.35
6+
Version: 0.36
77
*/
88
define( 'MB_PROD_NAME', 'Accelerator by Membucket.io' );
99
define( 'MEMBUCKET', true );
1010

1111
global $MB_version;
12-
$MB_version = '0.35';
13-
14-
// We need access to Membucket's API
15-
require( 'mb-common.php' );
12+
$MB_version = '0.36';
1613

1714
// Handle "Activate" or plugin update
1815
require( 'mb-install-wp.php' );
@@ -74,5 +71,6 @@ function MB_diagnostics_page() {
7471
}
7572

7673
function MB_settings_page() {
74+
require( 'mb-common.php' ); // We need access to Membucket's API
7775
require( 'page-settings.php' );
7876
}

mb-common.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
require( 'Well.class.php' );
1010

11+
$_GLOBALS[ 'mb_checks' ] = [
12+
0 => file_exists( '/usr/local/cpanel/version' ),
13+
1 => file_exists( '/usr/bin/membucket' ) ||
14+
file_exists( '/usr/bin/membucketd' ),
15+
2 => MB_Get_User_Key() != ""
16+
];
17+
1118
function CallAPI( $method = 'GET', $path = '', $data = false ) {
1219
$curl = curl_init();
1320
curl_setopt( $curl, CURLOPT_URL, "http://127.0.0.1:9999/wells{$path}" );
@@ -91,9 +98,7 @@ function _RecursiveUpSearch($path, $name) {
9198
*/
9299
// TODO: Check when supporting Operating Systems outside of CentOS
93100
function MB_Get_Associations() {
94-
// Get script directory without trailing slash
95-
$path = realpath( get_home_path() );
96-
$path = _RecursiveUpSearch( $path, MB_FILENAME_ASSOCIATE );
101+
$path = _RecursiveUpSearch( realpath( get_home_path() ), MB_FILENAME_ASSOCIATE );
97102

98103
if ( ! file_exists( $path ) ||
99104
4096 < filesize( $path ) ) {
@@ -114,9 +119,7 @@ function MB_Get_Associations() {
114119
}
115120

116121
function MB_Set_Associations( $well, $roles ) {
117-
// Get script directory without trailing slash
118-
$path = realpath( get_home_path() );
119-
$path = _RecursiveUpSearch( $path, MB_FILENAME_ASSOCIATE );
122+
$path = _RecursiveUpSearch( realpath( get_home_path() ), MB_FILENAME_ASSOCIATE );
120123

121124
if ( '' === $path ) {
122125
$path = realpath( get_home_path() ) . '/' . MB_FILENAME_ASSOCIATE;
@@ -140,19 +143,7 @@ function MB_Set_Associations( $well, $roles ) {
140143
* @return string access key for this user
141144
*/
142145
function MB_Get_User_Key() {
143-
// Get script directory without trailing slash
144-
$path = realpath( get_home_path() );
145-
146-
// On CentOS under default (supported) configuration, the home Directory
147-
// contains the username, therefore we need the username.
148-
$user = _Get_User();
149-
150-
// Currently the username must be in the path
151-
if ( -1 === strpos( $path, $user ) )
152-
return '';
153-
154-
// Try at most 10 directories
155-
$path = _RecursiveUpSearch( $path, MB_FILENAME_ACCESSKEY );
146+
$path = _RecursiveUpSearch( realpath( get_home_path() ), MB_FILENAME_ACCESSKEY );
156147
if ( $path === '' ) {
157148
return '';
158149
}

page-settings.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
// Prevent direct script access
33
if ( ! defined( 'MEMBUCKET' ) ) exit;
44

5-
// Checks
6-
$checks = [
7-
0 => file_exists( '/usr/local/cpanel/version' ),
8-
1 => file_exists( '/usr/bin/membucket' ) ||
9-
file_exists( '/usr/bin/membucketd' ),
10-
2 => MB_Get_User_Key() != ""
11-
];
12-
135
// If we're changing well associations
146
if ( ! empty( $_POST ) ) {
157
MB_Set_Associations( $_POST[ 'well' ], explode( ',', $_POST[ 'roles' ] ) );
@@ -31,30 +23,32 @@
3123

3224
<h2><?php echo MB_PROD_NAME; ?> Settings</h2>
3325

34-
<?php if ( ! $checks[ 0 ] ): ?>
26+
<?php if ( ! $_GLOBALS[ 'mb_checks' ][ 0 ] ): ?><p>
3527
Your hosting control panel is not yet supported! If you are using cPanel/WHM
3628
and are seeing this message, ask your hosting provider if there is a jail in
3729
place. If there is a jail, you can <a href="?dimiss=0">ignore and dismiss
3830
this message.</a>
39-
<?php endif; ?>
31+
</p><?php endif; ?>
4032

41-
<?php if ( ! $checks[ 1 ] ): ?>
33+
<?php if ( ! $_GLOBALS[ 'mb_checks' ][ 1 ] ): ?><p>
4234
Membucket was not found on your system! Your hosting provider does not
4335
support Membucket, or has not made it available to your user.
44-
<?php elseif ( ! $checks[ 2 ] ): ?>
36+
</p><?php elseif ( ! $_GLOBALS[ 'mb_checks' ][ 2 ] ): ?><p>
4537
Your account does not have an access key for use with Membucket. If you
4638
have access to SSH, please run the command: `membucket generate-key`.
4739
Otherwise, ask your hosting provider to run this command as your user.
48-
<?php endif; ?>
40+
</p><?php endif; ?>
4941

42+
<?php if ( $_GLOBALS[ 'mb_checks' ][ 1 ] &&
43+
$_GLOBALS[ 'mb_checks' ][ 2 ] ): ?>
5044
<p>Here you can assign roles to wells and customize how membucket caches your site.</p>
5145

5246
<div>
5347
<h3>Wells</h3>
5448
<p><strong>Step 1)</strong> Select a Well</p>
5549
<?php
5650
foreach ( $wells as $well ) {
57-
$groups = "Unassigned";
51+
$groups = 'Unassigned';
5852
if ( array_key_exists( $well->ID, $roles ) ) {
5953
$groups = ucfirst( $roles[ $well->ID ] );
6054
}
@@ -79,7 +73,9 @@
7973
<div>
8074
<h3>Roles</h3>
8175
<p><strong>Step 2)</strong> Select Roles to assign to <span id="wellName">-</span></p>
82-
<p>To accelerate everything, make sure every role is assigned to a Well. If you are unsure what to assign <button id="mbSelectAll">click here</button> to select all.</p>
76+
<p>To accelerate everything, make sure every role is assigned to a Well. If
77+
you are unsure what to assign, <button id="mb-select-all"
78+
>click here</button> to select all.</p>
8379

8480
<div class="mb-role" id="static">
8581
<h4>Static</h4>
@@ -115,3 +111,4 @@
115111

116112
<?php wp_enqueue_script( 'jquery' ); ?>
117113
<script src="<?php echo plugins_url( 'script.js', __FILE__ ); ?>"></script>
114+
<?php endif; ?>

script.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ transformBool = (boolish) ->
2121
selected = true if boolish == "true"
2222
return !selected
2323

24+
jQuery '#mb-select-all'
25+
.on 'click', ->
26+
selectedRoles = []
27+
jQuery '.mb-role'
28+
.each (_) ->
29+
ele = jQuery this
30+
selected = ele.attr 'data-selected'
31+
32+
if !selected
33+
ele.addClass 'selected'
34+
ele.attr 'data-selected', true
35+
selectedRoles.push ele.attr 'id'
36+
return
37+
38+
checkFormValidity()
39+
return
40+
2441
domSubmit.on 'click', ->
2542
return false unless checkFormValidity()
2643

@@ -49,6 +66,11 @@ jQuery '.mb-role'
4966
else
5067
i = selectedRoles.indexOf id
5168
selectedRoles.splice i, 1 if i != -1
69+
70+
checkFormValidity()
71+
return
72+
73+
return
5274

5375
jQuery '.mb-well'
5476
.each (_) ->

script.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ transformBool = function(boolish) {
3232
return !selected;
3333
};
3434

35+
jQuery('#mb-select-all').on('click', function() {
36+
selectedRoles = [];
37+
jQuery('.mb-role').each(function(_) {
38+
var ele, selected;
39+
ele = jQuery(this);
40+
selected = ele.attr('data-selected');
41+
if (!selected) {
42+
ele.addClass('selected');
43+
ele.attr('data-selected', true);
44+
selectedRoles.push(ele.attr('id'));
45+
}
46+
});
47+
checkFormValidity();
48+
});
49+
3550
domSubmit.on('click', function() {
3651
if (!checkFormValidity()) {
3752
return false;
@@ -42,7 +57,7 @@ domSubmit.on('click', function() {
4257
});
4358

4459
jQuery('.mb-role').each(function(_) {
45-
return jQuery(this).on('click', function() {
60+
jQuery(this).on('click', function() {
4661
var ele, i, id, selected;
4762
ele = jQuery(this);
4863
selected = transformBool(ele.attr('data-selected'));
@@ -54,13 +69,14 @@ jQuery('.mb-role').each(function(_) {
5469
ele.attr('data-selected', selected);
5570
id = ele.attr('id');
5671
if (selected) {
57-
return selectedRoles.push(id);
72+
selectedRoles.push(id);
5873
} else {
5974
i = selectedRoles.indexOf(id);
6075
if (i !== -1) {
61-
return selectedRoles.splice(i, 1);
76+
selectedRoles.splice(i, 1);
6277
}
6378
}
79+
checkFormValidity();
6480
});
6581
});
6682

0 commit comments

Comments
 (0)