admin_url( 'admin-ajax.php' ), 'axeUrl' => ACCSCAN_URL . 'assets/js/axe.min.js', 'nonce' => wp_create_nonce( 'accscan_nonce' ), 'level' => isset( $settings['wcag_level'] ) ? $settings['wcag_level'] : 'wcag21aa', 'i18n' => array( 'collecting' => __( 'Collecting your pages…', 'easyable' ), /* translators: %1$d: page being checked now, %2$d: total number of pages. */ 'checking' => __( 'Checking page %1$d of %2$d', 'easyable' ), 'saving' => __( 'Saving your results…', 'easyable' ), 'done' => __( 'Done! Taking you to your problems…', 'easyable' ), 'failed' => __( 'Something went wrong. Please try again.', 'easyable' ), 'engineMissing' => __( 'The checker engine did not load. Please reload this page and try again.', 'easyable' ), /* translators: %d: number of pages skipped because they were too slow. */ 'skipped' => __( '%d slow page(s) skipped', 'easyable' ), 'cancelling' => __( 'Stopping — saving what we have checked so far…', 'easyable' ), 'foundProblems' => __( 'problems found', 'easyable' ), 'copied' => __( 'Copied!', 'easyable' ), ), ) ); } /* ------------------------------------------------------- utilities */ /** * Page header used on every screen. * * @param string $title Screen title. * @param string $sub Plain subtitle. */ private function header( $title, $sub ) { ?>

' . esc_html__( 'Your statement page is ready as a draft. Review it, then publish it when you are happy.', 'easyable' ); if ( $page_id ) { echo ' ' . esc_html__( 'Open the draft', 'easyable' ) . ''; } echo '

'; } elseif ( 'settings' === $msg ) { echo '

' . esc_html__( 'Settings saved.', 'easyable' ) . '

'; } } /* --------------------------------------------------------- screens */ /** * Overview screen. */ public function screen_overview() { if ( ! current_user_can( 'manage_options' ) ) { return; } $results = AccScan_Core::latest_results(); $scan = $results['scan']; $issues = $results['issues']; $counts = AccScan_Core::bucket_counts( $issues ); $active = array_filter( $issues, function ( $i ) { return empty( $i['ignored'] ); } ); $score = $scan ? AccScan_Core::compute_score( $active ) : null; echo '
'; $this->header( __( 'EasyAble', 'easyable' ), __( 'Make your site easy for everyone to use.', 'easyable' ) ); $this->flag_notice(); ?>

1
2
3

urls_count ) ); ?>

finished_at ) ) ) ); ?>


array( __( 'Fix first', 'easyable' ), '#c42c2c' ), 'important' => array( __( 'Important', 'easyable' ), '#d97706' ), 'should' => array( __( 'Should fix', 'easyable' ), '#b08404' ), 'nice' => array( __( 'Nice to fix', 'easyable' ), '#5a6e82' ), ); foreach ( $buckets as $key => $meta ) : ?>
recent_scans_table(); $this->honesty_note(); $this->scan_modal(); echo '
'; } /** * Recent scans table on the overview. */ private function recent_scans_table() { global $wpdb; $table = $wpdb->prefix . 'accscan_scans'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is built from $wpdb->prefix only; the query has no user input. $rows = $wpdb->get_results( "SELECT * FROM $table ORDER BY id DESC LIMIT 5" ); if ( ! $rows ) { return; } ?>

started_at ) ) ); ?> status ? esc_html( $row->urls_count ) : '—'; ?> score ? esc_html( $row->score ) : '—'; ?> counts ) { $c = json_decode( $row->counts, true ); echo isset( $c['total'] ) ? esc_html( $c['total'] ) : '—'; } else { echo 'reminder' === $row->status ? esc_html__( 'Time for a new check', 'easyable' ) : '—'; } ?>
0, 'important' => 1, 'should' => 2, 'nice' => 3 ); uasort( $groups, function ( $a, $b ) use ( $order ) { return $order[ $a['bucket']['key'] ] <=> $order[ $b['bucket']['key'] ]; } ); echo '
'; $this->header( __( 'Problems to fix', 'easyable' ), __( 'Start at the top. We explain everything in plain words.', 'easyable' ) ); $this->flag_notice(); if ( ! $results['scan'] ) { echo '

