PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.4
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.4
4.3.2 4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 All 165 releases
← All changes | Inc/Classes/ServerInfo.php +707 -551 4.2.7 → 2.0.4 View file →
@@ -1,14 +1,14 @@
1 1 <?php
2 2
3 -namespace PXLBSAdminify\Inc\Classes;
3 +namespace WPAdminify\Inc\Classes;
4 4
5 +use WPAdminify\Inc\Utils;
6 +
5 7 // no direct access allowed
6 -if (!defined('ABSPATH')) {
7 - exit;
8 -}
8 +if (!defined('ABSPATH')) exit;
9 9 /**
10 - * PXLBSAdminify
10 + * WPAdminify
11 11 * Admin Menu: Server Info
12 12 *
13 13 * @author Jewel Theme <[email protected]>
14 14 */
@@ -15,660 +15,816 @@
15 15
16 16 class ServerInfo
17 17 {
18 18
19 + /**
20 + * SERVER CPU LOAD
21 + * Get the server CPU load in percentage.
22 + */
19 23
20 - /**
21 - * SERVER CPU LOAD
22 - * Get the server CPU load in percentage.
23 - */
24 + public function get_server_cpu_load_percentage()
25 + {
24 26
25 - public function get_server_cpu_load_percentage()
26 - {
27 - $result = -1;
28 - $lines = null;
27 + $result = -1;
28 + $lines = null;
29 29
30 - $os = '';
31 - if (defined('PHP_OS')) {
32 - $os = PHP_OS;
33 - }
30 + $os = '';
31 + if (defined('PHP_OS')) {
32 + $os = PHP_OS;
33 + }
34 34
35 - // Linux server
36 - if ($os == 'Linux') {
37 - $checks = [];
38 - foreach ([0, 1] as $i) {
39 - $cmd = '/proc/stat';
40 - $lines = [];
41 - $fh = fopen($cmd, 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem.
42 - if ($fh) {
43 - while ($line = fgets($fh)) {
44 - $lines[] = $line;
45 - }
46 - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem.
47 - }
48 - foreach ($lines as $line) {
49 - $ma = [];
50 - if (!preg_match('/^cpu (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)$/', $line, $ma)) {
51 - continue;
52 - }
53 - $total = $ma[1] + $ma[2] + $ma[3] + $ma[4] + $ma[5] + $ma[6] + $ma[7] + $ma[8] + $ma[9];
54 - // $totalCpu = $ma[1] + $ma[2] + $ma[3];
55 - // $result = (100 / $total) * $totalCpu;
56 - $ma['total'] = $total;
57 - $checks[] = $ma;
58 - break;
59 - }
60 - if ($i == 0) {
61 - // Wait before checking again.
62 - sleep(1);
63 - }
64 - }
65 - // Idle - prev idle
66 - $diffIdle = $checks[1][4] - $checks[0][4];
67 - // Total - prev total
68 - $diffTotal = $checks[1]['total'] - $checks[0]['total'];
69 - // Usage in %
70 - $diffUsage = round((1000 * ($diffTotal - $diffIdle) / $diffTotal + 5) / 10, 2);
71 - $result = $diffUsage;
35 + // Linux server
36 + if ($os == 'Linux') {
72 37
73 - return (float) $result;
74 - }
38 + $checks = array();
39 + foreach (array(0, 1) as $i) {
40 + $cmd = '/proc/stat';
41 + $lines = array();
42 + $fh = fopen($cmd, 'r');
43 + while ($line = fgets($fh)) {
44 + $lines[] = $line;
45 + }
46 + fclose($fh);
47 + foreach ($lines as $line) {
48 + $ma = array();
49 + if (!preg_match('/^cpu (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)$/', $line, $ma)) {
50 + continue;
51 + }
52 + $total = $ma[1] + $ma[2] + $ma[3] + $ma[4] + $ma[5] + $ma[6] + $ma[7] + $ma[8] + $ma[9];
53 + //$totalCpu = $ma[1] + $ma[2] + $ma[3];
54 + //$result = (100 / $total) * $totalCpu;
55 + $ma['total'] = $total;
56 + $checks[] = $ma;
57 + break;
58 + }
59 + if ($i == 0) {
60 + // Wait before checking again.
61 + sleep(1);
62 + }
63 + }
64 + // Idle - prev idle
65 + $diffIdle = $checks[1][4] - $checks[0][4];
66 + // Total - prev total
67 + $diffTotal = $checks[1]['total'] - $checks[0]['total'];
68 + // Usage in %
69 + $diffUsage = round((1000 * ($diffTotal - $diffIdle) / $diffTotal + 5) / 10, 2);
70 + $result = $diffUsage;
75 71
76 - return 'N/A';
77 - }
72 + return (float) $result;
73 + }
78 74
79 - /**
80 - * Convert Memory Size
81 - *
82 - * @param [type] $size
83 - *
84 - * @return void
85 - */
86 - public function convert_memory_size($size)
87 - {
88 - $l = substr($size, -1);
89 - $ret = substr($size, 0, -1);
75 + return 'N/A';
76 + }
90 77
91 - switch (strtoupper($l)) {
92 - case 'P':
93 - $ret *= 1024;
94 - case 'T':
95 - $ret *= 1024;
96 - case 'G':
97 - $ret *= 1024;
98 - case 'M':
99 - $ret *= 1024;
100 - case 'K':
101 - $ret *= 1024;
102 - }
103 78
104 - return $ret;
105 - }
106 79
107 - /**
108 - * Get Server/WP Memory Limit
109 - */
110 80
111 - public function get_wp_memory_limit()
112 - {
113 - $memory_limit = (int) @ini_get('memory_limit') . ' MB' . ' (' . (int) WP_MEMORY_LIMIT . ' MB)';
114 - if (@ini_get('memory_limit') == '-1') {
115 - $memory_limit = '-1 / ' . esc_html__('Unlimited', 'adminify') . ' (' . (int) WP_MEMORY_LIMIT . ' MB)';
116 - }
81 + /**
82 + *******************
83 + * SERVER CPU CORE COUNT
84 + *******************
85 + *
86 + * Get the count of available server CPU cores.
87 + */
117 88
118 - if ((int) WP_MEMORY_LIMIT < (int) @ini_get('memory_limit') && WP_MEMORY_LIMIT != '-1' || (int) WP_MEMORY_LIMIT < (int) @ini_get('memory_limit') && @ini_get('memory_limit') != '-1') {
119 - /* translators: %s: Server PHP memory limit, e.g. "256 MB" */
120 - $memory_limit .= ' <span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('The WP PHP Memory Limit is less than the %s Server PHP Memory Limit', 'adminify'), (int) @ini_get('memory_limit') . ' MB') . '!</span>';
121 - }
89 + function check_core_count()
90 + {
122 91
123 - return $memory_limit;
124 - }
92 + $cmd = "uname";
125 93
126 - /**
127 - * Get PHP Version
128 - */
129 - public function get_php_version()
130 - {
131 - $php_version = 'N/A';
94 + $OS = strtolower(trim(shell_exec($cmd)));
132 95
133 - if (function_exists('phpversion')) {
134 - $php_version = phpversion();
135 - }
96 + switch ($OS) {
97 + case ('linux'):
98 + $cmd = "cat /proc/cpuinfo | grep processor | wc -l";
99 + break;
100 + case ('freebsd'):
101 + $cmd = "sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2";
102 + break;
103 + default:
104 + unset($cmd);
105 + }
136 106
137 - if (defined('PHP_VERSION')) {
138 - $php_version = PHP_VERSION;
139 - }
107 + if (isset($cmd) && $cmd != '') {
108 + $cpuCoreNo = intval(trim(shell_exec($cmd)));
109 + }
140 110
141 - if ($php_version != 'N/A' && version_compare($php_version, '7.3', '<')) {
142 - /* translators: 1: Current PHP version, 2: Link to WordPress requirements page */
143 - $php_version = '<span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('%1$s - Recommend PHP version of 7.3. See: %2$s', 'adminify'), esc_html($php_version), '<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener">' . __('WordPress Requirements', 'adminify') . '</a>') . '</span>';
144 - }
111 + return empty($cpuCoreNo) ? 1 : $cpuCoreNo;
112 + }
145 113
146 - return $php_version;
147 - }
148 114
149 - /**
150 - * Get PHP Version Only
151 - * */
152 - public function get_php_version_lite()
153 - {
154 - $php_version = 'N/A';
115 + /**
116 + * Convert Memory Size
117 + *
118 + * @param [type] $size
119 + *
120 + * @return void
121 + */
122 + public function convert_memory_size($size)
123 + {
155 124
156 - if (function_exists('phpversion')) {
157 - $php_version = phpversion();
158 - }
125 + $l = substr($size, -1);
126 + $ret = substr($size, 0, -1);
159 127
160 - if (defined('PHP_VERSION')) {
161 - $php_version = PHP_VERSION;
162 - }
128 + switch (strtoupper($l)) {
129 + case 'P':
130 + $ret *= 1024;
131 + case 'T':
132 + $ret *= 1024;
133 + case 'G':
134 + $ret *= 1024;
135 + case 'M':
136 + $ret *= 1024;
137 + case 'K':
138 + $ret *= 1024;
139 + }
163 140
164 - return $php_version;
165 - }
141 + return $ret;
142 + }
166 143
167 - /**
168 - * Get Curl Version
169 - *
170 - * @return void
171 - */
172 - public function get_cURL_version()
173 - {
174 - $curl_version = 'N/A';
144 + /**
145 + * Get Server/WP Memory Limit
146 + */
175 147
176 - if (function_exists('curl_version')) {
177 - $curl_version = curl_version();
178 - $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
179 - }
148 + public function get_wp_memory_limit()
149 + {
180 150
181 - return $curl_version;
182 - }
151 + $memory_limit = (int)@ini_get('memory_limit') . ' MB' . ' (' . (int)WP_MEMORY_LIMIT . ' MB)';
152 + if (@ini_get('memory_limit') == '-1') {
153 + $memory_limit = '-1 / ' . esc_html__('Unlimited', WP_ADMINIFY_TD) . ' (' . (int)WP_MEMORY_LIMIT . ' MB)';
154 + }
183 155
184 - /**
185 - * Get MySQL Version
186 - *
187 - * @return void
188 - */
189 - public function get_mysql_version()
190 - {
191 - global $wpdb;
156 + if ((int)WP_MEMORY_LIMIT < (int)@ini_get('memory_limit') && WP_MEMORY_LIMIT != '-1' || (int)WP_MEMORY_LIMIT < (int)@ini_get('memory_limit') && @ini_get('memory_limit') != '-1') {
157 + $memory_limit .= ' <span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('The WP PHP Memory Limit is less than the %s Server PHP Memory Limit', WP_ADMINIFY_TD), (int)@ini_get('memory_limit') . ' MB') . '!</span>';
158 + }
192 159
193 - // Short Version
194 - // $db_version = $wpdb->db_server_info();
160 + return $memory_limit;
161 + }
195 162
196 - $db_version_dump = $wpdb->get_var('SELECT VERSION() AS version from DUAL'); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for reading the live MySQL server version; not cached intentionally.
197 - if (preg_match('/\d+(?:\.\d+)+/', $db_version_dump, $matches)) {
198 - $db_version = $matches[0]; // returning the first match
199 - } else {
200 - $db_version = __('N/A', 'adminify');
201 - }
202 - return $db_version;
203 - }
163 + /**
164 + * Get PHP Version
165 + */
166 + public function get_php_version()
167 + {
204 168
169 + $php_version = 'N/A';
205 170
206 - /**
207 - * Get Get Database Software Name
208 - *
209 - * @return void
210 - */
211 - public function get_db_software()
212 - {
213 - global $wpdb;
214 - $db_software_query = $wpdb->get_row("SHOW VARIABLES LIKE 'version_comment'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for reading the live MySQL server variable; not cached intentionally.
215 - $db_software_dump = $db_software_query->Value;
216 - if (!empty($db_software_dump)) {
217 - $db_soft_array = explode(' ', trim($db_software_dump));
218 - $db_software = $db_soft_array[0];
219 - } else {
220 - $db_software = __('N/A', 'adminify');
221 - }
171 + if (function_exists('phpversion')) {
172 + $php_version = phpversion();
173 + }
222 174
223 - return $db_software;
224 - }
175 + if (defined('PHP_VERSION')) {
176 + $php_version = PHP_VERSION;
177 + }
225 178
226 - /**
227 - * Get WP Table Prefix
228 - */
229 - public function get_table_prefix()
230 - {
231 - global $wpdb;
179 + if ($php_version != 'N/A' && version_compare($php_version, '7.3', '<')) {
180 + $php_version = '<span class="warning"><span class="dashicons dashicons-warning"></span> ' . sprintf(__('%s - Recommend PHP version of 7.3. See: %s', WP_ADMINIFY_TD), esc_html($php_version), '<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener">' . __('WordPress Requirements', WP_ADMINIFY_TD) . '</a>') . '</span>';
181 + }
232 182
233 - $prefix = [
234 - 'tablePrefix' => $wpdb->prefix,
235 - 'tableBasePrefix' => $wpdb->base_prefix,
236 - ];
183 + return $php_version;
184 + }
237 185
238 - return $prefix;
239 - }
186 + /**
187 + * Get PHP Version Only
188 + * */
189 + public function get_php_version_lite()
190 + {
240 191
192 + $php_version = 'N/A';
241 193
242 - /**
243 - * Get WP Timezone
244 - */
194 + if (function_exists('phpversion')) {
195 + $php_version = phpversion();
196 + }
245 197
246 - public function get_wp_timezone()
247 - {
248 - $timezone = get_option('timezone_string'); // Direct value
198 + if (defined('PHP_VERSION')) {
199 + $php_version = PHP_VERSION;
200 + }
249 201
250 - // Create a UTC+- zone if no timezone string exists
251 - if (empty($timezone)) {
252 - // Current offset
253 - $current_offset = get_option('gmt_offset');
202 + return $php_version;
203 + }
254 204
255 - // Plus offset
256 - $timezone = 'UTC+' . $current_offset;
205 + /**
206 + * Get Curl Version
207 + *
208 + * @return void
209 + */
210 + public function get_cURL_version()
211 + {
257 212
258 - // No offset
259 - if (0 == $current_offset) {
260 - $timezone = 'UTC+0';
261 - // Negative offset
262 - } elseif ($current_offset < 0) {
263 - $timezone = 'UTC' . $current_offset;
264 - }
213 + $curl_version = 'N/A';
265 214
266 - // Normalize
267 - $timezone = str_replace(['.25', '.5', '.75'], [':15', ':30', ':45'], $timezone);
268 - }
215 + if (function_exists('curl_version')) {
216 + $curl_version = curl_version();
217 + $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
218 + }
269 219
270 - return $timezone;
271 - }
220 + return $curl_version;
221 + }
272 222
273 - /**
274 - * Get Server/WP Total RAM
275 - *
276 - * @return void
277 - */
278 - public function get_server_total_ram()
279 - {
280 - $os = '';
281 - if (defined('PHP_OS')) {
282 - $os = PHP_OS;
283 - }
223 + /**
224 + * Get MySQL Version
225 + *
226 + * @return void
227 + */
228 + public function get_mysql_version()
229 + {
230 + global $wpdb;
284 231
285 - $result = 0;
232 + // Short Version
233 + // $db_version = $wpdb->db_server_info();
286 234
287 - // Linux server
288 - if ($os == 'Linux') {
289 - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem.
290 - if ($fh) {
291 - while ($line = fgets($fh)) {
292 - $pieces = [];
293 - if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
294 - $result = $pieces[1];
295 - // KB to Bytes
296 - $result = round($result / 1024 / 1024, 2);
297 - break;
298 - }
299 - }
300 - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem.
301 - return $result;
302 - }
303 - }
235 + $db_version_dump = $wpdb->get_var("SELECT VERSION() AS version from DUAL");
236 + if (preg_match('/\d+(?:\.\d+)+/', $db_version_dump, $matches)) {
237 + $db_version = $matches[0]; //returning the first match
238 + } else {
239 + $db_version = __('N/A', WP_ADMINIFY_TD);
240 + }
241 + return $db_version;
242 + }
304 243
305 - return 'N/A';
306 - }
307 244
245 + /**
246 + * Get Get Database Software Name
247 + *
248 + * @return void
249 + */
250 + public function get_db_software()
251 + {
308 252
309 - /**
310 - * Get Server/WP Free RAM
311 - */
312 - public function get_server_free_ram()
313 - {
314 - $os = '';
315 - if (defined('PHP_OS')) {
316 - $os = PHP_OS;
317 - }
253 + global $wpdb;
254 + $db_software_query = $wpdb->get_row("SHOW VARIABLES LIKE 'version_comment'");
255 + $db_software_dump = $db_software_query->Value;
256 + if (!empty($db_software_dump)) {
257 + $db_soft_array = explode(" ", trim($db_software_dump));
258 + $db_software = $db_soft_array[0];
259 + } else {
260 + $db_software = __('N/A', WP_ADMINIFY_TD);
261 + }
318 262
319 - $result = 0;
263 + return $db_software;
264 + }
320 265
321 - // Linux server
322 - if ($os == 'Linux') {
323 - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem.
324 - if ($fh) {
325 - while ($line = fgets($fh)) {
326 - $pieces = [];
327 - if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
328 - // KB to Bytes
329 - $result = round($pieces[1] / 1024 / 1024, 2);
330 - break;
331 - }
332 - }
333 - fclose($fh); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- closing the /proc special path not supported by WP_Filesystem.
266 + /**
267 + * Get WP Table Prefix
268 + */
269 + public function get_table_prefix()
270 + {
334 271
335 - return $result;
336 - }
337 - }
272 + global $wpdb;
338 273
339 - return 'N/A';
340 - }
274 + $prefix = array(
275 + 'tablePrefix' => $wpdb->prefix,
276 + 'tableBasePrefix' => $wpdb->base_prefix,
277 + );
341 278
342 - /**
343 - * Get Server/WP RAM Details
344 - *
345 - * @return void
346 - */
347 - public function get_server_ram_details()
348 - {
349 - $os = '';
350 - if (defined('PHP_OS')) {
351 - $os = PHP_OS;
352 - }
279 + return $prefix;
280 + }
353 281
354 - if ($os == 'Linux') {
282 + /**
283 + * Shell Enable/Disable
284 + */
285 + public function is_shell_enable()
286 + {
355 287
356 - $ram_data = '';
357 - // Check if it readable
358 - $fh = fopen('/proc/meminfo', 'r'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- reading the /proc special path not supported by WP_Filesystem.
359 - if ($fh) {
360 - foreach (file('/proc/meminfo') as $ri) {
361 - $m[strtok($ri, ':')] = strtok('');
362 - }
288 + if (function_exists('shell_exec') && !in_array('shell_exec', array_map('trim', explode(', ', ini_get('disable_functions'))))) {
289 + // If enabled, check if shell_exec() actually have execution power
290 + $returnVal = shell_exec('cat /proc/cpuinfo');
291 + if (!empty($returnVal)) {
292 + return true;
293 + } else {
294 + return false;
295 + }
296 + } else {
297 + return false;
298 + }
299 + }
363 300
364 - $ram_total = round((int) $m['MemTotal'] / 1024 / 1024, 2);
365 - $ram_available = round((int) $m['MemAvailable'] / 1024 / 1024, 2);
366 - $ram_free = round((int) $m['MemFree'] / 1024 / 1024, 2);
367 - $ram_buffers = round((int) $m['Buffers'] / 1024 / 1024, 2);
368 - $ram_cached = round((int) $m['Cached'] / 1024 / 1024, 2);
301 + /**
302 + * Get Server Uptime
303 + */
304 + public function get_server_uptime()
305 + {
306 +
307 + error_reporting(0);
308 +
309 + if (ini_get('disable_functions')) {
310 + $disabled_funcs = array_map('trim',explode(',',ini_get('disable_functions')));
311 + }
312 +
313 + if (strpos(strtolower(PHP_OS),'win') !== FALSE) {
314 +
315 + // For Windaz
316 + if (!in_array('exec',$disabled_funcs)) {
317 +
318 + set_time_limit(150); // 'systeminfo' command can take a while...
319 +
320 + $uptime = exec('systeminfo | find "System Up"');
321 + $parts = explode(':',$uptime);
322 + $parts = array_pop($parts);
323 + $parts = explode(',',trim($parts));
324 +
325 + foreach (array('days','hours','mins','secs') as $k => $v) {
326 + $parts[$k] = explode(' ',trim($parts[$k]));
327 + $$v = ($k) ? str_pad(array_shift($parts[$k]),2,'0',STR_PAD_LEFT) : array_shift($parts[$k]);
328 + }
369 329
370 - $mem_kernel_app = round((100 - ($ram_buffers + $ram_cached + $ram_free) / $ram_total * 100), 2);
371 - $mem_cached = round($ram_cached / $ram_total * 100, 2);
372 - $mem_buffers = round($ram_buffers / $ram_total * 100, 2);
330 + return ( $days * DAY_IN_SECONDS ) + ( $hours * HOUR_IN_SECONDS ) + ( $mins * MINUTE_IN_SECONDS ) + $secs;
331 +
332 + }
333 +
334 + } else {
335 +
336 + // For *nix
337 +
338 + if (in_array('shell_exec',$disabled_funcs)) {
339 + $uptime_text = file_get_contents("/proc/uptime");
340 + $uptime = substr($uptime_text,0,strpos($uptime_text," "));
341 + } else {
342 + $uptime = shell_exec("cut -d. -f1 /proc/uptime");
343 + }
373 344
374 - $ram_data = [
375 - 'MemTotal' => $ram_total,
376 - 'MemAvailable' => $ram_available,
377 - 'MemFree' => $ram_free,
378 - 'Buffers' => $ram_buffers,
379 - 'Cached' => $ram_cached,
380 - 'MemUsagePercentage' => round($mem_kernel_app + $mem_buffers + $mem_cached, 2), // Physical Memory
381 - ];
345 + $days = floor($uptime/60/60/24);
346 + $hours = str_pad($uptime/60/60%24,2,"0",STR_PAD_LEFT);
347 + $mins = str_pad($uptime/60%60,2,"0",STR_PAD_LEFT);
348 + $secs = str_pad($uptime%60,2,"0",STR_PAD_LEFT);
382 349
383 - return $ram_data;
384 - }
385 - }
350 + return ( $days * DAY_IN_SECONDS ) + ( $hours * HOUR_IN_SECONDS ) + ( $mins * MINUTE_IN_SECONDS ) + $secs;
351 +
352 + }
386 353
387 - return 'N/A';
388 - }
354 + return false;
389 355
390 - /**
391 - * Get Real Server Memory Usage
392 - */
393 - public function get_real_memory_usage()
394 - {
395 - $real_memory_usage = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage(true)) : 0;
356 + }
396 357
397 - if ($real_memory_usage) {
398 - return $real_memory_usage;
399 - }
400 358
401 - return 'N/A';
402 - }
359 + /**
360 + * Get WP Timezone
361 + */
403 362
404 - /**
405 - * WP Memory Usage
406 - */
407 - public function get_wp_memory_usage()
408 - {
409 - // Get PHP memory limit
410 - $php_memory_limit = ini_get('memory_limit');
363 + public function get_wp_timezone()
364 + {
411 365
412 - // Get WordPress memory limit if defined
413 - $wordpress_memory_limit = defined('WP_MEMORY_LIMIT') ? WP_MEMORY_LIMIT : null;
366 + $timezone = get_option('timezone_string'); // Direct value
414 367
415 - // Determine the effective memory limit with PHP memory limit taking priority
416 - $get_memory_limit = $php_memory_limit ? $php_memory_limit : $wordpress_memory_limit;
368 + // Create a UTC+- zone if no timezone string exists
369 + if (empty($timezone)) {
370 + // Current offset
371 + $current_offset = get_option('gmt_offset');
417 372
373 + // Plus offset
374 + $timezone = 'UTC+' . $current_offset;
418 375
419 - // Get WP Memory Limit
420 - // $get_memory_limit = WP_MEMORY_LIMIT;
421 - // if ((int) WP_MEMORY_LIMIT > (int) @ini_get('memory_limit')) {
422 - // // WP Limit can't be greater than Server Limiit
423 - // $get_memory_limit = @ini_get('memory_limit');
424 - // }
376 + // No offset
377 + if (0 == $current_offset) {
378 + $timezone = 'UTC+0';
379 + // Negative offset
380 + } elseif ($current_offset < 0) {
381 + $timezone = 'UTC' . $current_offset;
382 + }
425 383
426 - $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
427 - $memory_limit_format = size_format($memory_limit_convert);
428 - $memory_limit = $memory_limit_convert;
384 + // Normalize
385 + $timezone = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $timezone);
386 + }
429 387
430 - // Get Real Memory Usage
431 - $get_memory_usage = $this->get_real_memory_usage();
432 - $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
433 - $memory_usage_format = $memory_usage_convert . 'MB';
434 - $memory_usage = $get_memory_usage;
388 + return $timezone;
389 + }
435 390
436 - if ($get_memory_usage != false && $get_memory_limit != false) {
391 + /**
392 + * Get Server/WP Total RAM
393 + *
394 + * @return void
395 + */
396 + public function get_server_total_ram()
397 + {
437 398
438 - // check memory limit is a numeric value
439 - if (!is_numeric($memory_limit)) {
440 - $memory_limit = 999;
441 - }
399 + $os = '';
400 + if (defined('PHP_OS')) {
401 + $os = PHP_OS;
402 + }
442 403
443 - $wp_mem_data = [
444 - 'MemLimit' => $memory_limit,
445 - 'MemLimitGet' => $get_memory_limit,
446 - 'MemLimitConvert' => $memory_limit_convert,
447 - 'MemLimitFormat' => $memory_limit_format,
448 - 'MemUsage' => $memory_usage,
449 - 'MemUsageGet' => $get_memory_usage,
450 - 'MemUsageConvert' => $memory_usage_convert,
451 - 'MemUsageFormat' => $memory_usage_format,
452 - 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
453 - ];
404 + $result = 0;
454 405
455 - return $wp_mem_data;
456 - }
406 + // Linux server
407 + if ($os == 'Linux') {
457 408
458 - return 'N/A';
459 - }
409 + $fh = fopen('/proc/meminfo', 'r');
410 + while ($line = fgets($fh)) {
411 + $pieces = array();
412 + if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
413 + $result = $pieces[1];
414 + // KB to Bytes
415 + $result = round($result / 1024 / 1024, 2);
416 + break;
417 + }
418 + }
419 + fclose($fh);
460 420
461 - /**
462 - * Server Memory Usage
463 - */
464 - public function get_server_memory_usage()
465 - {
421 + return $result;
422 + }
466 423
467 - // Get Server Memory Limit
468 - $get_memory_limit = @ini_get('memory_limit');
469 - $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
470 - $memory_limit_format = size_format($memory_limit_convert);
471 - $memory_limit = $memory_limit_convert;
424 + return 'N/A';
425 + }
472 426
473 - // Get Real Memory Usage
474 - $get_memory_usage = $this->get_real_memory_usage();
475 - $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
476 - $memory_usage_format = $memory_usage_convert . ' MB';
477 - $memory_usage = $get_memory_usage;
478 427
479 - if ($get_memory_usage != false && $get_memory_limit != false) {
428 + /**
429 + * Get Server/WP Free RAM
430 + */
431 + public function get_server_free_ram()
432 + {
480 433
481 - // check memory limit is a numeric value
482 - if (!is_numeric($memory_limit)) {
483 - $memory_limit = 999;
484 - }
434 + $os = '';
435 + if (defined('PHP_OS')) {
436 + $os = PHP_OS;
437 + }
485 438
486 - $php_mem_data = [
487 - 'MemLimit' => $memory_limit,
488 - 'MemLimitGet' => $get_memory_limit,
489 - 'MemLimitConvert' => $memory_limit_convert,
490 - 'MemLimitFormat' => $memory_limit_format,
491 - 'MemUsage' => $memory_usage,
492 - 'MemUsageGet' => $get_memory_usage,
493 - 'MemUsageConvert' => $memory_usage_convert,
494 - 'MemUsageFormat' => $memory_usage_format,
495 - 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
496 - ];
439 + $result = 0;
497 440
498 - return $php_mem_data;
499 - }
441 + // Linux server
442 + if ($os == 'Linux') {
500 443
501 - return 'N/A';
502 - }
444 + $fh = fopen('/proc/meminfo', 'r');
445 + while ($line = fgets($fh)) {
446 + $pieces = array();
447 + if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
448 + // KB to Bytes
449 + $result = round($pieces[1] / 1024 / 1024, 2);
450 + break;
451 + }
452 + }
453 + fclose($fh);
503 454
455 + return $result;
456 + }
504 457
505 - public static function memory_usage_percentage()
506 - {
507 - $memory_usage = (new ServerInfo())->get_wp_memory_usage();
508 - $memory_usage_percentage = $memory_usage['MemUsageCalc'];
509 - return $memory_usage_percentage;
510 - }
458 + return 'N/A';
459 + }
511 460
461 + /**
462 + * Get Server/WP RAM Details
463 + *
464 + * @return void
465 + */
466 + public function get_server_ram_details()
467 + {
512 468
469 + $os = '';
470 + if (defined('PHP_OS')) {
471 + $os = PHP_OS;
472 + }
513 473
474 + $ram_data = '';
475 + if ($os == 'Linux') {
514 476
515 - /**
516 - * Get Server Disk Size
517 - */
477 + foreach (file('/proc/meminfo') as $ri) {
478 + $m[strtok($ri, ':')] = strtok('');
479 + }
518 480
519 - public function get_server_disk_size($path = '/')
520 - {
521 - $os = '';
522 - if (defined('PHP_OS')) {
523 - $os = PHP_OS;
524 - }
481 + $ram_total = round((int)$m['MemTotal'] / 1024 / 1024, 2);
482 + $ram_available = round((int)$m['MemAvailable'] / 1024 / 1024, 2);
483 + $ram_free = round((int)$m['MemFree'] / 1024 / 1024, 2);
484 + $ram_buffers = round((int)$m['Buffers'] / 1024 / 1024, 2);
485 + $ram_cached = round((int)$m['Cached'] / 1024 / 1024, 2);
525 486
526 - // Linux server
527 - if ($os == 'Linux') {
528 - $result = [];
529 - $result['size'] = 0;
530 - $result['free'] = 0;
531 - $result['used'] = 0;
487 + $mem_kernel_app = round((100 - ($ram_buffers + $ram_cached + $ram_free) / $ram_total * 100), 2);
488 + $mem_cached = round($ram_cached / $ram_total * 100, 2);
489 + $mem_buffers = round($ram_buffers / $ram_total * 100, 2);
532 490
533 - $lines = null;
534 - // $path defaults to '/'. Escape it before composing the shell
535 - // command so any future caller-supplied path can't break out
536 - // into additional commands.
537 - exec( sprintf( 'df /P %s', escapeshellarg( $path ) ), $lines );
491 + $ram_data = array(
492 + 'MemTotal' => $ram_total,
493 + 'MemAvailable' => $ram_available,
494 + 'MemFree' => $ram_free,
495 + 'Buffers' => $ram_buffers,
496 + 'Cached' => $ram_cached,
497 + 'MemUsagePercentage' => round($mem_kernel_app + $mem_buffers + $mem_cached, 2), // Physical Memory
498 + );
538 499
539 - foreach ($lines as $index => $line) {
540 - if ($index != 1) {
541 - continue;
542 - }
543 - $values = preg_split('/\s{1,}/', $line);
544 - $result['size'] = round($values[1] / 1024 / 1024, 2);
545 - $result['free'] = round($values[3] / 1024 / 1024, 2);
546 - $result['used'] = round($values[2] / 1024 / 1024, 2);
547 - $result['usage'] = round($result['used'] / $result['size'] * 100, 2);
548 - break;
549 - }
500 + return $ram_data;
501 + }
550 502
551 - return $result;
552 - }
503 + return 'N/A';
504 + }
553 505
554 - return 'N/A';
555 - }
506 + /**
507 + * Get Real Server Memory Usage
508 + */
509 + public function get_real_memory_usage()
510 + {
511 + $real_memory_usage = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage(true)) : 0;
556 512
513 + if ($real_memory_usage) {
514 + return $real_memory_usage;
515 + }
557 516
517 + return 'N/A';
518 + }
558 519
520 + /**
521 + * WP Memory Usage
522 + */
523 + public function get_wp_memory_usage()
524 + {
525 + // Get WP Memory Limit
526 + $get_memory_limit = WP_MEMORY_LIMIT;
527 + if ((int)WP_MEMORY_LIMIT > (int)@ini_get('memory_limit')) {
528 + // WP Limit can't be greater than Server Limiit
529 + $get_memory_limit = @ini_get('memory_limit');
530 + }
559 531
560 - /**
561 - * CPU Load Average
562 - *
563 - * @return void
564 - */
532 + $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
533 + $memory_limit_format = size_format($memory_limit_convert);
534 + $memory_limit = $memory_limit_convert;
565 535
566 - public function get_cpu_load_average()
567 - {
568 - $load = 'N/A';
536 + // Get Real Memory Usage
537 + $get_memory_usage = $this->get_real_memory_usage();
538 + $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
539 + $memory_usage_format = $memory_usage_convert . 'MB';
540 + $memory_usage = $get_memory_usage;
569 541
570 - // Check via PHP function
571 - $avg = function_exists('sys_getloadavg') ? sys_getloadavg() : false;
572 - if (!empty($avg) && is_array($avg) && 3 == count($avg)) {
573 - $load = implode(', ', $avg);
574 - }
542 + if ($get_memory_usage != false && $get_memory_limit != false) {
575 543
576 - return $load;
577 - }
544 + // check memory limit is a numeric value
545 + if (!is_numeric($memory_limit)) $memory_limit = 999;
578 546
579 - /**
580 - * Get IP Address
581 - *
582 - * @return void
583 - */
584 - public function get_ip_address()
585 - {
586 - // Get ip address
547 + $wp_mem_data = array(
548 + 'MemLimit' => $memory_limit,
549 + 'MemLimitGet' => $get_memory_limit,
550 + 'MemLimitConvert' => $memory_limit_convert,
551 + 'MemLimitFormat' => $memory_limit_format,
552 + 'MemUsage' => $memory_usage,
553 + 'MemUsageGet' => $get_memory_usage,
554 + 'MemUsageConvert' => $memory_usage_convert,
555 + 'MemUsageFormat' => $memory_usage_format,
556 + 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
557 + );
587 558
588 - $ip_address = isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_ADDR'])) : '';
589 - if (!$ip_address) {
590 - $ip_address = isset($_SERVER['LOCAL_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['LOCAL_ADDR'])) : '';
591 - }
592 - return $ip_address;
593 - }
559 + return $wp_mem_data;
560 + }
594 561
595 - /**
596 - * Get WordPress Version
597 - *
598 - * @return void
599 - */
600 - public function get_wp_version()
601 - {
602 - global $wp_version;
603 - return $wp_version;
604 - }
562 + return 'N/A';
563 + }
605 564
606 - public function check_limit()
607 - {
608 - $memory_limit = ini_get('memory_limit');
609 - if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
610 - if ($matches[2] == 'G') {
611 - $memory_limit = $matches[1] . ' ' . 'GB'; // nnnG -> nnn GB
612 - } elseif ($matches[2] == 'M') {
613 - $memory_limit = $matches[1] . ' ' . 'MB'; // nnnM -> nnn MB
614 - } elseif ($matches[2] == 'K') {
615 - $memory_limit = $matches[1] . ' ' . 'KB'; // nnnK -> nnn KB
616 - } elseif ($matches[2] == 'T') {
617 - $memory_limit = $matches[1] . ' ' . 'TB'; // nnnT -> nnn TB
618 - } elseif ($matches[2] == 'P') {
619 - $memory_limit = $matches[1] . ' ' . 'PB'; // nnnP -> nnn PB
620 - }
621 - }
622 - return $memory_limit;
623 - }
565 + /**
566 + * Server Memory Usage
567 + */
568 + public function get_server_memory_usage()
569 + {
624 570
625 - public function format_filesize($bytes)
626 - {
627 - if (($bytes / pow(1024, 5)) > 1) {
628 - return number_format_i18n(($bytes / pow(1024, 5)), 0) . ' ' . __('PB', 'adminify');
629 - } elseif (($bytes / pow(1024, 4)) > 1) {
630 - return number_format_i18n(($bytes / pow(1024, 4)), 0) . ' ' . __('TB', 'adminify');
631 - } elseif (($bytes / pow(1024, 3)) > 1) {
632 - return number_format_i18n(($bytes / pow(1024, 3)), 0) . ' ' . __('GB', 'adminify');
633 - } elseif (($bytes / pow(1024, 2)) > 1) {
634 - return number_format_i18n(($bytes / pow(1024, 2)), 0) . ' ' . __('MB', 'adminify');
635 - } elseif ($bytes / 1024 > 1) {
636 - return number_format_i18n($bytes / 1024, 0) . ' ' . __('KB', 'adminify');
637 - } elseif ($bytes >= 0) {
638 - return number_format_i18n($bytes, 0) . ' ' . __('bytes', 'adminify');
639 - } else {
640 - return __('Unknown', 'adminify');
641 - }
642 - }
571 + // Get Server Memory Limit
572 + $get_memory_limit = @ini_get('memory_limit');
573 + $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
574 + $memory_limit_format = size_format($memory_limit_convert);
575 + $memory_limit = $memory_limit_convert;
643 576
644 - public function format_filesize_kB($kiloBytes)
645 - {
646 - if (($kiloBytes / pow(1024, 4)) > 1) {
647 - return number_format_i18n(($kiloBytes / pow(1024, 4)), 0) . ' ' . __('PB', 'adminify');
648 - } elseif (($kiloBytes / pow(1024, 3)) > 1) {
649 - return number_format_i18n(($kiloBytes / pow(1024, 3)), 0) . ' ' . __('TB', 'adminify');
650 - } elseif (($kiloBytes / pow(1024, 2)) > 1) {
651 - return number_format_i18n(($kiloBytes / pow(1024, 2)), 0) . ' ' . __('GB', 'adminify');
652 - } elseif (($kiloBytes / 1024) > 1) {
653 - return number_format_i18n($kiloBytes / 1024, 0) . ' ' . __('MB', 'adminify');
654 - } elseif ($kiloBytes >= 0) {
655 - return number_format_i18n($kiloBytes / 1, 0) . ' ' . __('KB', 'adminify');
656 - } else {
657 - return __('Unknown', 'adminify');
658 - }
659 - }
577 + // Get Real Memory Usage
578 + $get_memory_usage = $this->get_real_memory_usage();
579 + $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
580 + $memory_usage_format = $memory_usage_convert . ' MB';
581 + $memory_usage = $get_memory_usage;
660 582
661 - public function format_php_size($size)
662 - {
663 - if (!is_numeric($size)) {
664 - if (strpos($size, 'M') !== false) {
665 - $size = intval($size) * 1024 * 1024;
666 - } elseif (strpos($size, 'K') !== false) {
667 - $size = intval($size) * 1024;
668 - } elseif (strpos($size, 'G') !== false) {
669 - $size = intval($size) * 1024 * 1024 * 1024;
670 - }
671 - }
672 - return is_numeric($size) ? $this->format_filesize($size) : $size;
673 - }
583 + if ($get_memory_usage != false && $get_memory_limit != false) {
584 +
585 + // check memory limit is a numeric value
586 + if (!is_numeric($memory_limit)) $memory_limit = 999;
587 +
588 + $php_mem_data = array(
589 + 'MemLimit' => $memory_limit,
590 + 'MemLimitGet' => $get_memory_limit,
591 + 'MemLimitConvert' => $memory_limit_convert,
592 + 'MemLimitFormat' => $memory_limit_format,
593 + 'MemUsage' => $memory_usage,
594 + 'MemUsageGet' => $get_memory_usage,
595 + 'MemUsageConvert' => $memory_usage_convert,
596 + 'MemUsageFormat' => $memory_usage_format,
597 + 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
598 + );
599 +
600 + return $php_mem_data;
601 + }
602 +
603 + return 'N/A';
604 + }
605 +
606 +
607 + public static function wp_memory_usage_percentage()
608 + {
609 + $memory_usage = (new ServerInfo)->get_wp_memory_usage();
610 + $memory_usage_percentage = $memory_usage['MemUsageCalc'];
611 + return $memory_usage_percentage;
612 + }
613 +
614 +
615 +
616 +
617 + /**
618 + * Get Server Disk Size
619 + */
620 +
621 + public function get_server_disk_size($path = '/')
622 + {
623 +
624 + $os = '';
625 + if (defined('PHP_OS')) {
626 + $os = PHP_OS;
627 + }
628 +
629 + // Linux server
630 + if ($os == 'Linux') {
631 +
632 + $result = array();
633 + $result['size'] = 0;
634 + $result['free'] = 0;
635 + $result['used'] = 0;
636 +
637 + $lines = null;
638 + exec(sprintf('df /P %s', $path), $lines);
639 +
640 + foreach ($lines as $index => $line) {
641 + if ($index != 1) {
642 + continue;
643 + }
644 + $values = preg_split('/\s{1,}/', $line);
645 + $result['size'] = round($values[1] / 1024 / 1024, 2);
646 + $result['free'] = round($values[3] / 1024 / 1024, 2);
647 + $result['used'] = round($values[2] / 1024 / 1024, 2);
648 + $result['usage'] = round($result['used'] / $result['size'] * 100, 2);
649 + break;
650 + }
651 +
652 + return $result;
653 + }
654 +
655 + return 'N/A';
656 + }
657 +
658 +
659 +
660 + /**
661 + * CPU Count
662 + */
663 + public function check_cpu_count()
664 + {
665 +
666 + if ($this->is_shell_enable()) {
667 + $cpu_count = shell_exec('cat /proc/cpuinfo |grep "physical id" | sort | uniq | wc -l');
668 + set_transient('wphave_admin_cpu_count', $cpu_count, WEEK_IN_SECONDS);
669 + } else {
670 + $cpu_count = 'N/A';
671 + }
672 +
673 + return $cpu_count;
674 + }
675 +
676 + /**
677 + * CPU Load Average
678 + *
679 + * @return void
680 + */
681 +
682 + public function get_cpu_load_average()
683 + {
684 + $load = 'N/A';
685 +
686 + // Check via PHP function
687 + $avg = function_exists('sys_getloadavg') ? sys_getloadavg() : false;
688 + if (!empty($avg) && is_array($avg) && 3 == count($avg)) {
689 + $load = implode(', ', $avg);
690 + }
691 +
692 + return $load;
693 + }
694 +
695 + /** CPU Load */
696 + public function get_cpu_load()
697 + {
698 + $cpu_load = 'N/A';
699 + if ($this->is_shell_enable()) {
700 + $cpu_load .= trim(shell_exec("echo $((`ps aux|awk 'NR > 0 { s +=$3 }; END {print s}'| cut -d . -f 1` / `cat /proc/cpuinfo | grep cores | grep -o '[0-9]' | wc -l`))"));
701 + }
702 + return $cpu_load;
703 + }
704 +
705 + /**
706 + * CPU Core Count
707 + */
708 +
709 + public function get_cpu_core_count()
710 + {
711 +
712 + $cmd = "uname";
713 +
714 + $OS = strtolower(trim(shell_exec($cmd)));
715 +
716 + switch ($OS) {
717 + case ('linux'):
718 + $cmd = "cat /proc/cpuinfo | grep processor | wc -l";
719 + break;
720 + case ('freebsd'):
721 + $cmd = "sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2";
722 + break;
723 + default:
724 + unset($cmd);
725 + }
726 +
727 + if (isset($cmd) && $cmd != '') {
728 + $cpuCoreNo = intval(trim(shell_exec($cmd)));
729 + }
730 +
731 + return empty($cpuCoreNo) ? 1 : $cpuCoreNo;
732 + }
733 +
734 + /**
735 + * Get IP Address
736 + *
737 + * @return void
738 + */
739 + public function get_ip_address()
740 + {
741 + // Get ip address
742 + $ip_address = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
743 + if (!$ip_address) {
744 + $ip_address = isset($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR'] : '';
745 + }
746 + return $ip_address;
747 + }
748 +
749 + /**
750 + * Get WordPress Version
751 + *
752 + * @return void
753 + */
754 + public function get_wp_version()
755 + {
756 + global $wp_version;
757 + return $wp_version;
758 + }
759 +
760 +
761 +
762 + public function check_limit()
763 + {
764 + $memory_limit = ini_get('memory_limit');
765 + if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
766 + if ($matches[2] == 'G') {
767 + $memory_limit = $matches[1] . ' ' . 'GB'; // nnnG -> nnn GB
768 + } else if ($matches[2] == 'M') {
769 + $memory_limit = $matches[1] . ' ' . 'MB'; // nnnM -> nnn MB
770 + } else if ($matches[2] == 'K') {
771 + $memory_limit = $matches[1] . ' ' . 'KB'; // nnnK -> nnn KB
772 + } else if ($matches[2] == 'T') {
773 + $memory_limit = $matches[1] . ' ' . 'TB'; // nnnT -> nnn TB
774 + } else if ($matches[2] == 'P') {
775 + $memory_limit = $matches[1] . ' ' . 'PB'; // nnnP -> nnn PB
776 + }
777 + }
778 + return $memory_limit;
779 + }
780 +
781 + public function format_filesize($bytes)
782 + {
783 + if (($bytes / pow(1024, 5)) > 1) {
784 + return number_format_i18n(($bytes / pow(1024, 5)), 0) . ' ' . __('PB', WP_ADMINIFY_TD);
785 + } elseif (($bytes / pow(1024, 4)) > 1) {
786 + return number_format_i18n(($bytes / pow(1024, 4)), 0) . ' ' . __('TB', WP_ADMINIFY_TD);
787 + } elseif (($bytes / pow(1024, 3)) > 1) {
788 + return number_format_i18n(($bytes / pow(1024, 3)), 0) . ' ' . __('GB', WP_ADMINIFY_TD);
789 + } elseif (($bytes / pow(1024, 2)) > 1) {
790 + return number_format_i18n(($bytes / pow(1024, 2)), 0) . ' ' . __('MB', WP_ADMINIFY_TD);
791 + } elseif ($bytes / 1024 > 1) {
792 + return number_format_i18n($bytes / 1024, 0) . ' ' . __('KB', WP_ADMINIFY_TD);
793 + } elseif ($bytes >= 0) {
794 + return number_format_i18n($bytes, 0) . ' ' . __('bytes', WP_ADMINIFY_TD);
795 + } else {
796 + return __('Unknown', WP_ADMINIFY_TD);
797 + }
798 + }
799 +
800 + public function format_filesize_kB($kiloBytes)
801 + {
802 + if (($kiloBytes / pow(1024, 4)) > 1) {
803 + return number_format_i18n(($kiloBytes / pow(1024, 4)), 0) . ' ' . __('PB', WP_ADMINIFY_TD);
804 + } elseif (($kiloBytes / pow(1024, 3)) > 1) {
805 + return number_format_i18n(($kiloBytes / pow(1024, 3)), 0) . ' ' . __('TB', WP_ADMINIFY_TD);
806 + } elseif (($kiloBytes / pow(1024, 2)) > 1) {
807 + return number_format_i18n(($kiloBytes / pow(1024, 2)), 0) . ' ' . __('GB', WP_ADMINIFY_TD);
808 + } elseif (($kiloBytes / 1024) > 1) {
809 + return number_format_i18n($kiloBytes / 1024, 0) . ' ' . __('MB', WP_ADMINIFY_TD);
810 + } elseif ($kiloBytes >= 0) {
811 + return number_format_i18n($kiloBytes / 1, 0) . ' ' . __('KB', WP_ADMINIFY_TD);
812 + } else {
813 + return __('Unknown', WP_ADMINIFY_TD);
814 + }
815 + }
816 +
817 + public function format_php_size($size)
818 + {
819 + if (!is_numeric($size)) {
820 + if (strpos($size, 'M') !== false) {
821 + $size = intval($size) * 1024 * 1024;
822 + } elseif (strpos($size, 'K') !== false) {
823 + $size = intval($size) * 1024;
824 + } elseif (strpos($size, 'G') !== false) {
825 + $size = intval($size) * 1024 * 1024 * 1024;
826 + }
827 + }
828 + return is_numeric($size) ? $this->format_filesize($size) : $size;
829 + }
674 830 }