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

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