' . esc_html__( 'No check yet. Run your first check from the Overview and your problems will appear here.', 'easyable' ) . '

' . esc_html__( 'Go to Overview', 'easyable' ) . '

'; echo '
'; return; } $chips = array( '' => __( 'All problems', 'easyable' ), 'fix-first' => __( 'Fix first', 'easyable' ), 'important' => __( 'Important', 'easyable' ), 'should' => __( 'Should fix', 'easyable' ), 'nice' => __( 'Nice to fix', 'easyable' ) ); echo '
'; foreach ( $chips as $key => $label ) { $url = admin_url( 'admin.php?page=accscan-problems' . ( $key ? '&bucket=' . $key : '' ) ); echo '' . esc_html( $label ) . ''; } echo '
'; if ( ! $groups ) { echo '

' . esc_html__( 'Nothing here. Either everything in this group is fixed, or it is on your ignore list below.', 'easyable' ) . '

'; } foreach ( $groups as $rule_id => $group ) { $guide = AccScan_Guidance::for_rule( $rule_id ); $pages = count( array_unique( array_column( $group['items'], 'page_url' ) ) ); $first = $group['items'][0]; $fixtext = implode( "\n", array_map( function ( $s, $i ) { return ( $i + 1 ) . '. ' . $s; }, $guide['steps'], array_keys( $guide['steps'] ) ) ); ?>
·

1 ) : ?>

' . esc_html__( 'Ignored problems', 'easyable' ) . ''; $iguide = array(); foreach ( $ignored as $issue ) { $iguide[ $issue['rule_id'] ] = true; } foreach ( array_keys( $iguide ) as $rule_id ) { $guide = AccScan_Guidance::for_rule( $rule_id ); ?>
honesty_note(); echo ''; } /** * Statement screen. */ public function screen_statement() { if ( ! current_user_can( 'manage_options' ) ) { return; } $saved = get_option( 'accscan_statement', array() ); $org = isset( $saved['org'] ) ? $saved['org'] : get_bloginfo( 'name' ); $email = isset( $saved['email'] ) ? $saved['email'] : get_bloginfo( 'admin_email' ); $level = isset( $saved['level'] ) ? $saved['level'] : 'WCAG 2.1 AA'; echo '
'; $this->header( __( 'Make your statement', 'easyable' ), __( 'One page that shows visitors you take accessibility seriously.', 'easyable' ) ); $this->flag_notice(); ?>

'; } /** * Settings screen. */ public function screen_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = get_option( 'accscan_settings', array() ); $types = isset( $settings['post_types'] ) ? (array) $settings['post_types'] : array( 'page', 'post' ); $level = isset( $settings['wcag_level'] ) ? $settings['wcag_level'] : 'wcag21aa'; $schedule = isset( $settings['schedule'] ) ? $settings['schedule'] : 'off'; $public = get_post_types( array( 'public' => true ), 'objects' ); echo '
'; $this->header( __( 'Settings', 'easyable' ), __( 'Choose what to check. Everything stays on your own server.', 'easyable' ) ); $this->flag_notice(); ?>

name ) { continue; } ?>

