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

361 lines 8.9 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 if ( ! Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
122 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu_manager ) {
123 $this->register_menu( $admin_menu_manager );
124 }, Settings::ADMIN_MENU_PRIORITY + 30 );
125 }
126
127 add_action( 'wp_ajax_elementor_system_info_download_file', [ $this, 'download_file' ] );
128 }
129
130 /**
131 * Register admin menu.
132 *
133 * Add new Elementor system info admin menu.
134 *
135 * Fired by `admin_menu` action.
136 *
137 * @since 2.9.0
138 * @access private
139 */
140 private function register_menu( Admin_Menu_Manager $admin_menu ) {
141 $admin_menu->register( 'elementor-system-info', new System_Info_Menu_Item( $this ) );
142 }
143
144 /**
145 * Display page.
146 *
147 * Output the content for the main system info page.
148 *
149 * @since 2.9.0
150 * @access public
151 */
152 public function display_page() {
153 $reports_info = self::get_allowed_reports();
154
155 $reports = $this->load_reports( $reports_info );
156 ?>
157 <div id="elementor-system-info">
158 <div class="elementor-system-info-header">
159 <h3 class="wp-heading-inline"><?php echo esc_html__( 'System Info', 'elementor' ); ?></h3>
160 <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
161 <input type="hidden" name="action" value="elementor_system_info_download_file">
162 <input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>">
163 </form>
164 </div>
165 <div><?php $this->print_report( $reports, 'html' ); ?></div>
166 <h3><?php echo esc_html__( 'Copy & Paste Info', 'elementor' ); ?></h3>
167 <div id="elementor-system-info-raw">
168 <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>
169 <textarea id="elementor-system-info-raw-code" readonly>
170 <?php
171 $this->print_report( $reports, 'raw' );
172 ?>
173 </textarea>
174 <script>
175 var textarea = document.getElementById( 'elementor-system-info-raw-code' );
176 var selectRange = function() {
177 textarea.setSelectionRange( 0, textarea.value.length );
178 };
179 textarea.onfocus = textarea.onblur = textarea.onclick = selectRange;
180 textarea.onfocus();
181 </script>
182 </div>
183 <hr>
184 <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
185 <input type="hidden" name="action" value="elementor_system_info_download_file">
186 <input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>">
187 </form>
188 </div>
189 <?php
190 }
191
192 /**
193 * Download file.
194 *
195 * Download the reports files.
196 *
197 * Fired by `wp_ajax_elementor_system_info_download_file` action.
198 *
199 * @since 2.9.0
200 * @access public
201 */
202 public function download_file() {
203 if ( ! current_user_can( $this->capability ) ) {
204 wp_die( esc_html__( 'You don\'t have permissions to download this file', 'elementor' ) );
205 }
206
207 $reports_info = self::get_allowed_reports();
208 $reports = $this->load_reports( $reports_info );
209
210 $domain = parse_url( site_url(), PHP_URL_HOST );
211
212 header( 'Content-Type: text/plain' );
213 header( 'Content-Disposition:attachment; filename=system-info-' . $domain . '-' . gmdate( 'd-m-Y' ) . '.txt' );
214
215 $this->print_report( $reports );
216
217 die;
218 }
219
220 /**
221 * Get report class.
222 *
223 * Retrieve the class of the report for any given report type.
224 *
225 * @since 2.9.0
226 * @access public
227 *
228 * @param string $reporter_type The type of the report.
229 *
230 * @return string The class of the report.
231 */
232 public function get_reporter_class( $reporter_type ) {
233 return __NAMESPACE__ . '\Reporters\\' . ucfirst( $reporter_type );
234 }
235
236 /**
237 * Load reports.
238 *
239 * Retrieve the system info reports.
240 *
241 * @since 2.9.0
242 * @access public
243 *
244 * @param array $reports An array of system info reports.
245 *
246 * @return array An array of system info reports.
247 */
248 public function load_reports( $reports ) {
249 $result = [];
250
251 foreach ( $reports as $report_name => $report_info ) {
252 $reporter_params = [
253 'name' => $report_name,
254 ];
255
256 $reporter_params = array_merge( $reporter_params, $report_info );
257
258 $reporter = $this->create_reporter( $reporter_params );
259
260 if ( ! $reporter instanceof Base ) {
261 continue;
262 }
263
264 $result[ $report_name ] = [
265 'report' => $reporter,
266 'label' => $reporter->get_title(),
267 ];
268
269 if ( ! empty( $report_info['sub'] ) ) {
270 $result[ $report_name ]['sub'] = $this->load_reports( $report_info['sub'] );
271 }
272 }
273
274 return $result;
275 }
276
277 /**
278 * Create a report.
279 *
280 * Register a new report that will be displayed in Elementor system info page.
281 *
282 * @param array $properties Report properties.
283 *
284 * @return \WP_Error|false|Base Base instance if the report was created,
285 * False or WP_Error otherwise.
286 *@since 2.9.0
287 * @access public
288 *
289 */
290 public function create_reporter( array $properties ) {
291 $properties = Model_Helper::prepare_properties( $this->get_settings( 'reporter_properties' ), $properties );
292
293 $reporter_class = $properties['class_name'] ? $properties['class_name'] : $this->get_reporter_class( $properties['name'] );
294
295 $reporter = new $reporter_class( $properties );
296
297 if ( ! ( $reporter instanceof Base ) ) {
298 return new \WP_Error( 'Each reporter must to be an instance or sub-instance of `Base` class.' );
299 }
300
301 if ( ! $reporter->is_enabled() ) {
302 return false;
303 }
304
305 return $reporter;
306 }
307
308 /**
309 * Print report.
310 *
311 * Output the system info page reports using an output template.
312 *
313 * @since 2.9.0
314 * @access public
315 *
316 * @param array $reports An array of system info reports.
317 * @param string $template Output type from the templates folder. Available
318 * templates are `raw` and `html`. Default is `raw`.
319 */
320 public function print_report( $reports, $template = 'raw' ) {
321 static $tabs_count = 0;
322
323 $template_path = __DIR__ . '/templates/' . $template . '.php';
324
325 require $template_path;
326 }
327
328 /**
329 * Get allowed reports.
330 *
331 * Retrieve the available reports in Elementor system info page.
332 *
333 * @since 2.9.0
334 * @access public
335 * @static
336 *
337 * @return array Available reports in Elementor system info page.
338 */
339 public static function get_allowed_reports() {
340 do_action( 'elementor/system_info/get_allowed_reports' );
341
342 return self::$reports;
343 }
344
345 /**
346 * Add report.
347 *
348 * Register a new report to Elementor system info page.
349 *
350 * @since 2.9.0
351 * @access public
352 * @static
353 *
354 * @param string $report_name The name of the report.
355 * @param array $report_info Report info.
356 */
357 public static function add_report( $report_name, $report_info ) {
358 self::$reports[ $report_name ] = $report_info;
359 }
360 }
361