set_translation_strings(); require_once( ITSEC_Core::get_core_dir() . '/admin-pages/sidebar-widget.php' ); require_once( ITSEC_Core::get_core_dir() . '/lib/form.php' ); do_action( 'itsec-grade-report-page-init' ); } public function add_scripts() { $vars = array( 'ajax_action' => 'itsec_grade_report_page', 'ajax_nonce' => wp_create_nonce( 'itsec-grade-report-nonce' ), 'translations' => $this->translations, ); wp_enqueue_script( 'itsec-grade-donut', plugins_url( 'js/grade-donut.js', __FILE__ ), array( 'jquery' ), ITSEC_Core::get_plugin_build(), true ); wp_enqueue_script( 'itsec-grade-report-page-script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery-ui-dialog', 'itsec-grade-donut' ), ITSEC_Core::get_plugin_build(), true ); wp_localize_script( 'itsec-grade-report-page-script', 'itsec_page', $vars ); } public function add_styles() { wp_enqueue_style( 'itsec-settings-page-style', plugins_url( 'css/style.css', ITSEC_Core::get_core_dir() . '/admin-pages/init.php' ), array(), ITSEC_Core::get_plugin_build() ); wp_enqueue_style( 'itsec-grade-report-page-style', plugins_url( 'css/style.css', __FILE__ ), array( 'itsec-settings-page-style' ), ITSEC_Core::get_plugin_build() ); wp_enqueue_style( 'wp-jquery-ui-dialog' ); } private function set_translation_strings() { $this->translations = array( 'loading' => esc_html__( 'Loading...', 'it-l10n-ithemes-security-pro' ), 'num_criteria' => esc_html__( '%d Grading Criteria', 'it-l10n-ithemes-security-pro' ), 'ajax_invalid' => new WP_Error( 'itsec-settings-page-invalid-ajax-response', __( 'An "invalid format" error prevented the request from completing as expected. The format of data returned could not be recognized. This could be due to a plugin/theme conflict or a server configuration issue.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_forbidden' => new WP_Error( 'itsec-settings-page-forbidden-ajax-response: %1$s "%2$s"', __( 'A "request forbidden" error prevented the request from completing as expected. The server returned a 403 status code, indicating that the server configuration is prohibiting this request. This could be due to a plugin/theme conflict or a server configuration issue. Please try refreshing the page and trying again. If the request continues to fail, you may have to alter plugin settings or server configuration that could account for this AJAX request being blocked.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_not_found' => new WP_Error( 'itsec-settings-page-not-found-ajax-response: %1$s "%2$s"', __( 'A "not found" error prevented the request from completing as expected. The server returned a 404 status code, indicating that the server was unable to find the requested admin-ajax.php file. This could be due to a plugin/theme conflict, a server configuration issue, or an incomplete WordPress installation. Please try refreshing the page and trying again. If the request continues to fail, you may have to alter plugin settings, alter server configurations, or reinstall WordPress.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_server_error' => new WP_Error( 'itsec-settings-page-server-error-ajax-response: %1$s "%2$s"', __( 'A "internal server" error prevented the request from completing as expected. The server returned a 500 status code, indicating that the server was unable to complete the request due to a fatal PHP error or a server problem. This could be due to a plugin/theme conflict, a server configuration issue, a temporary hosting issue, or invalid custom PHP modifications. Please check your server\'s error logs for details about the source of the error and contact your hosting company for assistance if required.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_unknown' => new WP_Error( 'itsec-settings-page-ajax-error-unknown: %1$s "%2$s"', __( 'An unknown error prevented the request from completing as expected. This could be due to a plugin/theme conflict or a server configuration issue.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_timeout' => new WP_Error( 'itsec-settings-page-ajax-error-timeout: %1$s "%2$s"', __( 'A timeout error prevented the request from completing as expected. The site took too long to respond. This could be due to a plugin/theme conflict or a server configuration issue.', 'it-l10n-ithemes-security-pro' ) ), 'ajax_parsererror' => new WP_Error( 'itsec-settings-page-ajax-error-parsererror: %1$s "%2$s"', __( 'A parser error prevented the request from completing as expected. The site sent a response that jQuery could not process. This could be due to a plugin/theme conflict or a server configuration issue.', 'it-l10n-ithemes-security-pro' ) ), ); foreach ( $this->translations as $key => $message ) { if ( is_wp_error( $message ) ) { $messages = ITSEC_Response::get_error_strings( $message ); $this->translations[$key] = $messages[0]; } } } public function handle_ajax_request() { check_admin_referer( 'itsec-grade-report-nonce' ); if ( 'resolve_selected_issues' === $_POST['method'] ) { $this->resolve_selected_issues(); } ITSEC_Response::send_json(); } private function resolve_selected_issues() { require_once( dirname( dirname ( __FILE__ ) ) . '/report.php' ); if ( empty( $_POST['selected'] ) ) { ITSEC_Response::add_info( __( 'No issues were selected. No changes were made.', 'it-l10n-ithemes-security-pro' ) ); return; } ITSEC_Grading_System::resolve_issues( $_POST['selected'] ); $form = new ITSEC_Form(); $report = ITSEC_Grading_System::get_report(); ob_start(); $this->render_modal_content_main( $form, $report ); $modal_content_main = ob_get_clean(); ob_start(); $this->render_modal_title( $report ); $modal_title = ob_get_clean(); ob_start(); $this->render_cards( $form, $report ); $cards = ob_get_clean(); $data = array( 'modalContentMain' => $modal_content_main, 'modalTitle' => $modal_title, 'cards' => $cards, ); ITSEC_Response::add_js_function_call( 'updatePageAfterFixes', $data ); } public function filter_screen_settings( $settings ) { } public function handle_page_load( $self_url ) { $this->self_url = $self_url; $this->show_grade_report(); } private function show_grade_report() { require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-wp-list-table.php' ); require_once( ITSEC_Core::get_core_dir() . '/admin-pages/logs-list-table.php' ); require_once( dirname( dirname ( __FILE__ ) ) . '/report.php' ); $form = new ITSEC_Form(); $report = ITSEC_Grading_System::get_report(); ?>

start_form(); ?>
    render_cards( $form, $report ); ?>
end_form(); ?>
start_form(); ?>
render_modal_title( $report ); ?>
render_modal_content_main( $form, $report ); ?>
end_form(); ?>

render_card_grade( $report['grade']['real'] ); $this->render_card_header_text( 'Grade Report Issues', 'it-l10n-ithemes-security-pro' ); $this->render_card_subheader_text( sprintf( esc_html( _n( '%d Total Issue', '%d Total Issues', $report['issues'], 'it-l10n-ithemes-security-pro' ) ), $report['issues'] ) ); } private function render_modal_content_main( $form, $report ) { ?> render_security_score_card( $form, $report ); $this->render_summary_card( $form, $report ); foreach ( $report['sections'] as $section ) { $this->render_section_card( $form, $section ); } } private function render_security_score_card( $form, $report ) { $this->open_card( 'security-score' ); $this->open_card_header(); $this->render_card_header_text( esc_html__( 'Grade', 'it-l10n-ithemes-security-pro' ) ); $subheader = ''; if ( $report['grade']['real'] !== $report['grade']['potential'] ) { if ( in_array( substr( $report['grade']['potential'], 0, 1 ), array( 'A', 'F' ) ) ) { $subheader = sprintf( wp_kses( _n( 'Resolve 1 issue to raise the grade to an "%2$s".', 'Resolve %1$s issues to raise the grade to an "%2$s".', $report['issues'], 'it-l10n-ithemes-security-pro' ), array( 'a' => array( 'href' => array() ) ) ), $report['issues'], $report['grade']['potential'] ); } else { $subheader = sprintf( wp_kses( _n( 'Resolve 1 issue to raise the grade to a "%2$s".', 'Resolve %1$s issues to raise the grade to a "%2$s".', $report['issues'], 'it-l10n-ithemes-security-pro' ), array( 'a' => array( 'href' => array() ) ) ), $report['issues'], $report['grade']['potential'] ); } } else { $subheader = wp_kses( __( 'View grade report details.', 'it-l10n-ithemes-security-pro' ), array( 'a' => array( 'href' => array() ) ) ); } if ( ! empty( $subheader ) ) { $this->render_card_subheader_text( $subheader ); } $this->close_card_header(); ?>
open_card_footer(); ?>
A B C D F
close_card_footer(); $this->close_card(); } private function render_summary_card( $form, $report ) { $this->open_card( 'summary' ); $this->open_card_header(); if ( $report['fixable_issues'] ) { $this->render_card_header_button( 'itsec-resolve-issues', esc_html__( 'Resolve Issues', 'it-l10n-ithemes-security-pro' ) ); } else { $this->render_card_header_button( 'itsec-resolve-issues', esc_html__( 'View Grade Report Details', 'it-l10n-ithemes-security-pro' ) ); } $this->render_card_header_text( esc_html__( 'Summary', 'it-l10n-ithemes-security-pro' ) ); $report_datetime = date( _x( 'l, F j, Y', 'security score assessment date format' ), $report['timestamp'] ); $subheader = sprintf( wp_kses( __( 'Assessed on: %s', 'it-l10n-ithemes-security-pro' ), array( 'span' => array( 'class' => array() ) ) ), $report_datetime ); $this->render_card_subheader_text( $subheader ); $this->close_card_header(); ?>
open_card_footer(); ?>
close_card_footer(); $this->close_card(); } private function render_resolve_issues_section( $form, $section ) { $this->open_card( $section['id'], 'itsec-section-card' ); $this->open_card_header(); $this->render_card_grade( $section['grade']['current'] ); $this->render_card_header_text( $section['name'] ); $this->close_card_header(); ?>
$criterion ) : ?>
array( 'href' => array() ) ) ); ?>  
close_card(); } private function render_section_card( $form, $section ) { $this->open_card( $section['id'], 'itsec-section-card' ); $this->open_card_header(); $this->render_card_grade( $section['grade']['current'] ); $this->render_card_header_text( $section['name'] ); $this->render_card_subheader_text( $section['description'] ); $this->close_card_header(); ?>
open_card_footer(); $this->render_card_button( 'view-report', esc_html__( 'View Report', 'it-l10n-ithemes-security-pro' ) ); $this->close_card_footer();*/ $this->close_card(); } private function render_card_header_text( $text ) { echo "

$text

\n"; } private function render_card_subheader_text( $text, $class = '' ) { echo "
$text
\n"; } private function render_card_header_button( $class, $text ) { echo "\n"; } private function render_card_button( $class, $text ) { echo "\n"; } private function render_card_grade( $grade ) { $grade = strtoupper( $grade ); if ( 1 == strlen( $grade ) ) { $letter = $grade; $modifier = ''; } else { list( $letter, $modifier ) = str_split( $grade ); } if ( ! in_array( $letter, array( 'A', 'B', 'C', 'D', 'F' ) ) ) { $letter = 'F'; } if ( '+' === $modifier ) { $class = 'itsec-card-grade-modifier-plus'; $display_modifier = '+'; } else if ( '-' === $modifier ) { $class = 'itsec-card-grade-modifier-minus'; $display_modifier = '–'; } echo "$letter"; if ( isset( $display_modifier ) ) { echo "$display_modifier"; } echo "\n"; } private function open_card_header() { echo "
\n"; } private function close_card_header() { echo "
\n"; } private function open_card_footer() { echo "\n"; } private function open_card( $id, $class = '' ) { echo "
  • \n"; } private function close_card() { echo "
  • \n"; } } new ITSEC_Grade_Report_Page();