'; } /* ------------------------------------------------------------ AJAX */ /** * Capability + nonce gate for AJAX handlers. */ private function ajax_gate() { if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'msg' => 'forbidden' ), 403 ); } check_ajax_referer( 'accscan_nonce', 'nonce' ); } /** * Start a scan: create the scan record. */ public function ajax_start_scan() { $this->ajax_gate(); global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->insert( $wpdb->prefix . 'accscan_scans', array( 'started_at' => current_time( 'mysql' ), 'status' => 'running' ), array( '%s', '%s' ) ); wp_send_json_success( array( 'scan_id' => (int) $wpdb->insert_id ) ); } /** * Return the URL list for the runner. */ public function ajax_get_urls() { $this->ajax_gate(); wp_send_json_success( array( 'urls' => AccScan_Core::collect_urls() ) ); } /** * Save one batch of page results. */ public function ajax_save_results() { $this->ajax_gate(); global $wpdb; $scan_id = isset( $_POST['scan_id'] ) ? (int) $_POST['scan_id'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in ajax_gate() above via check_ajax_referer(). $pages = isset( $_POST['pages'] ) ? json_decode( wp_unslash( $_POST['pages'] ), true ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification.Missing -- Nonce verified in ajax_gate() above; decoded as data, each field sanitized below. if ( ! $scan_id || ! is_array( $pages ) ) { wp_send_json_error( array( 'msg' => 'bad request' ), 400 ); } $table = $wpdb->prefix . 'accscan_issues'; $saved = 0; foreach ( $pages as $page ) { $url = isset( $page['url'] ) ? esc_url_raw( $page['url'] ) : ''; $title = isset( $page['title'] ) ? sanitize_text_field( $page['title'] ) : ''; $type = isset( $page['type'] ) ? sanitize_key( $page['type'] ) : ''; foreach ( isset( $page['violations'] ) && is_array( $page['violations'] ) ? $page['violations'] : array() as $v ) { $rule = isset( $v['rule'] ) ? sanitize_key( $v['rule'] ) : ''; $target = isset( $v['target'] ) ? sanitize_text_field( substr( (string) $v['target'], 0, 480 ) ) : ''; if ( ! $rule ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->insert( $table, array( 'scan_id' => $scan_id, 'rule_id' => $rule, 'impact' => isset( $v['impact'] ) ? sanitize_key( $v['impact'] ) : 'moderate', 'page_url' => $url, 'page_title' => $title, 'post_type' => $type, 'target' => $target, 'html_snippet' => isset( $v['html'] ) ? sanitize_text_field( substr( (string) $v['html'], 0, 300 ) ) : '', 'failure_summary' => isset( $v['summary'] ) ? sanitize_textarea_field( substr( (string) $v['summary'], 0, 500 ) ) : '', 'signature' => AccScan_Core::signature( $rule, $url, $target ), ), array( '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ); $saved++; } } // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'accscan_scans SET urls_done = urls_done + %d WHERE id = %d', count( $pages ), $scan_id ) ); wp_send_json_success( array( 'saved' => $saved ) ); } /** * Finish a scan: compute score + counts and close the record. */ public function ajax_finish_scan() { $this->ajax_gate(); global $wpdb; $scan_id = isset( $_POST['scan_id'] ) ? (int) $_POST['scan_id'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in ajax_gate() above via check_ajax_referer(). $urls_count = isset( $_POST['urls_count'] ) ? (int) $_POST['urls_count'] : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in ajax_gate() above via check_ajax_referer(). $issues_table = $wpdb->prefix . 'accscan_issues'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is built from $wpdb->prefix only; the scan id value is prepared. $rows = $wpdb->get_results( $wpdb->prepare( "SELECT impact, signature FROM $issues_table WHERE scan_id = %d", $scan_id ), ARRAY_A ); $ignored = AccScan_Core::ignored_signatures(); $active = array(); foreach ( (array) $rows as $row ) { if ( ! in_array( $row['signature'], $ignored, true ) ) { $active[] = $row; } } $score = AccScan_Core::compute_score( $active ); $counts = AccScan_Core::bucket_counts( $active ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->update( $wpdb->prefix . 'accscan_scans', array( 'finished_at' => current_time( 'mysql' ), 'status' => 'complete', 'urls_count' => $urls_count, 'score' => $score, 'counts' => wp_json_encode( $counts ), ), array( 'id' => $scan_id ), array( '%s', '%s', '%d', '%d', '%s' ), array( '%d' ) ); wp_send_json_success( array( 'score' => $score, 'counts' => $counts ) ); } /* ---------------------------------------------------- form actions */ /** * CSV export of the latest scan. */ public function handle_export() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'easyable' ) ); } check_admin_referer( 'accscan_export' ); $results = AccScan_Core::latest_results(); nocache_headers(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename=accessibility-problems.csv' ); // The CSV is built as a string and echoed: no direct filesystem // calls (fopen/fputcsv/fclose) are needed for a download. echo $this->csv_line( array( 'Problem', 'How urgent', 'Page', 'Page URL', 'Element', 'Why it matters', 'How to fix' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CSV download, fields escaped by csv_line(). foreach ( $results['issues'] as $issue ) { if ( ! empty( $issue['ignored'] ) ) { continue; } $guide = AccScan_Guidance::for_rule( $issue['rule_id'] ); $bucket = AccScan_Core::bucket_for_impact( $issue['impact'] ); $row = $this->csv_line( array( $guide['title'], $bucket['label'], $issue['page_title'], $issue['page_url'], $issue['target'], $guide['why'], implode( ' ', $guide['steps'] ), ) ); echo $row; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CSV download; the row is built and escaped by csv_line(). } exit; } /** * Escape and join one CSV row (RFC 4180 quoting). * * @param string[] $fields Row fields. * @return string */ private function csv_line( $fields ) { $cells = array(); foreach ( (array) $fields as $field ) { $field = (string) $field; if ( preg_match( '/[",\r\n ]/', $field ) ) { $field = '"' . str_replace( '"', '""', $field ) . '"'; } $cells[] = $field; } return implode( ',', $cells ) . "\r\n"; } /** * Ignore / unignore all instances of one rule from the latest scan. */ public function handle_ignore() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'easyable' ) ); } check_admin_referer( 'accscan_ignore' ); $mode = isset( $_POST['mode'] ) ? sanitize_key( wp_unslash( $_POST['mode'] ) ) : ''; $rule = isset( $_POST['rule'] ) ? sanitize_key( wp_unslash( $_POST['rule'] ) ) : ''; if ( $rule ) { $results = AccScan_Core::latest_results(); $ignored = AccScan_Core::ignored_signatures(); $sigs = array(); foreach ( $results['issues'] as $issue ) { if ( $issue['rule_id'] === $rule ) { $sigs[] = $issue['signature']; } } if ( 'ignore-rule' === $mode ) { $ignored = array_values( array_unique( array_merge( $ignored, $sigs ) ) ); } else { $ignored = array_values( array_diff( $ignored, $sigs ) ); } update_option( 'accscan_ignored', $ignored ); } wp_safe_redirect( admin_url( 'admin.php?page=accscan-problems' ) ); exit; } /** * Create the statement draft page. */ public function handle_statement() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'easyable' ) ); } check_admin_referer( 'accscan_statement' ); $org = isset( $_POST['org'] ) ? sanitize_text_field( wp_unslash( $_POST['org'] ) ) : ''; $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; $level = isset( $_POST['level'] ) ? sanitize_text_field( wp_unslash( $_POST['level'] ) ) : 'WCAG 2.1 AA'; if ( ! in_array( $level, array( 'WCAG 2.1 AA', 'WCAG 2.2 AA' ), true ) ) { $level = 'WCAG 2.1 AA'; } $results = AccScan_Core::latest_results(); $known = array(); foreach ( $results['issues'] as $issue ) { if ( empty( $issue['ignored'] ) ) { $guide = AccScan_Guidance::for_rule( $issue['rule_id'] ); $known[] = $guide['title']; } } $data = array( 'org' => $org, 'email' => $email, 'level' => $level, 'date' => date_i18n( get_option( 'date_format' ) ), 'known_issues' => $known, ); $result = AccScan_Statement::create_page( $data ); if ( ! is_wp_error( $result ) ) { $saved = get_option( 'accscan_statement', array() ); $saved['org'] = $org; $saved['email'] = $email; $saved['level'] = $level; update_option( 'accscan_statement', $saved ); } wp_safe_redirect( admin_url( 'admin.php?page=accscan-statement&accscan_msg=statement' ) ); exit; } /** * Save settings. */ public function handle_settings() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'easyable' ) ); } check_admin_referer( 'accscan_settings' ); $types = isset( $_POST['post_types'] ) ? array_map( 'sanitize_key', (array) wp_unslash( $_POST['post_types'] ) ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $types = array_filter( $types, 'post_type_exists' ); $level = isset( $_POST['wcag_level'] ) ? sanitize_key( wp_unslash( $_POST['wcag_level'] ) ) : 'wcag21aa'; if ( ! in_array( $level, array( 'wcag21aa', 'wcag22aa' ), true ) ) { $level = 'wcag21aa'; } $schedule = isset( $_POST['schedule'] ) ? sanitize_key( wp_unslash( $_POST['schedule'] ) ) : 'off'; if ( ! in_array( $schedule, array( 'off', 'weekly' ), true ) ) { $schedule = 'off'; } update_option( 'accscan_settings', array( 'post_types' => array_values( $types ), 'wcag_level' => $level, 'schedule' => $schedule, ) ); accscan_sync_schedule(); wp_safe_redirect( admin_url( 'admin.php?page=accscan-settings&accscan_msg=settings' ) ); exit; } }