0 === strpos( get_locale(), 'it' ) ? 'it' : 'en', 'org' => get_bloginfo( 'name' ), 'status' => '', 'standard' => '2.2', 'noncompliant' => '', 'alternatives' => '', 'method' => 'self', 'date' => '', 'email' => get_option( 'admin_email' ), 'response_days' => 30, 'enforcement' => '', 'page_id' => 0, ) ); } /** * Validates the submitted form. * * @param array $in Raw input (already unslashed). * @return array */ function agevole_a11y_statement_sanitize( $in ) { $date = isset( $in['date'] ) ? sanitize_text_field( $in['date'] ) : ''; return array( 'lang' => ( isset( $in['lang'] ) && 'en' === $in['lang'] ) ? 'en' : 'it', 'org' => isset( $in['org'] ) ? sanitize_text_field( $in['org'] ) : '', 'status' => ( isset( $in['status'] ) && in_array( $in['status'], array( 'full', 'partial', 'none' ), true ) ) ? $in['status'] : '', 'standard' => ( isset( $in['standard'] ) && '2.1' === $in['standard'] ) ? '2.1' : '2.2', 'noncompliant' => isset( $in['noncompliant'] ) ? sanitize_textarea_field( $in['noncompliant'] ) : '', 'alternatives' => isset( $in['alternatives'] ) ? sanitize_textarea_field( $in['alternatives'] ) : '', 'method' => ( isset( $in['method'] ) && 'third' === $in['method'] ) ? 'third' : 'self', 'date' => preg_match( '/^\d{4}-\d{2}-\d{2}$/', $date ) ? $date : '', 'email' => isset( $in['email'] ) ? sanitize_email( $in['email'] ) : '', 'response_days' => isset( $in['response_days'] ) ? min( 90, max( 1, absint( $in['response_days'] ) ) ) : 30, 'enforcement' => isset( $in['enforcement'] ) ? sanitize_textarea_field( $in['enforcement'] ) : '', ); } /** * Texts of the statement page, in Italian and English. * * @param string $lang it|en. * @return array */ function agevole_a11y_statement_texts( $lang ) { if ( 'it' === $lang ) { return array( 'title' => 'Dichiarazione di accessibilità', 'intro' => '%1$s si impegna a rendere accessibile il proprio sito web %2$s. Questa dichiarazione si riferisce al sito %2$s e fa riferimento alle Linee guida per l’accessibilità dei contenuti web (WCAG) %3$s, livello AA, e alla norma europea EN 301 549.', 'h_status' => 'Stato di conformità', 'full' => 'Questo sito è pienamente conforme alle WCAG %s livello AA.', 'partial' => 'Questo sito è parzialmente conforme alle WCAG %s livello AA, a causa dei casi di non conformità elencati di seguito.', 'none' => 'Questo sito non è conforme alle WCAG %s livello AA. I casi di non conformità sono elencati di seguito.', 'h_content' => 'Contenuti non accessibili', 'alternatives' => 'Alternative accessibili', 'h_prep' => 'Redazione della dichiarazione', 'prepared' => 'Questa dichiarazione è stata redatta il %s.', 'self' => 'La valutazione è stata effettuata con un’autovalutazione.', 'third' => 'La valutazione è stata effettuata da una terza parte.', 'h_feedback' => 'Segnalazioni e contatti', 'feedback' => 'Se riscontri problemi di accessibilità o non riesci ad accedere a un contenuto o a un servizio, scrivi a %1$s. Ti risponderemo entro %2$d giorni.', 'h_enforce' => 'Procedura di attuazione', ); } return array( 'title' => 'Accessibility statement', 'intro' => '%1$s is committed to making its website %2$s accessible. This statement applies to %2$s and refers to the Web Content Accessibility Guidelines (WCAG) %3$s, level AA, and to the European standard EN 301 549.', 'h_status' => 'Compliance status', 'full' => 'This website is fully compliant with WCAG %s level AA.', 'partial' => 'This website is partially compliant with WCAG %s level AA, due to the non-compliances listed below.', 'none' => 'This website is not compliant with WCAG %s level AA. The non-compliances are listed below.', 'h_content' => 'Non-accessible content', 'alternatives' => 'Accessible alternatives', 'h_prep' => 'Preparation of this statement', 'prepared' => 'This statement was prepared on %s.', 'self' => 'The assessment was carried out as a self-assessment.', 'third' => 'The assessment was carried out by a third party.', 'h_feedback' => 'Feedback and contact information', 'feedback' => 'If you find accessibility problems or cannot access any content or service, write to %1$s. We will reply within %2$d days.', 'h_enforce' => 'Enforcement procedure', ); } /** * Block markup of the statement page. * * @param array $d Statement data. * @return string */ function agevole_a11y_statement_content( $d ) { $t = agevole_a11y_statement_texts( $d['lang'] ); $p = static function ( $html ) { return "\n

" . $html . "

\n\n\n"; }; $h = static function ( $text ) { return "\n

" . esc_html( $text ) . "

\n\n\n"; }; $ul = static function ( $lines ) { $items = ''; foreach ( $lines as $line ) { $items .= "\n
  • " . esc_html( $line ) . "
  • \n\n"; } return "\n\n\n\n"; }; $site = untrailingslashit( home_url( '/' ) ); $date = '' !== $d['date'] ? $d['date'] : wp_date( 'Y-m-d' ); $date = date_i18n( 'it' === $d['lang'] ? 'j/n/Y' : 'Y-m-d', strtotime( $date . ' 12:00:00' ) ); $out = $p( esc_html( sprintf( $t['intro'], $d['org'], $site, $d['standard'] ) ) ); $out .= $h( $t['h_status'] ); $out .= $p( esc_html( sprintf( $t[ $d['status'] ], $d['standard'] ) ) ); $lines = array_filter( array_map( 'trim', explode( "\n", $d['noncompliant'] ) ) ); if ( 'full' !== $d['status'] && $lines ) { $out .= $h( $t['h_content'] ); $out .= $ul( $lines ); if ( '' !== trim( $d['alternatives'] ) ) { $out .= $p( '' . esc_html( $t['alternatives'] ) . ': ' . nl2br( esc_html( $d['alternatives'] ) ) ); } } $out .= $h( $t['h_prep'] ); $out .= $p( esc_html( sprintf( $t['prepared'], $date ) ) . ' ' . esc_html( $t[ $d['method'] ] ) ); $out .= $h( $t['h_feedback'] ); $mail = '' . esc_html( $d['email'] ) . ''; $out .= $p( sprintf( esc_html( $t['feedback'] ), $mail, (int) $d['response_days'] ) ); if ( '' !== trim( $d['enforcement'] ) ) { $out .= $h( $t['h_enforce'] ); $out .= $p( nl2br( esc_html( $d['enforcement'] ) ) ); } return $out; } /** * Statement tab: guided form. */ function agevole_a11y_render_statement_tab() { $d = agevole_a11y_statement_data(); $page = $d['page_id'] ? get_post( (int) $d['page_id'] ) : null; $page = ( $page && 'trash' !== $page->post_status ) ? $page : null; $done = isset( $_GET['statement'] ) ? sanitize_key( wp_unslash( $_GET['statement'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only. $can = current_user_can( 'manage_options' ); $f = static function ( $key ) { return 'agevole-st-' . $key; }; ?>

    'invalid' ) ) ); exit; } $texts = agevole_a11y_statement_texts( $d['lang'] ); $page = $d['page_id'] ? get_post( $d['page_id'] ) : null; if ( $page && 'page' === $page->post_type && 'trash' !== $page->post_status ) { wp_update_post( array( 'ID' => $page->ID, 'post_content' => agevole_a11y_statement_content( $d ), ) ); $result = 'updated'; } else { $id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'draft', 'post_title' => $texts['title'], 'post_content' => agevole_a11y_statement_content( $d ), ), true ); if ( is_wp_error( $id ) ) { wp_die( esc_html( $id->get_error_message() ) ); } $d['page_id'] = (int) $id; update_option( AGEVOLE_A11Y_STATEMENT_OPTION, $d, false ); $result = 'created'; } wp_safe_redirect( agevole_a11y_tools_url( 'statement', array( 'statement' => $result ) ) ); exit; } add_action( 'admin_post_agevole_a11y_statement', 'agevole_a11y_statement_save' );