| @@ -1,16 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\System_Info; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 6 | -use Elementor\Modules\System_Info\AdminMenuItems\Editor_One_System_Info_Menu; | |
| 7 | -use Elementor\Modules\System_Info\AdminMenuItems\Editor_One_System_Menu; | |
| 5 | +use Elementor\Modules\System_Info\Reporters\Base; | |
| 8 | 6 | use Elementor\Modules\System_Info\Helpers\Model_Helper; |
| 9 | -use Elementor\Modules\System_Info\Reporters\Base; | |
| 10 | -use Elementor\Modules\System_Info\Rest\Rest_Api; | |
| 11 | -use Elementor\Plugin; | |
| 12 | -use Elementor\Settings; | |
| 13 | 7 | |
| 14 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | 9 | exit; // Exit if accessed directly. |
| 16 | 10 | } |
| @@ -23,9 +17,8 @@ | ||
| 23 | 17 | * |
| 24 | 18 | * @since 2.9.0 |
| 25 | 19 | */ |
| 26 | 20 | class Module extends BaseModule { |
| 27 | - | |
| 28 | 21 | /** |
| 29 | 22 | * Get module name. |
| 30 | 23 | * |
| 31 | 24 | * Retrieve the system info module name. |
| @@ -70,12 +63,8 @@ | ||
| 70 | 63 | 'network_plugins' => [], |
| 71 | 64 | 'mu_plugins' => [], |
| 72 | 65 | ]; |
| 73 | 66 | |
| 74 | - public function get_capability() { | |
| 75 | - return $this->capability; | |
| 76 | - } | |
| 77 | - | |
| 78 | 67 | /** |
| 79 | 68 | * Main system info page constructor. |
| 80 | 69 | * |
| 81 | 70 | * Initializing Elementor system info page. |
| @@ -120,56 +109,35 @@ | ||
| 120 | 109 | * @since 2.9.0 |
| 121 | 110 | * @access private |
| 122 | 111 | */ |
| 123 | 112 | private function add_actions() { |
| 124 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 125 | - $this->register_editor_one_menu( $menu_data_provider ); | |
| 126 | - } ); | |
| 127 | - | |
| 113 | + add_action( 'admin_menu', [ $this, 'register_menu' ], 500 ); | |
| 128 | 114 | add_action( 'wp_ajax_elementor_system_info_download_file', [ $this, 'download_file' ] ); |
| 129 | - add_action( 'rest_api_init', [ $this, 'register_rest_routes' ] ); | |
| 130 | 115 | } |
| 131 | 116 | |
| 132 | - public function register_rest_routes(): void { | |
| 133 | - ( new Rest_Api() )->register_routes(); | |
| 134 | - } | |
| 117 | + /** | |
| 118 | + * Register admin menu. | |
| 119 | + * | |
| 120 | + * Add new Elementor system info admin menu. | |
| 121 | + * | |
| 122 | + * Fired by `admin_menu` action. | |
| 123 | + * | |
| 124 | + * @since 2.9.0 | |
| 125 | + * @access public | |
| 126 | + */ | |
| 127 | + public function register_menu() { | |
| 128 | + $system_info_text = esc_html__( 'System Info', 'elementor' ); | |
| 135 | 129 | |
| 136 | - public function get_reports_data(): array { | |
| 137 | - $reports = $this->load_reports( self::get_allowed_reports() ); | |
| 138 | - | |
| 139 | - return $this->build_reports_data( $reports ); | |
| 130 | + add_submenu_page( | |
| 131 | + 'elementor', | |
| 132 | + $system_info_text, | |
| 133 | + $system_info_text, | |
| 134 | + $this->capability, | |
| 135 | + 'elementor-system-info', | |
| 136 | + [ $this, 'display_page' ] | |
| 137 | + ); | |
| 140 | 138 | } |
| 141 | 139 | |
| 142 | - private function build_reports_data( array $reports ): array { | |
| 143 | - $data = []; | |
| 144 | - | |
| 145 | - foreach ( $reports as $report_name => $report_details ) { | |
| 146 | - $report = $report_details['report']->get_report(); | |
| 147 | - | |
| 148 | - if ( is_wp_error( $report ) ) { | |
| 149 | - continue; | |
| 150 | - } | |
| 151 | - | |
| 152 | - $report_data = [ | |
| 153 | - 'label' => $report_details['label'], | |
| 154 | - 'report' => $report, | |
| 155 | - ]; | |
| 156 | - | |
| 157 | - if ( ! empty( $report_details['sub'] ) ) { | |
| 158 | - $report_data['sub'] = $this->build_reports_data( $report_details['sub'] ); | |
| 159 | - } | |
| 160 | - | |
| 161 | - $data[ $report_name ] = $report_data; | |
| 162 | - } | |
| 163 | - | |
| 164 | - return $data; | |
| 165 | - } | |
| 166 | - | |
| 167 | - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 168 | - $menu_data_provider->register_menu( new Editor_One_System_Menu() ); | |
| 169 | - $menu_data_provider->register_menu( new Editor_One_System_Info_Menu() ); | |
| 170 | - } | |
| 171 | - | |
| 172 | 140 | /** |
| 173 | 141 | * Display page. |
| 174 | 142 | * |
| 175 | 143 | * Output the content for the main system info page. |
| @@ -179,18 +147,15 @@ | ||
| 179 | 147 | */ |
| 180 | 148 | public function display_page() { |
| 181 | 149 | $reports_info = self::get_allowed_reports(); |
| 182 | 150 | |
| 183 | - $reports = $this->load_reports( $reports_info ); | |
| 151 | + $reports = $this->load_reports( $reports_info, 'html' ); | |
| 152 | + | |
| 153 | + $raw_reports = $this->load_reports( $reports_info, 'raw' ); | |
| 154 | + | |
| 184 | 155 | ?> |
| 185 | 156 | <div id="elementor-system-info"> |
| 186 | - <div class="elementor-system-info-header"> | |
| 187 | - <h3 class="wp-heading-inline"><?php echo esc_html__( 'System Info', 'elementor' ); ?></h3> | |
| 188 | - <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> | |
| 189 | - <input type="hidden" name="action" value="elementor_system_info_download_file"> | |
| 190 | - <input type="submit" data-id="elementor-system-info-download-file" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>"> | |
| 191 | - </form> | |
| 192 | - </div> | |
| 157 | + <h3 class="wp-heading-inline"><?php echo esc_html__( 'System Info', 'elementor' ); ?></h3> | |
| 193 | 158 | <div><?php $this->print_report( $reports, 'html' ); ?></div> |
| 194 | 159 | <h3><?php echo esc_html__( 'Copy & Paste Info', 'elementor' ); ?></h3> |
| 195 | 160 | <div id="elementor-system-info-raw"> |
| 196 | 161 | <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> |
| @@ -195,9 +160,11 @@ | ||
| 195 | 160 | <div id="elementor-system-info-raw"> |
| 196 | 161 | <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> |
| 197 | 162 | <textarea id="elementor-system-info-raw-code" readonly> |
| 198 | 163 | <?php |
| 199 | - $this->print_report( $reports, 'raw' ); | |
| 164 | + unset( $raw_reports['wordpress']['report']['admin_email'] ); | |
| 165 | + | |
| 166 | + $this->print_report( $raw_reports, 'raw' ); | |
| 200 | 167 | ?> |
| 201 | 168 | </textarea> |
| 202 | 169 | <script> |
| 203 | 170 | var textarea = document.getElementById( 'elementor-system-info-raw-code' ); |
| @@ -210,9 +177,9 @@ | ||
| 210 | 177 | </div> |
| 211 | 178 | <hr> |
| 212 | 179 | <form action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> |
| 213 | 180 | <input type="hidden" name="action" value="elementor_system_info_download_file"> |
| 214 | - <input type="submit" data-id="elementor-system-info-download-file" class="button button-primary" value="<?php echo esc_attr__( 'Download System Info', 'elementor' ); ?>"> | |
| 181 | + <input type="submit" class="button button-primary" value="<?php echo esc_html__( 'Download System Info', 'elementor' ); ?>"> | |
| 215 | 182 | </form> |
| 216 | 183 | </div> |
| 217 | 184 | <?php |
| 218 | 185 | } |
| @@ -228,13 +195,13 @@ | ||
| 228 | 195 | * @access public |
| 229 | 196 | */ |
| 230 | 197 | public function download_file() { |
| 231 | 198 | if ( ! current_user_can( $this->capability ) ) { |
| 232 | - wp_die( esc_html__( 'You do not have permission to download this file.', 'elementor' ) ); | |
| 199 | + wp_die( esc_html__( 'You don\'t have permissions to download this file', 'elementor' ) ); | |
| 233 | 200 | } |
| 234 | 201 | |
| 235 | 202 | $reports_info = self::get_allowed_reports(); |
| 236 | - $reports = $this->load_reports( $reports_info ); | |
| 203 | + $reports = $this->load_reports( $reports_info, 'raw' ); | |
| 237 | 204 | |
| 238 | 205 | $domain = parse_url( site_url(), PHP_URL_HOST ); |
| 239 | 206 | |
| 240 | 207 | header( 'Content-Type: text/plain' ); |
| @@ -269,17 +236,19 @@ | ||
| 269 | 236 | * @since 2.9.0 |
| 270 | 237 | * @access public |
| 271 | 238 | * |
| 272 | 239 | * @param array $reports An array of system info reports. |
| 240 | + * @param string $format - possible values: 'raw' or empty string, meaning 'html' | |
| 273 | 241 | * |
| 274 | 242 | * @return array An array of system info reports. |
| 275 | 243 | */ |
| 276 | - public function load_reports( $reports ) { | |
| 244 | + public function load_reports( $reports, $format = '' ) { | |
| 277 | 245 | $result = []; |
| 278 | 246 | |
| 279 | 247 | foreach ( $reports as $report_name => $report_info ) { |
| 280 | 248 | $reporter_params = [ |
| 281 | 249 | 'name' => $report_name, |
| 250 | + 'format' => $format, | |
| 282 | 251 | ]; |
| 283 | 252 | |
| 284 | 253 | $reporter_params = array_merge( $reporter_params, $report_info ); |
| 285 | 254 | |
| @@ -289,9 +258,9 @@ | ||
| 289 | 258 | continue; |
| 290 | 259 | } |
| 291 | 260 | |
| 292 | 261 | $result[ $report_name ] = [ |
| 293 | - 'report' => $reporter, | |
| 262 | + 'report' => $reporter->get_report( $format ), | |
| 294 | 263 | 'label' => $reporter->get_title(), |
| 295 | 264 | ]; |
| 296 | 265 | |
| 297 | 266 | if ( ! empty( $report_info['sub'] ) ) { |
| @@ -310,10 +279,11 @@ | ||
| 310 | 279 | * @param array $properties Report properties. |
| 311 | 280 | * |
| 312 | 281 | * @return \WP_Error|false|Base Base instance if the report was created, |
| 313 | 282 | * False or WP_Error otherwise. |
| 314 | - * @since 2.9.0 | |
| 283 | + *@since 2.9.0 | |
| 315 | 284 | * @access public |
| 285 | + * | |
| 316 | 286 | */ |
| 317 | 287 | public function create_reporter( array $properties ) { |
| 318 | 288 | $properties = Model_Helper::prepare_properties( $this->get_settings( 'reporter_properties' ), $properties ); |
| 319 | 289 | |
| @@ -346,8 +316,15 @@ | ||
| 346 | 316 | */ |
| 347 | 317 | public function print_report( $reports, $template = 'raw' ) { |
| 348 | 318 | static $tabs_count = 0; |
| 349 | 319 | |
| 320 | + static $required_plugins_properties = [ | |
| 321 | + 'Name', | |
| 322 | + 'Version', | |
| 323 | + 'URL', | |
| 324 | + 'Author', | |
| 325 | + ]; | |
| 326 | + | |
| 350 | 327 | $template_path = __DIR__ . '/templates/' . $template . '.php'; |
| 351 | 328 | |
| 352 | 329 | require $template_path; |
| 353 | 330 | } |
| @@ -363,10 +340,8 @@ | ||
| 363 | 340 | * |
| 364 | 341 | * @return array Available reports in Elementor system info page. |
| 365 | 342 | */ |
| 366 | 343 | public static function get_allowed_reports() { |
| 367 | - do_action( 'elementor/system_info/get_allowed_reports' ); | |
| 368 | - | |
| 369 | 344 | return self::$reports; |
| 370 | 345 | } |
| 371 | 346 | |
| 372 | 347 | /** |