PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.7
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.7
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.7, at Inc/Classes/ServerInfo.php

827 lines 23.2 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', 'adminify') . ' (' . (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', 'adminify'), (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', 'adminify'), esc_html($php_version), '<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener">' . __('WordPress Requirements', 'adminify') . '</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', 'adminify');
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', 'adminify');
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 } else {
333
334 // For *nix
335
336 if (in_array('shell_exec', $disabled_funcs)) {
337 $uptime_text = file_get_contents("/proc/uptime");
338 $uptime = substr($uptime_text, 0, strpos($uptime_text, " "));
339 } else {
340 $uptime = shell_exec("cut -d. -f1 /proc/uptime");
341 }
342
343 $days = floor($uptime / 60 / 60 / 24);
344 $hours = str_pad($uptime / 60 / 60 % 24, 2, "0", STR_PAD_LEFT);
345 $mins = str_pad($uptime / 60 % 60, 2, "0", STR_PAD_LEFT);
346 $secs = str_pad($uptime % 60, 2, "0", STR_PAD_LEFT);
347
348 return ($days * DAY_IN_SECONDS) + ($hours * HOUR_IN_SECONDS) + ($mins * MINUTE_IN_SECONDS) + $secs;
349 }
350
351 return false;
352 }
353
354
355 /**
356 * Get WP Timezone
357 */
358
359 public function get_wp_timezone()
360 {
361
362 $timezone = get_option('timezone_string'); // Direct value
363
364 // Create a UTC+- zone if no timezone string exists
365 if (empty($timezone)) {
366 // Current offset
367 $current_offset = get_option('gmt_offset');
368
369 // Plus offset
370 $timezone = 'UTC+' . $current_offset;
371
372 // No offset
373 if (0 == $current_offset) {
374 $timezone = 'UTC+0';
375 // Negative offset
376 } elseif ($current_offset < 0) {
377 $timezone = 'UTC' . $current_offset;
378 }
379
380 // Normalize
381 $timezone = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $timezone);
382 }
383
384 return $timezone;
385 }
386
387 /**
388 * Get Server/WP Total RAM
389 *
390 * @return void
391 */
392 public function get_server_total_ram()
393 {
394
395 $os = '';
396 if (defined('PHP_OS')) {
397 $os = PHP_OS;
398 }
399
400 $result = 0;
401
402 // Linux server
403 if ($os == 'Linux') {
404
405 $fh = fopen('/proc/meminfo', 'r');
406 while ($line = fgets($fh)) {
407 $pieces = array();
408 if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
409 $result = $pieces[1];
410 // KB to Bytes
411 $result = round($result / 1024 / 1024, 2);
412 break;
413 }
414 }
415 fclose($fh);
416
417 return $result;
418 }
419
420 return 'N/A';
421 }
422
423
424 /**
425 * Get Server/WP Free RAM
426 */
427 public function get_server_free_ram()
428 {
429
430 $os = '';
431 if (defined('PHP_OS')) {
432 $os = PHP_OS;
433 }
434
435 $result = 0;
436
437 // Linux server
438 if ($os == 'Linux') {
439
440 $fh = fopen('/proc/meminfo', 'r');
441 while ($line = fgets($fh)) {
442 $pieces = array();
443 if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
444 // KB to Bytes
445 $result = round($pieces[1] / 1024 / 1024, 2);
446 break;
447 }
448 }
449 fclose($fh);
450
451 return $result;
452 }
453
454 return 'N/A';
455 }
456
457 /**
458 * Get Server/WP RAM Details
459 *
460 * @return void
461 */
462 public function get_server_ram_details()
463 {
464
465 $os = '';
466 if (defined('PHP_OS')) {
467 $os = PHP_OS;
468 }
469
470 $ram_data = '';
471 if ($os == 'Linux') {
472
473 foreach (file('/proc/meminfo') as $ri) {
474 $m[strtok($ri, ':')] = strtok('');
475 }
476
477 $ram_total = round((int)$m['MemTotal'] / 1024 / 1024, 2);
478 $ram_available = round((int)$m['MemAvailable'] / 1024 / 1024, 2);
479 $ram_free = round((int)$m['MemFree'] / 1024 / 1024, 2);
480 $ram_buffers = round((int)$m['Buffers'] / 1024 / 1024, 2);
481 $ram_cached = round((int)$m['Cached'] / 1024 / 1024, 2);
482
483 $mem_kernel_app = round((100 - ($ram_buffers + $ram_cached + $ram_free) / $ram_total * 100), 2);
484 $mem_cached = round($ram_cached / $ram_total * 100, 2);
485 $mem_buffers = round($ram_buffers / $ram_total * 100, 2);
486
487 $ram_data = array(
488 'MemTotal' => $ram_total,
489 'MemAvailable' => $ram_available,
490 'MemFree' => $ram_free,
491 'Buffers' => $ram_buffers,
492 'Cached' => $ram_cached,
493 'MemUsagePercentage' => round($mem_kernel_app + $mem_buffers + $mem_cached, 2), // Physical Memory
494 );
495
496 return $ram_data;
497 }
498
499 return 'N/A';
500 }
501
502 /**
503 * Get Real Server Memory Usage
504 */
505 public function get_real_memory_usage()
506 {
507 $real_memory_usage = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage(true)) : 0;
508
509 if ($real_memory_usage) {
510 return $real_memory_usage;
511 }
512
513 return 'N/A';
514 }
515
516 /**
517 * WP Memory Usage
518 */
519 public function get_wp_memory_usage()
520 {
521 // Get WP Memory Limit
522 $get_memory_limit = WP_MEMORY_LIMIT;
523 if ((int)WP_MEMORY_LIMIT > (int)@ini_get('memory_limit')) {
524 // WP Limit can't be greater than Server Limiit
525 $get_memory_limit = @ini_get('memory_limit');
526 }
527
528 $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
529 $memory_limit_format = size_format($memory_limit_convert);
530 $memory_limit = $memory_limit_convert;
531
532 // Get Real Memory Usage
533 $get_memory_usage = $this->get_real_memory_usage();
534 $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
535 $memory_usage_format = $memory_usage_convert . 'MB';
536 $memory_usage = $get_memory_usage;
537
538 if ($get_memory_usage != false && $get_memory_limit != false) {
539
540 // check memory limit is a numeric value
541 if (!is_numeric($memory_limit)) $memory_limit = 999;
542
543 $wp_mem_data = array(
544 'MemLimit' => $memory_limit,
545 'MemLimitGet' => $get_memory_limit,
546 'MemLimitConvert' => $memory_limit_convert,
547 'MemLimitFormat' => $memory_limit_format,
548 'MemUsage' => $memory_usage,
549 'MemUsageGet' => $get_memory_usage,
550 'MemUsageConvert' => $memory_usage_convert,
551 'MemUsageFormat' => $memory_usage_format,
552 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
553 );
554
555 return $wp_mem_data;
556 }
557
558 return 'N/A';
559 }
560
561 /**
562 * Server Memory Usage
563 */
564 public function get_server_memory_usage()
565 {
566
567 // Get Server Memory Limit
568 $get_memory_limit = @ini_get('memory_limit');
569 $memory_limit_convert = $this->convert_memory_size($get_memory_limit);
570 $memory_limit_format = size_format($memory_limit_convert);
571 $memory_limit = $memory_limit_convert;
572
573 // Get Real Memory Usage
574 $get_memory_usage = $this->get_real_memory_usage();
575 $memory_usage_convert = round($get_memory_usage / 1024 / 1024);
576 $memory_usage_format = $memory_usage_convert . ' MB';
577 $memory_usage = $get_memory_usage;
578
579 if ($get_memory_usage != false && $get_memory_limit != false) {
580
581 // check memory limit is a numeric value
582 if (!is_numeric($memory_limit)) $memory_limit = 999;
583
584 $php_mem_data = array(
585 'MemLimit' => $memory_limit,
586 'MemLimitGet' => $get_memory_limit,
587 'MemLimitConvert' => $memory_limit_convert,
588 'MemLimitFormat' => $memory_limit_format,
589 'MemUsage' => $memory_usage,
590 'MemUsageGet' => $get_memory_usage,
591 'MemUsageConvert' => $memory_usage_convert,
592 'MemUsageFormat' => $memory_usage_format,
593 'MemUsageCalc' => round($memory_usage / $memory_limit * 100, 0),
594 );
595
596 return $php_mem_data;
597 }
598
599 return 'N/A';
600 }
601
602
603 public static function wp_memory_usage_percentage()
604 {
605 $memory_usage = (new ServerInfo)->get_wp_memory_usage();
606 $memory_usage_percentage = $memory_usage['MemUsageCalc'];
607 return $memory_usage_percentage;
608 }
609
610
611
612
613 /**
614 * Get Server Disk Size
615 */
616
617 public function get_server_disk_size($path = '/')
618 {
619
620 $os = '';
621 if (defined('PHP_OS')) {
622 $os = PHP_OS;
623 }
624
625 // Linux server
626 if ($os == 'Linux') {
627
628 $result = array();
629 $result['size'] = 0;
630 $result['free'] = 0;
631 $result['used'] = 0;
632
633 $lines = null;
634 exec(sprintf('df /P %s', $path), $lines);
635
636 foreach ($lines as $index => $line) {
637 if ($index != 1) {
638 continue;
639 }
640 $values = preg_split('/\s{1,}/', $line);
641 $result['size'] = round($values[1] / 1024 / 1024, 2);
642 $result['free'] = round($values[3] / 1024 / 1024, 2);
643 $result['used'] = round($values[2] / 1024 / 1024, 2);
644 $result['usage'] = round($result['used'] / $result['size'] * 100, 2);
645 break;
646 }
647
648 return $result;
649 }
650
651 return 'N/A';
652 }
653
654
655
656 /**
657 * CPU Count
658 */
659 public function check_cpu_count()
660 {
661
662 if ($this->is_shell_enable()) {
663 $cpu_count = shell_exec('cat /proc/cpuinfo |grep "physical id" | sort | uniq | wc -l');
664 set_transient('wphave_admin_cpu_count', $cpu_count, WEEK_IN_SECONDS);
665 } else {
666 $cpu_count = 'N/A';
667 }
668
669 return $cpu_count;
670 }
671
672 /**
673 * CPU Load Average
674 *
675 * @return void
676 */
677
678 public function get_cpu_load_average()
679 {
680 $load = 'N/A';
681
682 // Check via PHP function
683 $avg = function_exists('sys_getloadavg') ? sys_getloadavg() : false;
684 if (!empty($avg) && is_array($avg) && 3 == count($avg)) {
685 $load = implode(', ', $avg);
686 }
687
688 return $load;
689 }
690
691 /** CPU Load */
692 public function get_cpu_load()
693 {
694 $cpu_load = 'N/A';
695 if ($this->is_shell_enable()) {
696 $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`))"));
697 }
698 return $cpu_load;
699 }
700
701 /**
702 * CPU Core Count
703 */
704
705 public function get_cpu_core_count()
706 {
707
708 $cmd = "uname";
709
710 $OS = strtolower(trim(shell_exec($cmd)));
711
712 switch ($OS) {
713 case ('linux'):
714 $cmd = "cat /proc/cpuinfo | grep processor | wc -l";
715 break;
716 case ('freebsd'):
717 $cmd = "sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2";
718 break;
719 default:
720 unset($cmd);
721 }
722
723 if (isset($cmd) && $cmd != '') {
724 $cpuCoreNo = intval(trim(shell_exec($cmd)));
725 }
726
727 return empty($cpuCoreNo) ? 1 : $cpuCoreNo;
728 }
729
730 /**
731 * Get IP Address
732 *
733 * @return void
734 */
735 public function get_ip_address()
736 {
737 // Get ip address
738 $ip_address = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
739 if (!$ip_address) {
740 $ip_address = isset($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR'] : '';
741 }
742 return $ip_address;
743 }
744
745 /**
746 * Get WordPress Version
747 *
748 * @return void
749 */
750 public function get_wp_version()
751 {
752 global $wp_version;
753 return $wp_version;
754 }
755
756
757
758 public function check_limit()
759 {
760 $memory_limit = ini_get('memory_limit');
761 if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
762 if ($matches[2] == 'G') {
763 $memory_limit = $matches[1] . ' ' . 'GB'; // nnnG -> nnn GB
764 } else if ($matches[2] == 'M') {
765 $memory_limit = $matches[1] . ' ' . 'MB'; // nnnM -> nnn MB
766 } else if ($matches[2] == 'K') {
767 $memory_limit = $matches[1] . ' ' . 'KB'; // nnnK -> nnn KB
768 } else if ($matches[2] == 'T') {
769 $memory_limit = $matches[1] . ' ' . 'TB'; // nnnT -> nnn TB
770 } else if ($matches[2] == 'P') {
771 $memory_limit = $matches[1] . ' ' . 'PB'; // nnnP -> nnn PB
772 }
773 }
774 return $memory_limit;
775 }
776
777 public function format_filesize($bytes)
778 {
779 if (($bytes / pow(1024, 5)) > 1) {
780 return number_format_i18n(($bytes / pow(1024, 5)), 0) . ' ' . __('PB', 'adminify');
781 } elseif (($bytes / pow(1024, 4)) > 1) {
782 return number_format_i18n(($bytes / pow(1024, 4)), 0) . ' ' . __('TB', 'adminify');
783 } elseif (($bytes / pow(1024, 3)) > 1) {
784 return number_format_i18n(($bytes / pow(1024, 3)), 0) . ' ' . __('GB', 'adminify');
785 } elseif (($bytes / pow(1024, 2)) > 1) {
786 return number_format_i18n(($bytes / pow(1024, 2)), 0) . ' ' . __('MB', 'adminify');
787 } elseif ($bytes / 1024 > 1) {
788 return number_format_i18n($bytes / 1024, 0) . ' ' . __('KB', 'adminify');
789 } elseif ($bytes >= 0) {
790 return number_format_i18n($bytes, 0) . ' ' . __('bytes', 'adminify');
791 } else {
792 return __('Unknown', 'adminify');
793 }
794 }
795
796 public function format_filesize_kB($kiloBytes)
797 {
798 if (($kiloBytes / pow(1024, 4)) > 1) {
799 return number_format_i18n(($kiloBytes / pow(1024, 4)), 0) . ' ' . __('PB', 'adminify');
800 } elseif (($kiloBytes / pow(1024, 3)) > 1) {
801 return number_format_i18n(($kiloBytes / pow(1024, 3)), 0) . ' ' . __('TB', 'adminify');
802 } elseif (($kiloBytes / pow(1024, 2)) > 1) {
803 return number_format_i18n(($kiloBytes / pow(1024, 2)), 0) . ' ' . __('GB', 'adminify');
804 } elseif (($kiloBytes / 1024) > 1) {
805 return number_format_i18n($kiloBytes / 1024, 0) . ' ' . __('MB', 'adminify');
806 } elseif ($kiloBytes >= 0) {
807 return number_format_i18n($kiloBytes / 1, 0) . ' ' . __('KB', 'adminify');
808 } else {
809 return __('Unknown', 'adminify');
810 }
811 }
812
813 public function format_php_size($size)
814 {
815 if (!is_numeric($size)) {
816 if (strpos($size, 'M') !== false) {
817 $size = intval($size) * 1024 * 1024;
818 } elseif (strpos($size, 'K') !== false) {
819 $size = intval($size) * 1024;
820 } elseif (strpos($size, 'G') !== false) {
821 $size = intval($size) * 1024 * 1024 * 1024;
822 }
823 }
824 return is_numeric($size) ? $this->format_filesize($size) : $size;
825 }
826 }
827