-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsysinfo.php
248 lines (209 loc) · 7.55 KB
/
sysinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/**
* Useful system information about your WordPress install.
*
* @package Sysinfor
* @author Leo Gopal
* @copyright 2020 Leo Gopal
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: SysInfo
* Plugin URI: http://wordpress.org/extend/plugins/sysinfo/
* Description: Useful system information about your WordPress install.
* Version: 1.2.0
* Requires at least: 4.2
* Requires PHP: 5.6
* Author: Leo Gopal
* Author URI: https://leogopal.com
* License: GPL2
* Text Domain: sysinfo
*
* Copyright 2020 Leo Gopal, Seramade
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class SysInfo {
function __construct() {
// Global constants first
define( 'SYSINFO_VERSION_KEY', 'sysinfo_version' );
define( 'SYSINFO_VERSION_NUM', '1.1.0' );
define( 'SYSINFO_PLUGIN_NAME', trim( dirname( plugin_basename( __FILE__ ) ), '/' ) );
define( 'SYSINFO_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . SYSINFO_PLUGIN_NAME );
define( 'SYSINFO_PLUGIN_URL', WP_PLUGIN_URL . '/' . SYSINFO_PLUGIN_NAME );
// Activation/deactivation hooks
register_activation_hook( __FILE__, array( $this, 'do_activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'do_deactivation' ) );
// Any other hooks we need
add_action( 'init', array( $this, 'load_textdomain' ) );
add_action( 'admin_menu', array( $this, 'add_tools_page' ) );
add_filter( 'plugin_action_links', array( $this, 'add_action_links' ), 10, 2 );
}
function activate() {
update_option( SYSINFO_VERSION_KEY, SYSINFO_VERSION_NUM );
}
function deactivate() {
delete_option( SYSINFO_VERSION_KEY );
}
function do_activation( $network_wide ) {
if ( $network_wide ) {
$this->call_function_for_each_site( array( $this, 'activate' ) );
} else {
$this->activate();
}
}
function do_deactivation( $network_wide ) {
if ( $network_wide ) {
$this->call_function_for_each_site( array( $this, 'deactivate' ) );
} else {
$this->deactivate();
}
}
function call_function_for_each_site( $function ) {
global $wpdb;
// Hold this so we can switch back to it
$current_blog = $wpdb->blogid;
// Get all the blogs/sites in the network and invoke the function for each one
$blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs" ) );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
call_user_func( $function );
}
// Now switch back to the root blog
switch_to_blog( $current_blog );
}
function load_textdomain() {
load_plugin_textdomain( 'sysinfo', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
function add_tools_page() {
$admin_pages = array();
$parent_slug = 'tools.php';
$page_title = __( 'SysInfo', 'sysinfo' );
$sub_menu_title = __( 'SysInfo', 'sysinfo' );
$capability = 'manage_options';
$menu_slug = 'sysinfo';
$function = array( $this, 'add_sysinfo_page' );
$admin_pages[] = add_submenu_page( $parent_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function );
foreach ( $admin_pages as $admin_page ) {
add_action( "admin_print_styles-{$admin_page}", array( $this, 'add_admin_styles' ) );
}
}
function add_sysinfo_page() {
require_once 'views/admin.php';
}
function add_admin_styles() {
wp_enqueue_style( 'sysinfo-css', SYSINFO_PLUGIN_URL . '/css/sysinfo.css' );
}
function add_action_links( $links, $file ) {
static $this_plugin;
if ( ! $this_plugin ) {
$this_plugin = plugin_basename( __FILE__ );
}
if ( $file == $this_plugin ) {
$packs_link = '<a href="' . admin_url( 'tools.php?page=sysinfo' ) . '">' . __( 'View', 'sysinfo' ) . '</a>';
array_unshift( $links, $packs_link );
}
return $links;
}
function get_browser() {
// http://www.php.net/manual/en/function.get-browser.php#101125.
// Cleaned up a bit, but overall it's the same.
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$browser_name = 'Unknown';
$platform = 'Unknown';
$version = "";
// First get the platform
if ( preg_match( '/linux/i', $user_agent ) ) {
$platform = 'Linux';
} elseif ( preg_match( '/macintosh|mac os x/i', $user_agent ) ) {
$platform = 'Mac';
} elseif ( preg_match( '/windows|win32/i', $user_agent ) ) {
$platform = 'Windows';
}
// Next get the name of the user agent yes seperately and for good reason
if ( preg_match( '/MSIE/i', $user_agent ) && ! preg_match( '/Opera/i', $user_agent ) ) {
$browser_name = 'Internet Explorer';
$browser_name_short = "MSIE";
} elseif ( preg_match( '/Firefox/i', $user_agent ) ) {
$browser_name = 'Mozilla Firefox';
$browser_name_short = "Firefox";
} elseif ( preg_match( '/Chrome/i', $user_agent ) ) {
$browser_name = 'Google Chrome';
$browser_name_short = "Chrome";
} elseif ( preg_match( '/Safari/i', $user_agent ) ) {
$browser_name = 'Apple Safari';
$browser_name_short = "Safari";
} elseif ( preg_match( '/Opera/i', $user_agent ) ) {
$browser_name = 'Opera';
$browser_name_short = "Opera";
} elseif ( preg_match( '/Netscape/i', $user_agent ) ) {
$browser_name = 'Netscape';
$browser_name_short = "Netscape";
}
// Finally get the correct version number
$known = array( 'Version', $browser_name_short, 'other' );
$pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if ( ! preg_match_all( $pattern, $user_agent, $matches ) ) {
// We have no matching number just continue
}
// See how many we have
$i = count( $matches['browser'] );
if ( $i != 1 ) {
// We will have two since we are not using 'other' argument yet
// See if version is before or after the name
if ( strripos( $user_agent, "Version" ) < strripos( $user_agent, $browser_name_short ) ) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
$version = $matches['version'][0];
}
// Check if we have a number
if ( $version == null || $version == "" ) {
$version = "?";
}
return array(
'user_agent' => $user_agent,
'name' => $browser_name,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern
);
}
function get_all_plugins() {
return get_plugins();
}
function get_active_plugins() {
return get_option( 'active_plugins', array() );
}
function get_memory_usage() {
return round( memory_get_usage() / 1024 / 1024, 2 );
}
function get_all_options() {
// Not to be confused with the core deprecated get_alloptions
return wp_load_alloptions();
}
function get_transients_in_options( $options ) {
$transients = array();
foreach ( $options as $name => $value ) {
if ( stristr( $name, 'transient' ) ) {
$transients[ $name ] = $value;
}
}
return $transients;
}
}
// Let's get this party started
$sysinfo = new SysInfo();