Skip to content

Commit 1a85348

Browse files
committed
supergroups and changes to alerts / notifications
1 parent 022d407 commit 1a85348

File tree

6 files changed

+495
-90
lines changed

6 files changed

+495
-90
lines changed

index.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
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.36
6+
Version: 0.37
77
*/
88
define( 'MB_PROD_NAME', 'Accelerator by Membucket.io' );
99
define( 'MEMBUCKET', true );
1010

1111
global $MB_version;
12-
$MB_version = '0.36';
12+
$MB_version = '0.37';
1313

1414
// Handle "Activate" or plugin update
1515
require( 'mb-install-wp.php' );
1616

1717
function MB_menu() {
18-
$product_name = __( "Membucket", 'textdomain' );
18+
$product_name = __( 'Membucket', 'textdomain' );
1919

2020
$menu_token = 'accel-membucket';
21+
$menu_location = 'manage_options';
2122
add_menu_page(
2223
$product_name,
2324
$product_name,
@@ -31,7 +32,7 @@ function MB_menu() {
3132
$menu_token,
3233
$product_name,
3334
'Settings',
34-
'manage_options',
35+
$menu_location,
3536
'accel-membucket',
3637
'MB_settings_page'
3738
);
@@ -40,7 +41,7 @@ function MB_menu() {
4041
$menu_token,
4142
$product_name,
4243
'Analytics',
43-
'manage_options',
44+
$menu_location,
4445
'accel-analytics',
4546
'MB_analytics_page'
4647
);
@@ -49,7 +50,7 @@ function MB_menu() {
4950
$menu_token,
5051
$product_name,
5152
'Diagnostics',
52-
'manage_options',
53+
$menu_location,
5354
'accel-diagnostics',
5455
'mb_diagnostics_page'
5556
);

mb-common.php

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

5-
// Some handy constants
6-
define( 'MB_FILENAME_ACCESSKEY', '.membucket' );
7-
define( 'MB_FILENAME_ASSOCIATE', '.membucketwells' );
8-
9-
require( 'Well.class.php' );
5+
require_once( 'mb-stub.php' );
106

117
$_GLOBALS[ 'mb_checks' ] = [
128
0 => file_exists( '/usr/local/cpanel/version' ),
139
1 => file_exists( '/usr/bin/membucket' ) ||
1410
file_exists( '/usr/bin/membucketd' ),
15-
2 => MB_Get_User_Key() != ""
11+
2 => MB_Get_User_Key() != '',
12+
3 => file_exists( realpath( get_home_path() ) . '/wp-content/object-cache.php' ),
13+
4 => class_exists( 'Memcache' )
1614
];
1715

1816
function CallAPI( $method = 'GET', $path = '', $data = false ) {
@@ -53,73 +51,8 @@ function _Get_User() {
5351
return $user[ 'name' ];
5452
}
5553

56-
/**
57-
* Searches for $name, traveling up from $path
58-
*
59-
* Searches the directory tree starting at $path and working upwards until
60-
* we hit one of the restricted directories, for a file named $name. This
61-
* search is case sensitive on all platforms.
62-
*
63-
* @param
64-
*/
65-
function _RecursiveUpSearch($path, $name) {
66-
for ( $i = 0; 10 > $i; $i++ ) {
67-
if ( '/' === $path || // system root
68-
'/home' === $path || // system home directory
69-
'/home2' === $path || // cpanel additional home directory
70-
'/home3' === $path || // cpanel additional home directory
71-
'/opt' === $path || // system directory
72-
'/usr' === $path || // system directory
73-
'/var' === $path) { // system directory
74-
return '';
75-
}
76-
77-
$file = "{$path}/{$name}";
78-
if ( file_exists( $file ) ) {
79-
return $file;
80-
}
81-
82-
// Traverse up one directory
83-
$path = realpath( "{$path}/../" );
84-
}
85-
86-
return '';
87-
}
88-
89-
/**
90-
* Reads well associations from {@link MB_FILENAME_ASSOCIATE}
91-
*
92-
* Well Associations are stored above the web directory. On cPanel we can
93-
* automatically detect this fairly easily, as all sites are served from
94-
* within a user's home directory. This approach might need to be adjusted
95-
* when targeting another platform or control panel.
96-
*
97-
* @return array keyed as cache groups, values as Well hashes
98-
*/
99-
// TODO: Check when supporting Operating Systems outside of CentOS
100-
function MB_Get_Associations() {
101-
$path = _RecursiveUpSearch( realpath( get_home_path() ), MB_FILENAME_ASSOCIATE );
102-
103-
if ( ! file_exists( $path ) ||
104-
4096 < filesize( $path ) ) {
105-
return null;
106-
}
107-
108-
$s = file_get_contents( $path );
109-
$s = json_decode( $s );
110-
$groups = [
111-
'static' => $s->static,
112-
'dynamic' => $s->dynamic,
113-
'author' => $s->author,
114-
'session' => $s->session,
115-
'default' => $s->default
116-
];
117-
118-
return $groups;
119-
}
120-
12154
function MB_Set_Associations( $well, $roles ) {
122-
$path = _RecursiveUpSearch( realpath( get_home_path() ), MB_FILENAME_ASSOCIATE );
55+
$path = _RecursiveUpSearch( realpath( __DIR__ ), MB_FILENAME_ASSOCIATE );
12356

12457
if ( '' === $path ) {
12558
$path = realpath( get_home_path() ) . '/' . MB_FILENAME_ASSOCIATE;

mb-install-wp.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ function MB_install() {
77

88
global $MB_version;
99
add_option( 'mb_version', $MB_version );
10+
11+
$contents = file_get_contents( realpath( __DIR__ ) . '/object-cache.php' );
12+
$path = realpath( get_home_path() ) . '/wp-content/object-cache.php';
13+
if ( file_exists( $path ) ) {
14+
$file = file_get_contents( $path );
15+
if ( $contents === $file ) {
16+
return;
17+
}
18+
}
19+
20+
if ( false === file_put_contents( $path, $contents ) ) {
21+
die( "Installation Failed. Could not write {$path}, and it was not up-to-date." );
22+
}
1023
}
1124

1225
register_activation_hook( __FILE__, 'MB_install' );
26+
27+
function MB_uninstall() {
28+
$contents = file_get_contents( realpath( __DIR__ ) . '/object-cache.php' );
29+
$path = realpath( get_home_path() ) . '/wp-content/object-cache.php';
30+
if ( ! file_exists( $path ) ) {
31+
return;
32+
}
33+
$file = file_get_contents( $path );
34+
if ( $contents === $file ) {
35+
unlink( $path );
36+
}
37+
}
38+
39+
register_deactivation_hook( __FILE__, 'MB_uninstall' );

mb-stub.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
// Some handy constants
3+
define( 'MB_FILENAME_ACCESSKEY', '.membucket' );
4+
define( 'MB_FILENAME_ASSOCIATE', '.membucketwells' );
5+
6+
require_once( 'Well.class.php' );
7+
8+
/**
9+
* Searches for $name, traveling up from $path
10+
*
11+
* Searches the directory tree starting at $path and working upwards until
12+
* we hit one of the restricted directories, for a file named $name. This
13+
* search is case sensitive on all platforms.
14+
*
15+
* @param string $path Directory to start traversal from
16+
* @param string $name Filename to look for (case sensitive)
17+
*
18+
* @return string|'' Absolute Path and Filename to requested file
19+
*/
20+
function _RecursiveUpSearch($path, $name) {
21+
for ( $i = 0; 10 > $i; $i++ ) {
22+
if ( '/' === $path || // system root
23+
'/home' === $path || // system home directory
24+
'/home2' === $path || // cpanel additional home directory
25+
'/home3' === $path || // cpanel additional home directory
26+
'/opt' === $path || // system directory
27+
'/usr' === $path || // system directory
28+
'/var' === $path) { // system directory
29+
return '';
30+
}
31+
32+
$file = "{$path}/{$name}";
33+
if ( file_exists( $file ) ) {
34+
return $file;
35+
}
36+
37+
// Traverse up one directory
38+
$path = realpath( "{$path}/../" );
39+
}
40+
41+
return '';
42+
}
43+
44+
/**
45+
* Reads well associations from {@link MB_FILENAME_ASSOCIATE}
46+
*
47+
* Well Associations are stored above the web directory. On cPanel we can
48+
* automatically detect this fairly easily, as all sites are served from
49+
* within a user's home directory. This approach might need to be adjusted
50+
* when targeting another platform or control panel.
51+
*
52+
* @return array keyed as cache groups, values as Well hashes
53+
*/
54+
// TODO: Check when supporting Operating Systems outside of CentOS
55+
function MB_Get_Associations() {
56+
$path = _RecursiveUpSearch( realpath( __DIR__ ), MB_FILENAME_ASSOCIATE );
57+
58+
if ( ! file_exists( $path ) ||
59+
4096 < filesize( $path ) ) {
60+
return null;
61+
}
62+
63+
$s = file_get_contents( $path );
64+
$s = json_decode( $s );
65+
$groups = [
66+
'static' => $s->static,
67+
'dynamic' => $s->dynamic,
68+
'author' => $s->author,
69+
'session' => $s->session,
70+
'default' => $s->default
71+
];
72+
73+
return $groups;
74+
}

0 commit comments

Comments
 (0)