PluginProbe
Debug Log Viewer / 2.2.3
Debug Log Viewer v2.2.3
2.5 2.5.1 2.5.2 2.4 trunk 1.0.2 1.0.3 1.1 1.1.1 1.2 1.2.1 1.3 1.4 1.4.1 1.4.2 1.4.3 2.0.1 2.0.3 2.0.4 2.0.5 2.1 2.2.3
debug-log-viewer / admin / controllers / HooksController.php

HooksController.php in Debug Log Viewer 2.2.3, at admin/controllers/HooksController.php

203 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DebugLogViewer\Admin\Controllers;
4
5 use DebugLogViewer\Admin\Controllers\ReviewController;
6 use DebugLogViewer\Admin\Controllers\LogController;
7 use DebugLogViewer\Admin\Controllers\AlertController;
8 use DebugLogViewer\Admin\Controllers\ServiceController;
9 use DebugLogViewer\Admin\Translations\Phrases;
10 use DebugLogViewer\Admin\Models\LogModel;
11
12 if (!defined('ABSPATH')) {
13 exit;
14 // Exit if accessed directly
15 }
16
17 class HooksController
18 {
19
20 public $logController;
21 public $menuController;
22 public $freemiusController;
23 public $reviewController;
24 public $liveUpdatesController;
25 public $notificationController;
26 public $serviceController;
27 public $cleanupController;
28
29 public function __construct()
30 {
31 $this->logController = new LogController();
32 $this->menuController = new MenuController();
33 $this->freemiusController = new FreemiusController();
34 $this->reviewController = new ReviewController();
35 $this->liveUpdatesController = new LiveUpdatesController();
36 $this->notificationController = new AlertController();
37 $this->serviceController = new ServiceController();
38 $this->cleanupController = new CleanupController();
39 }
40
41 public function init()
42 {
43 // Load text domain for translations
44
45 $dbg_lv_index_file = plugin_dir_path(__DIR__) . 'debug-log-viewer.php';
46
47 // Include styles and scripts in Debug Log Viewer plugin's pages only
48 add_action('admin_enqueue_scripts', function ($hook_suffix) {
49 // Use $this instead of $this->hooksController
50 $this->enqueueAdminAssets($hook_suffix);
51 });
52
53 // Log actions
54 add_action('wp_ajax_dbg_lv_log_viewer_clear_log', function () {
55 $this->logController->clear();
56 });
57
58 add_action('wp_ajax_dbg_lv_log_viewer_download_log', function () {
59 $this->logController->download();
60 });
61
62 // Handle Alerts
63 add_action('wp_ajax_dbg_lv_change_log_viewer_alerts_status', function () {
64 $this->logController->changeNotificationsStatus();
65 });
66
67 add_action('wp_ajax_dbg_lv_get_current_user_email', function () {
68 $this->logController->getCurrentUserEmail();
69 });
70
71 // Mode: auto / manual
72 add_action('wp_ajax_dbg_lv_change_logs_update_mode', function () {
73 $this->logController->changeLogsUpdateMode();
74 });
75
76 // Datetime format: absolute / relative
77 add_action('wp_ajax_dbg_lv_change_datetime_format', function () {
78 $this->logController->changeDatetimeFormat();
79 });
80
81 // Timezone selection
82 add_action('wp_ajax_dbg_lv_change_timezone', function () {
83 $this->logController->changeTimezone();
84 });
85
86 // Group entries toggle
87 add_action('wp_ajax_dbg_lv_change_group_entries', function () {
88 $this->logController->changeGroupEntries();
89 });
90
91 // Save cleanup settings
92 add_action('wp_ajax_dbg_lv_save_cleanup_settings', function () {
93 $this->cleanupController->saveSettings();
94 });
95
96 // Button in template
97 add_action('wp_ajax_dbg_lv_first_run_enable_logging', function () {
98 $this->logController->firstRunEnableLogging();
99 });
100
101 // Debug constants
102 add_action('wp_ajax_dbg_lv_toggle_debug_mode', function () {
103 $this->logController->toggleDebugMode();
104 });
105 add_action('wp_ajax_dbg_lv_toggle_debug_scripts', function () {
106 $this->logController->toggleDebugScripts();
107 });
108 add_action('wp_ajax_dbg_lv_toggle_log_in_file', function () {
109 $this->logController->toggleLogInFile();
110 });
111 add_action('wp_ajax_dbg_lv_toggle_display_errors', function () {
112 $this->logController->toggleDisplayErrors();
113 });
114
115 // Live updates
116 add_action('wp_ajax_dbg_lv_run_live_updates', function () {
117 $this->liveUpdatesController->run();
118 });
119
120 add_action('wp_ajax_dbg_lv_is_debug_log_publicly_accessible', function () {
121 $this->logController->isDebugLogPubliclyAccessible();
122 });
123
124 add_action(LogController::SCHEDULE_MAIL_SEND, function ($args) {
125 $this->notificationController->sendLogsHandler($args);
126 });
127
128 add_action('wp_ajax_dbg_lv_get_alert_schedule', function () {
129 wp_send_json($this->notificationController->getNextScheduledTimeForAjax());
130 });
131
132 add_action('wp_ajax_dbg_lv_get_cleanup_schedule', function () {
133 wp_send_json($this->cleanupController->getNextScheduleTimeForAjax());
134 });
135
136 add_action('admin_init', function () {
137 $this->reviewController->handleUserAction();
138 });
139
140 // Activation / deactivation / uninstall hooks
141 register_activation_hook($dbg_lv_index_file, ['DebugLogViewer\Admin\Controllers\CleanupController', 'activate']);
142 register_deactivation_hook($dbg_lv_index_file, ['DebugLogViewer\Admin\Controllers\ServiceController', 'deactivateHandler']);
143 register_uninstall_hook($dbg_lv_index_file, ['DebugLogViewer\Admin\Controllers\ServiceController', 'uninstallHandler']);
144 }
145
146 public function enqueueAdminAssets($hook_suffix)
147 {
148 if (strpos($hook_suffix, 'debug-log-viewer') !== false) {
149 // Get the plugin version from the main plugin file
150 $main_plugin_file = plugin_dir_path(__DIR__) . '../debug-log-viewer.php';
151 $plugin_data = get_file_data($main_plugin_file, ['Version' => 'Version']);
152 $version = !empty($plugin_data['Version']) ? $plugin_data['Version'] : '1.0.0';
153
154 $logController = $this->logController;
155
156 // Enqueue Freemius checkout script
157 wp_enqueue_script('freemius_checkout', 'https://checkout.freemius.com/js/v1/', [], $version, true);
158
159 // Enqueue scripts
160 wp_enqueue_script('dbg_lv_app_js', plugins_url('../front/dist/bundle.js', __DIR__), ['jquery', 'freemius_checkout'], $version, true);
161 wp_enqueue_script('dbg_lv_font-awesome_js', plugins_url('../front/assets/vendor/js/font-awesome.js', __DIR__), [], $version, true);
162
163 // Get Freemius data
164 $is_premium = $checkout_url = false;
165 try {
166 $fs = dbg_lv();
167 if ($fs && is_object($fs)) {
168 $is_premium = $fs->is_premium();
169 $checkout_url = $fs->checkout_url();
170 }
171 } catch (\Exception $e) {
172 $is_premium = $checkout_url = false;
173 }
174
175 // Localize script
176 $group_entries_meta = get_user_meta(get_current_user_id(), LogModel::GROUP_ENTRIES_OPTION_NAME, true);
177 wp_localize_script('dbg_lv_app_js', 'dbg_lv_backend_data', [
178 'ajax_nonce' => wp_create_nonce('ajax_nonce'),
179 'phrases' => Phrases::getParsedContentPhrases(),
180 'log_updates_mode' => get_option(LogModel::LOG_UPDATES_MODE_OPTION_NAME),
181 'datetime_format' => get_option(LogModel::DATETIME_FORMAT_OPTION_NAME),
182 'group_entries' => $group_entries_meta !== '' ? $group_entries_meta : '1',
183 'log_updates_interval' => LogModel::LOG_UPDATES_INTERVAL,
184 'is_premium' => $is_premium,
185 'checkout_url' => $checkout_url
186 ]);
187
188 // Add Freemius configuration data
189 wp_localize_script('dbg_lv_app_js', 'dbg_lv_freemius_data', [
190 'is_premium' => $is_premium,
191 'checkout_url' => $checkout_url,
192 'product_id' => '17350',
193 'plan_id' => '29848',
194 'public_key' => 'pk_d456c712f16510d920c9f4ba4880a',
195 'image' => ''
196 ]);
197
198 // Enqueue styles
199 wp_enqueue_style('dbg_lv_datatables_css', plugins_url('../front/dist/bundle.css', __DIR__), [], $version);
200 }
201 }
202 }
203