| @@ -2,18 +2,16 @@ | ||
| 2 | 2 | namespace Mgleis\DiskUsageInsights; |
| 3 | 3 | |
| 4 | 4 | use Mgleis\DiskUsageInsights\Frontend\Controller\DeleteSnapshotController; |
| 5 | 5 | use Mgleis\DiskUsageInsights\Frontend\Controller\IndexController; |
| 6 | +use Mgleis\DiskUsageInsights\Frontend\Controller\ResultsController; | |
| 6 | 7 | use Mgleis\DiskUsageInsights\Frontend\Controller\ScanController; |
| 7 | 8 | use Mgleis\DiskUsageInsights\Frontend\Controller\ScanStatusController; |
| 8 | 9 | use Mgleis\DiskUsageInsights\Frontend\Controller\ScanWorkerController; |
| 9 | -use Mgleis\DiskUsageInsights\Frontend\Controller\ShowResultsController; | |
| 10 | -use Mgleis\DiskUsageInsights\Frontend\Controller\ShowResultsTableController; | |
| 11 | 10 | use Mgleis\DiskUsageInsights\Frontend\Controller\ShowSnapshotsController; |
| 12 | 11 | |
| 13 | 12 | class Plugin { |
| 14 | 13 | |
| 15 | - const TITLE = 'Disk Usage Insights'; | |
| 16 | 14 | const NONCE = 'disk_usage_insights'; |
| 17 | 15 | /** @var string */ |
| 18 | 16 | private $version = ''; |
| 19 | 17 | |
| @@ -36,10 +34,10 @@ | ||
| 36 | 34 | // Add to Tools menue |
| 37 | 35 | add_action('admin_menu', function () { |
| 38 | 36 | add_submenu_page( |
| 39 | 37 | 'tools.php', |
| 40 | - self::TITLE, | |
| 41 | - self::TITLE, | |
| 38 | + 'Disk Usage Insights', | |
| 39 | + 'Disk Usage Insights', | |
| 42 | 40 | 'administrator', |
| 43 | 41 | 'disk-usage-insights', |
| 44 | 42 | [$this, 'index'] |
| 45 | 43 | ); |
| @@ -51,31 +49,15 @@ | ||
| 51 | 49 | // Add JavaScript libs + CSS |
| 52 | 50 | add_action('admin_enqueue_scripts', [$this, 'addScripts']); |
| 53 | 51 | |
| 54 | 52 | // Add AJAX |
| 55 | - add_action('wp_ajax_dui_scan', $this->wrapErrors(function() { (new ScanController())->scan(); })); | |
| 56 | - add_action('wp_ajax_dui_worker', $this->wrapErrors(function() { (new ScanWorkerController())->worker(); })); | |
| 57 | - add_action('wp_ajax_dui_status', $this->wrapErrors(function() { (new ScanStatusController())->status(); })); | |
| 58 | - add_action('wp_ajax_dui_delete_snapshot', $this->wrapErrors(function() { (new DeleteSnapshotController())->delete(); })); | |
| 59 | - add_action('wp_ajax_dui_list_snapshots', $this->wrapErrors(function() { (new ShowSnapshotsController())->execute(); })); | |
| 60 | - add_action('wp_ajax_dui_results_table', $this->wrapErrors(function() { (new ShowResultsTableController())->execute(); })); | |
| 53 | + add_action('wp_ajax_dui_scan', function() { (new ScanController())->scan(); }); | |
| 54 | + add_action('wp_ajax_dui_worker', function() { (new ScanWorkerController())->worker(); }); | |
| 55 | + add_action('wp_ajax_dui_status', function() { (new ScanStatusController())->status(); }); | |
| 56 | + add_action('wp_ajax_dui_delete_snapshot', function() { (new DeleteSnapshotController())->delete(); }); | |
| 57 | + add_action('wp_ajax_dui_list_snapshots', function() { (new ShowSnapshotsController())->execute(); }); | |
| 61 | 58 | } |
| 62 | 59 | |
| 63 | - public function wrapErrors(callable $fn) { | |
| 64 | - return function() use ($fn) { | |
| 65 | - try { | |
| 66 | - return $fn(); | |
| 67 | - } catch (\Throwable $e) { | |
| 68 | - status_header(500, 'Interner Fehler'); | |
| 69 | - //echo 'Fehler: Interner Serverfehler.'; | |
| 70 | - echo "\n\n"; | |
| 71 | - echo esc_html($e->getMessage()); | |
| 72 | - echo esc_html($e->getTraceAsString()); | |
| 73 | - wp_die(); | |
| 74 | - } | |
| 75 | - }; | |
| 76 | - } | |
| 77 | - | |
| 78 | 60 | public function addScripts($hook_suffix) { |
| 79 | 61 | if ($hook_suffix != 'tools_page_disk-usage-insights') { |
| 80 | 62 | return; |
| 81 | 63 | } |
| @@ -104,12 +86,12 @@ | ||
| 104 | 86 | $admin_bar->add_menu(array( |
| 105 | 87 | 'id' => 'menu-id', |
| 106 | 88 | 'parent' => null, |
| 107 | 89 | 'group' => null, |
| 108 | - 'title' => '<img src="' . WpHelper::getPluginUrl() . '/res/pie.svg" style="margin-top:5px; width:20px" alt="'. self::TITLE .'">', | |
| 90 | + 'title' => '<img src="' . WpHelper::getPluginUrl() . '/res/pie.svg" style="margin-top:5px; width:20px" alt="Disk Usage Insights">', | |
| 109 | 91 | 'href' => admin_url('tools.php?page=disk-usage-insights'), |
| 110 | 92 | 'meta' => [ |
| 111 | - 'title' => self::TITLE | |
| 93 | + 'title' => 'Disk Usage Insights' | |
| 112 | 94 | ] |
| 113 | 95 | )); |
| 114 | 96 | } |
| 115 | 97 | |
| @@ -116,9 +98,9 @@ | ||
| 116 | 98 | public function index() { |
| 117 | 99 | if (!isset($_GET['snapshot'])) { |
| 118 | 100 | return (new IndexController())->execute(); |
| 119 | 101 | } else { |
| 120 | - return (new ShowResultsController())->execute(); | |
| 102 | + return (new ResultsController())->execute(); | |
| 121 | 103 | } |
| 122 | 104 | } |
| 123 | 105 | |
| 124 | 106 | } |