PluginProbe
Elementor Website Builder – more than just a page builder / 3.30.0
Elementor Website Builder – more than just a page builder v3.30.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.30.0, at modules/system-info/module.php

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