print_report( $reports, 'html' ); ?>
capability ) ) {
wp_die( esc_html__( 'You do not have permission to download this file.', 'elementor' ) );
}
$reports_info = self::get_allowed_reports();
$reports = $this->load_reports( $reports_info );
$domain = parse_url( site_url(), PHP_URL_HOST );
header( 'Content-Type: text/plain' );
header( 'Content-Disposition:attachment; filename=system-info-' . $domain . '-' . gmdate( 'd-m-Y' ) . '.txt' );
$this->print_report( $reports );
die;
}
/**
* Get report class.
*
* Retrieve the class of the report for any given report type.
*
* @since 2.9.0
* @access public
*
* @param string $reporter_type The type of the report.
*
* @return string The class of the report.
*/
public function get_reporter_class( $reporter_type ) {
return __NAMESPACE__ . '\Reporters\\' . ucfirst( $reporter_type );
}
/**
* Load reports.
*
* Retrieve the system info reports.
*
* @since 2.9.0
* @access public
*
* @param array $reports An array of system info reports.
*
* @return array An array of system info reports.
*/
public function load_reports( $reports ) {
$result = [];
foreach ( $reports as $report_name => $report_info ) {
$reporter_params = [
'name' => $report_name,
];
$reporter_params = array_merge( $reporter_params, $report_info );
$reporter = $this->create_reporter( $reporter_params );
if ( ! $reporter instanceof Base ) {
continue;
}
$result[ $report_name ] = [
'report' => $reporter,
'label' => $reporter->get_title(),
];
if ( ! empty( $report_info['sub'] ) ) {
$result[ $report_name ]['sub'] = $this->load_reports( $report_info['sub'] );
}
}
return $result;
}
/**
* Create a report.
*
* Register a new report that will be displayed in Elementor system info page.
*
* @param array $properties Report properties.
*
* @return \WP_Error|false|Base Base instance if the report was created,
* False or WP_Error otherwise.
*@since 2.9.0
* @access public
*
*/
public function create_reporter( array $properties ) {
$properties = Model_Helper::prepare_properties( $this->get_settings( 'reporter_properties' ), $properties );
$reporter_class = $properties['class_name'] ? $properties['class_name'] : $this->get_reporter_class( $properties['name'] );
$reporter = new $reporter_class( $properties );
if ( ! ( $reporter instanceof Base ) ) {
return new \WP_Error( 'Each reporter must to be an instance or sub-instance of `Base` class.' );
}
if ( ! $reporter->is_enabled() ) {
return false;
}
return $reporter;
}
/**
* Print report.
*
* Output the system info page reports using an output template.
*
* @since 2.9.0
* @access public
*
* @param array $reports An array of system info reports.
* @param string $template Output type from the templates folder. Available
* templates are `raw` and `html`. Default is `raw`.
*/
public function print_report( $reports, $template = 'raw' ) {
static $tabs_count = 0;
$template_path = __DIR__ . '/templates/' . $template . '.php';
require $template_path;
}
/**
* Get allowed reports.
*
* Retrieve the available reports in Elementor system info page.
*
* @since 2.9.0
* @access public
* @static
*
* @return array Available reports in Elementor system info page.
*/
public static function get_allowed_reports() {
do_action( 'elementor/system_info/get_allowed_reports' );
return self::$reports;
}
/**
* Add report.
*
* Register a new report to Elementor system info page.
*
* @since 2.9.0
* @access public
* @static
*
* @param string $report_name The name of the report.
* @param array $report_info Report info.
*/
public static function add_report( $report_name, $report_info ) {
self::$reports[ $report_name ] = $report_info;
}
}