PluginProbe
Disk Usage Insights / 1.3
Disk Usage Insights v1.3
trunk 1.0 1.10 1.11 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
disk-usage-insights / src / Frontend / ScanResults.php

ScanResults.php in Disk Usage Insights 1.3, at src/Frontend/ScanResults.php

138 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Mgleis\DiskUsageInsights\Frontend;
3
4 use Mgleis\DiskUsageInsights\Domain\DiskUsage;
5 use Mgleis\DiskUsageInsights\Frontend\Table;
6
7 class ScanResults {
8
9 public function execute() {
10
11 $root = \ABSPATH;
12
13 $d = new DiskUsage($root);
14 $res = $d->scan();
15 $totalSize = $d->calculateDirTotalSizes($res);
16 $d->calculateDirFileSizes($res);
17 $d->calculateDirFileCount($res);
18
19 echo '<div class="DUI-panel">';
20 echo '<div class="DUI-panel__content">';
21 echo sprintf("Root Directory: %s<br>\n", esc_html($root));
22 echo sprintf("Total Size: %s<br>\n", esc_html(number_format_i18n($totalSize)));
23 echo '</div>';
24 echo '</div>';
25
26 //
27 // Largest Files
28 //
29 $largestFiles = $d->calculateLargestFiles(20, $res);
30 $table = [];
31 foreach ($largestFiles as $file) {
32 $table[] = [
33 $file['abs'],
34 number_format_i18n($file['size']),
35 number_format_i18n(100 * $file['size'] / $totalSize, 2) . '%'
36 ];
37 }
38 (new Table(
39 'Largest Files',
40 ['Filename', 'Size', '%'],
41 ['', 'DUI-table__col--number', 'DUI-table__col--number']
42 ))->withPercentBar(2, 2)->withData($table)->output();
43
44
45 //
46 // Largest Folders (files only)
47 //
48 $largestFiles = $d->calculateLargestFolders(20, $res);
49 $table = [];
50 foreach ($largestFiles as $file) {
51 $table[] = [
52 $file['abs'],
53 number_format_i18n($file['fileSizes']),
54 number_format_i18n($file['fileCount']),
55 number_format_i18n(round($file['fileSizes'] / $file['fileCount'])),
56 number_format_i18n(100 * $file['fileSizes'] / $totalSize, 2) . '%'
57 ];
58 }
59 (new Table(
60 'Largest Folders (files only)',
61 ['Folder', 'File Sizes', 'File Count', 'Avg File Size', '%'],
62 ['', 'DUI-table__col--number', 'DUI-table__col--number', 'DUI-table__col--number', 'DUI-table__col--number']
63 ))->withPercentBar(4, 4)->withData($table)->output();
64
65
66 //
67 // Largest Folders (incl. sub folders)
68 //
69 $largestFiles = $d->calculateLargestFoldersRecursive(20, $res);
70 $table = [];
71 foreach ($largestFiles as $file) {
72 $table[] = [$file['abs'], number_format_i18n($file['totalSize'])];
73 }
74 (new Table(
75 'Largest Folders (incl. sub folders)',
76 ['Folder', 'Total Size'],
77 ['', 'DUI-table__col--number']
78 ))->withData($table)->output();
79
80
81 //
82 // Folders with most files
83 //
84 $files = $d->calculateFoldersWithMostFiles(20, $res);
85 $table = [];
86 foreach ($files as $file) {
87 $table[] = [
88 $file['abs'],
89 number_format_i18n($file['fileCount']),
90 number_format_i18n($file['fileSizes']),
91 number_format_i18n(round($file['fileSizes'] / $file['fileCount']))
92 ];
93 }
94 (new Table(
95 'Folders with most files',
96 ['Folder', 'File Count', 'File Size', 'Avg File Size'],
97 ['', 'DUI-table__col--number', 'DUI-table__col--number', 'DUI-table__col--number']
98 ))->withData($table)->output();
99
100
101 //
102 // Largest Directories within /wp-content/plugins
103 //
104 $pluginsDirRelative = substr(\WP_CONTENT_DIR . '/plugins', strlen($root));
105 $subres = $d->findSubDir($res, $pluginsDirRelative);
106
107 $largestFiles = $d->calculateLargestFilesFoldersFirstLevel(20, $subres);
108 $table = [];
109 foreach ($largestFiles as $file) {
110 $table[] = [$file['name'], number_format_i18n($file['size'])];
111 }
112 (new Table(
113 'Largest Plugin Folders',
114 ['Folder', 'Total Size'],
115 ['', 'DUI-table__col--number']
116 ))->withData($table)->output();
117
118 //
119 // Largest Directories within /wp-content/themes
120 //
121 $pluginsDirRelative = substr(\WP_CONTENT_DIR . '/themes', strlen($root));
122 $subres = $d->findSubDir($res, $pluginsDirRelative);
123
124 $largestFiles = $d->calculateLargestFilesFoldersFirstLevel(20, $subres);
125 $table = [];
126 foreach ($largestFiles as $file) {
127 $table[] = [$file['name'], number_format_i18n($file['size'])];
128 }
129 (new Table(
130 'Largest Theme Folders',
131 ['Folder', 'Total Size'],
132 ['', 'DUI-table__col--number']
133 ))->withData($table)->output();
134
135 }
136
137 }
138