PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0
Elementor Website Builder – more than just a page builder v3.35.0
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / system-info / module.php

module.php in Elementor Website Builder – more than just a page builder 3.35.0, at modules/system-info/module.php

385 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\System_Info;
3
4 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 use Elementor\Core\Base\Module as BaseModule;
6 use Elementor\Modules\System_Info\Reporters\Base;
7 use Elementor\Modules\System_Info\Helpers\Model_Helper;
8 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
9 use Elementor\Modules\System_Info\AdminMenuItems\Editor_One_System_Info_Menu;
10 use Elementor\Modules\System_Info\AdminMenuItems\Editor_One_System_Menu;
11 use Elementor\Plugin;
12 use Elementor\Settings;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Elementor system info module.
20 *
21 * Elementor system info module handler class is responsible for registering and
22 * managing Elementor system info reports.
23 *
24 * @since 2.9.0
25 */
26 class Module extends BaseModule {
27
28 /**
29 * Get module name.
30 *
31 * Retrieve the system info module name.
32 *
33 * @since 2.9.0
34 * @access public
35 *
36 * @return string Module name.
37 */
38 public function get_name() {
39 return 'system-info';
40 }
41
42 /**
43 * Required user capabilities.
44 *
45 * Holds the user capabilities required to manage Elementor menus.
46 *
47 * @since 2.9.0
48 * @access private
49 *
50 * @var string
51 */
52 private $capability = 'manage_options';
53
54 /**
55 * Elementor system info reports.
56 *
57 * Holds an array of available reports in Elementor system info page.
58 *
59 * @since 2.9.0
60 * @access private
61 *
62 * @var array
63 */
64 private static $reports = [
65 'server' => [],
66 'wordpress' => [],
67 'theme' => [],
68 'user' => [],
69 'plugins' => [],
70 'network_plugins' => [],
71 'mu_plugins' => [],
72 ];
73
74 public function get_capability() {
75 return $this->capability;
76 }
77
78 /**
79 * Main system info page constructor.
80 *
81 * Initializing Elementor system info page.
82 *
83 * @since 2.9.0
84 * @access public
85 */
86 public function __construct() {
87 $this->add_actions();
88 }
89
90 /**
91 * Get default settings.
92 *
93 * Retrieve the default settings. Used to reset the report settings on
94 * initialization.
95 *
96 * @since 2.9.0
97 * @access protected
98 *
99 * @return array Default settings.
100 */
101 protected function get_init_settings() {
102 $settings = [];
103
104 $reporter_properties = Base::get_properties_keys();
105
106 array_push( $reporter_properties, 'category', 'name', 'class_name' );
107
108 $settings['reporter_properties'] = $reporter_properties;
109
110 $settings['reportFilePrefix'] = '';
111
112 return $settings;
113 }
114
115 /**
116 * Add actions.
117 *
118 * Register filters and actions for the main system info page.
119 *
120 * @since 2.9.0
121 * @access private
122 */
123 private function add_actions() {
124 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu_manager ) {
125 if ( ! $this->is_editor_one_active() ) {
126 $this->register_menu( $admin_menu_manager );
127 }
128 }, Settings::ADMIN_MENU_PRIORITY + 30 );
129
130 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
131 $this->register_editor_one_menu( $menu_data_provider );
132 } );
133
134 add_filter( 'elementor/editor-one/menu/items_to_hide_from_wp_menu', [ $this, 'add_items_to_hide' ] );
135 add_action( 'wp_ajax_elementor_system_info_download_file', [ $this, 'download_file' ] );
136 }
137
138 private function is_editor_one_active(): bool {
139 return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
140 }
141
142 public function add_items_to_hide( array $items ): array {
143 $items[] = 'elementor-system-info';
144 $items[] = 'elementor-element-manager';
145 $items[] = 'go_knowledge_base_site';
146
147 return $items;
148 }
149
150 /**
151 * Register admin menu.
152 *
153 * Add new Elementor system info admin menu.
154 *
155 * Fired by `admin_menu` action.
156 *
157 * @since 2.9.0
158 * @access private
159 */
160 private function register_menu( Admin_Menu_Manager $admin_menu ) {
161 $admin_menu->register( 'elementor-system-info', new System_Info_Menu_Item( $this ) );
162 }
163
164 private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
165 $menu_data_provider->register_menu( new Editor_One_System_Menu() );
166 $menu_data_provider->register_menu( new Editor_One_System_Info_Menu() );
167 }
168
169 /**
170 * Display page.
171 *
172 * Output the content for the main system info page.
173 *
174 * @since 2.9.0
175 * @access public
176 */
177 public function display_page() {
178 $reports_info = self::get_allowed_reports();
179
180 $reports = $this->load_reports( $reports_info );
181 ?>
182 <div id="elementor-system-info">
183 <div class="elementor-system-info-header">
184 <h3 class="wp-heading-inline"><?php echo esc_html__( 'System Info', 'elementor' ); ?></h3>
185 <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
186 <input type="hidden" name="action" value="elementor_system_info_download_file">
187 <input type="submit" data-id="elementor-system-info-download-file" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>">
188 </form>
189 </div>
190 <div><?php $this->print_report( $reports, 'html' ); ?></div>
191 <h3><?php echo esc_html__( 'Copy & Paste Info', 'elementor' ); ?></h3>
192 <div id="elementor-system-info-raw">
193 <label id="elementor-system-info-raw-code-label" for="elementor-system-info-raw-code"><?php echo esc_html__( 'You can copy the below info as simple text with Ctrl+C / Ctrl+V:', 'elementor' ); ?></label>
194 <textarea id="elementor-system-info-raw-code" readonly>
195 <?php
196 $this->print_report( $reports, 'raw' );
197 ?>
198 </textarea>
199 <script>
200 var textarea = document.getElementById( 'elementor-system-info-raw-code' );
201 var selectRange = function() {
202 textarea.setSelectionRange( 0, textarea.value.length );
203 };
204 textarea.onfocus = textarea.onblur = textarea.onclick = selectRange;
205 textarea.onfocus();
206 </script>
207 </div>
208 <hr>
209 <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
210 <input type="hidden" name="action" value="elementor_system_info_download_file">
211 <input type="submit" data-id="elementor-system-info-download-file" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>">
212 </form>
213 </div>
214 <?php
215 }
216
217 /**
218 * Download file.
219 *
220 * Download the reports files.
221 *
222 * Fired by `wp_ajax_elementor_system_info_download_file` action.
223 *
224 * @since 2.9.0
225 * @access public
226 */
227 public function download_file() {
228 if ( ! current_user_can( $this->capability ) ) {
229 wp_die( esc_html__( 'You do not have permission to download this file.', 'elementor' ) );
230 }
231
232 $reports_info = self::get_allowed_reports();
233 $reports = $this->load_reports( $reports_info );
234
235 $domain = parse_url( site_url(), PHP_URL_HOST );
236
237 header( 'Content-Type: text/plain' );
238 header( 'Content-Disposition:attachment; filename=system-info-' . $domain . '-' . gmdate( 'd-m-Y' ) . '.txt' );
239
240 $this->print_report( $reports );
241
242 die;
243 }
244
245 /**
246 * Get report class.
247 *
248 * Retrieve the class of the report for any given report type.
249 *
250 * @since 2.9.0
251 * @access public
252 *
253 * @param string $reporter_type The type of the report.
254 *
255 * @return string The class of the report.
256 */
257 public function get_reporter_class( $reporter_type ) {
258 return __NAMESPACE__ . '\Reporters\\' . ucfirst( $reporter_type );
259 }
260
261 /**
262 * Load reports.
263 *
264 * Retrieve the system info reports.
265 *
266 * @since 2.9.0
267 * @access public
268 *
269 * @param array $reports An array of system info reports.
270 *
271 * @return array An array of system info reports.
272 */
273 public function load_reports( $reports ) {
274 $result = [];
275
276 foreach ( $reports as $report_name => $report_info ) {
277 $reporter_params = [
278 'name' => $report_name,
279 ];
280
281 $reporter_params = array_merge( $reporter_params, $report_info );
282
283 $reporter = $this->create_reporter( $reporter_params );
284
285 if ( ! $reporter instanceof Base ) {
286 continue;
287 }
288
289 $result[ $report_name ] = [
290 'report' => $reporter,
291 'label' => $reporter->get_title(),
292 ];
293
294 if ( ! empty( $report_info['sub'] ) ) {
295 $result[ $report_name ]['sub'] = $this->load_reports( $report_info['sub'] );
296 }
297 }
298
299 return $result;
300 }
301
302 /**
303 * Create a report.
304 *
305 * Register a new report that will be displayed in Elementor system info page.
306 *
307 * @param array $properties Report properties.
308 *
309 * @return \WP_Error|false|Base Base instance if the report was created,
310 * False or WP_Error otherwise.
311 * @since 2.9.0
312 * @access public
313 */
314 public function create_reporter( array $properties ) {
315 $properties = Model_Helper::prepare_properties( $this->get_settings( 'reporter_properties' ), $properties );
316
317 $reporter_class = $properties['class_name'] ? $properties['class_name'] : $this->get_reporter_class( $properties['name'] );
318
319 $reporter = new $reporter_class( $properties );
320
321 if ( ! ( $reporter instanceof Base ) ) {
322 return new \WP_Error( 'Each reporter must to be an instance or sub-instance of `Base` class.' );
323 }
324
325 if ( ! $reporter->is_enabled() ) {
326 return false;
327 }
328
329 return $reporter;
330 }
331
332 /**
333 * Print report.
334 *
335 * Output the system info page reports using an output template.
336 *
337 * @since 2.9.0
338 * @access public
339 *
340 * @param array $reports An array of system info reports.
341 * @param string $template Output type from the templates folder. Available
342 * templates are `raw` and `html`. Default is `raw`.
343 */
344 public function print_report( $reports, $template = 'raw' ) {
345 static $tabs_count = 0;
346
347 $template_path = __DIR__ . '/templates/' . $template . '.php';
348
349 require $template_path;
350 }
351
352 /**
353 * Get allowed reports.
354 *
355 * Retrieve the available reports in Elementor system info page.
356 *
357 * @since 2.9.0
358 * @access public
359 * @static
360 *
361 * @return array Available reports in Elementor system info page.
362 */
363 public static function get_allowed_reports() {
364 do_action( 'elementor/system_info/get_allowed_reports' );
365
366 return self::$reports;
367 }
368
369 /**
370 * Add report.
371 *
372 * Register a new report to Elementor system info page.
373 *
374 * @since 2.9.0
375 * @access public
376 * @static
377 *
378 * @param string $report_name The name of the report.
379 * @param array $report_info Report info.
380 */
381 public static function add_report( $report_name, $report_info ) {
382 self::$reports[ $report_name ] = $report_info;
383 }
384 }
385