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.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 4.1.17 All 164 releases
adminify / Inc / Classes / ServerInfo.php

ServerInfo.php in Adminify – White Label, Admin Menu Editor, Login Customizer 2.0.4, at Inc/Classes/ServerInfo.php

831 lines 23.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Classes;
4
5 use WPAdminify\Inc\Utils;
6
7 // no direct access allowed
8 if (!defined('ABSPATH')) exit;
9 /**
10 * WPAdminify
11 * Admin Menu: Server Info
12 *
13 * @author Jewel Theme <support@jeweltheme.com>
14 */
15
16 class ServerInfo
17 {
18
19 /**
20 * SERVER CPU LOAD
21 * Get the server CPU load in percentage.
22 */
23
24 public function get_server_cpu_load_percentage()
25 {
26
27 $result = -1;
28 $lines = null;
29
30 $os = '';
31 if (defined('PHP_OS')) {
32 $os = PHP_OS;
33 }
34
35 // Linux server
36 if ($os == 'Linux') {
37
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;
71
72 return (float) $result;
73 }
74
75 return 'N/A';
76 }
77
78
79
80
81 /**
82 *******************
83 * SERVER CPU CORE COUNT
84 *******************
85 *
86 * Get the count of available server CPU cores.
87 */
88
89 function check_core_count()
90 {
91
92 $cmd = "uname";
93
94 $OS = strtolower(trim(shell_exec($cmd)));
95
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 }
106
107 if (isset($cmd) && $cmd != '') {
108 $cpuCoreNo = intval(trim(shell_exec($cmd)));
109 }
110
111 return empty($cpuCoreNo) ? 1 : $cpuCoreNo;
112 }
113
114
115 /**
116 * Convert Memory Size
117 *
118 * @param [type] $size
119 *
120 * @return void
121 */
122 public function convert_memory_size($size)
123 {
124
125 $l = substr($size, -1);
126 $ret = substr($size, 0, -1);
127
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 }
140
141 return $ret;
142 }
143
144 /**
145 * Get Server/WP Memory Limit
146 */
147
148 public function get_wp_memory_limit()
149 {
150
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 }
155
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 }
159
160 return $memory_limit;
161 }
162
163 /**
164 * Get PHP Version
165 */
166 public function get_php_version()
167 {
168
169 $php_version = 'N/A';
170
171 if (function_exists('phpversion')) {
172 $php_version = phpversion();
173 }
174
175 if (defined('PHP_VERSION')) {
176 $php_version = PHP_VERSION;
177 }
178
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 }
182
183 return $php_version;
184 }
185
186 /**
187 * Get PHP Version Only
188 * */
189 public function get_php_version_lite()
190 {
191
192 $php_version = 'N/A';
193
194 if (function_exists('phpversion')) {
195 $php_version = phpversion();
196 }
197
198 if (defined('PHP_VERSION')) {
199 $php_version = PHP_VERSION;
200 }
201
202 return $php_version;
203 }
204
205 /**
206 * Get Curl Version
207 *
208 * @return void
209 */
210 public function get_cURL_version()
211 {
212
213 $curl_version = 'N/A';
214
215 if (function_exists('curl_version')) {
216 $curl_version = curl_version();
217 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
218 }
219
220 return $curl_version;
221 }
222
223 /**
224 * Get MySQL Version
225 *
226 * @return void
227 */
228 public function get_mysql_version()
229 {
230 global $wpdb;
231
232 // Short Version
233 // $db_version = $wpdb->db_server_info();
234
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 }
243
244
245 /**
246 * Get Get Database Software Name
247 *
248 * @return void
249 */
250 public function get_db_software()
251 {
252
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 }
262
263 return $db_software;
264 }
265
266 /**
267 * Get WP Table Prefix
268 */
269 public function get_table_prefix()
270 {
271
272 global $wpdb;
273
274 $prefix = array(
275 'tablePrefix' => $wpdb->prefix,
276 'tableBasePrefix' => $wpdb->base_prefix,
277 );
278
279 return $prefix;
280 }
281
282 /**
283 * Shell Enable/Disable
284 */
285 public function is_shell_enable()
286 {
287
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 }
300
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 }
329
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 }
344
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);
349
350 return ( $days * DAY_IN_SECONDS ) + ( $hours * HOUR_IN_SECONDS ) + ( $mins * MINUTE_IN_SECONDS ) + $secs;
351
352 }
353
354 return false;
355
356 }
357
358
359 /**
360 * Get WP Timezone
361 */
362
363 public function get_wp_timezone()
364 {
365
366 $timezone = get_option('timezone_string'); // Direct value
367
368 // Create a UTC+- zone if no timezone string exists
369 if (empty($timezone)) {
370 // Current offset
371 $current_offset = get_option('gmt_offset');
372
373 // Plus offset
374 $timezone = 'UTC+' . $current_offset;
375
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 }
383
384 // Normalize
385 $timezone = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $timezone);
386 }
387
388 return $timezone;
389 }
390
391 /**
392 * Get Server/WP Total RAM
393 *
394 * @return void
395 */
396 public function get_server_total_ram()
397 {
398
399 $os = '';
400 if (defined('PHP_OS')) {
401 $os = PHP_OS;
402 }
403
404 $result = 0;
405
406 // Linux server
407 if ($os == 'Linux') {
408
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);
420
421 return $result;
422 }
423
424 return 'N/A';
425 }
426
427
428 /**
429 * Get Server/WP Free RAM
430 */
431 public function get_server_free_ram()
432 {
433
434 $os = '';
435 if (defined('PHP_OS')) {
436 $os = PHP_OS;
437 }
438
439 $result = 0;
440
441 // Linux server
442 if ($os == 'Linux') {
443
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);
454
455 return $result;
456 }
457
458 return 'N/A';
459 }
460
461 /**
462 * Get Server/WP RAM Details
463 *
464 * @return void
465 */
466 public function get_server_ram_details()
467 {
468
469 $os = '';
470 if (defined('PHP_OS')) {
471 $os = PHP_OS;
472 }
473
474 $ram_data = '';
475 if ($os == 'Linux') {
476
477 foreach (file('/proc/meminfo') as $ri) {
478 $m[strtok($ri, ':')] = strtok('');
479 }
480
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);
486
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);
490
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 );
499
500 return $ram_data;
501 }
502
503 return 'N/A';
504 }
505
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;
512
513 if ($real_memory_usage) {
514 return $real_memory_usage;
515 }
516
517 return 'N/A';
518 }
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 }
531
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;
535
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;
541
542 if ($get_memory_usage != false && $get_memory_limit != false) {
543
544 // check memory limit is a numeric value
545 if (!is_numeric($memory_limit)) $memory_limit = 999;
546
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 );
558
559 return $wp_mem_data;
560 }
561
562 return 'N/A';
563 }
564
565 /**
566 * Server Memory Usage
567 */
568 public function get_server_memory_usage()
569 {
570
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;
576
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;
582
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 }
830 }
831