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

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