0 === strpos( (string) get_locale(), 'nb' ) || 0 === strpos( (string) get_locale(), 'nn' ) ? 'nb' : 'en', 'org' => get_bloginfo( 'name' ), 'website' => home_url( '/' ), 'email' => get_bloginfo( 'admin_email' ), 'phone' => '', 'response_days' => 10, 'standard' => AriAccess_Settings::get( 'checker', 'standard' ), 'status' => 'partial', 'known_issues' => '', 'alternatives' => '', 'method' => 'self', 'review_date' => gmdate( 'Y-m-d' ), 'uustatus_url' => '', 'footer_link' => false, 'page_id' => 0, ); } /** * Saved data merged over defaults. * * @return array */ public static function get() { $saved = get_option( self::OPTION, array() ); return array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); } /** * Sanitise and save. * * @param array $in Raw input. * @return array Saved data. */ public static function save( $in ) { $cur = self::get(); $out = array( 'language' => in_array( $in['language'] ?? '', array( 'en', 'nb' ), true ) ? $in['language'] : 'en', 'org' => sanitize_text_field( $in['org'] ?? '' ), 'website' => esc_url_raw( $in['website'] ?? '' ), 'email' => sanitize_email( $in['email'] ?? '' ), 'phone' => sanitize_text_field( $in['phone'] ?? '' ), 'response_days' => max( 1, min( 90, (int) ( $in['response_days'] ?? 10 ) ) ), 'standard' => array_key_exists( $in['standard'] ?? '', AriAccess_Rules::standards() ) ? $in['standard'] : 'no-private', 'status' => in_array( $in['status'] ?? '', array( 'full', 'partial', 'none' ), true ) ? $in['status'] : 'partial', 'known_issues' => sanitize_textarea_field( $in['known_issues'] ?? '' ), 'alternatives' => sanitize_textarea_field( $in['alternatives'] ?? '' ), 'method' => in_array( $in['method'] ?? '', array( 'self', 'external', 'mixed' ), true ) ? $in['method'] : 'self', 'review_date' => preg_match( '/^\d{4}-\d{2}-\d{2}$/', $in['review_date'] ?? '' ) ? $in['review_date'] : gmdate( 'Y-m-d' ), 'uustatus_url' => esc_url_raw( $in['uustatus_url'] ?? '' ), 'footer_link' => ! empty( $in['footer_link'] ), 'page_id' => (int) $cur['page_id'], ); update_option( self::OPTION, $out ); return $out; } /** * Public statement address: explicit setting, then uustatus, then the generated page. * * @return string */ public static function public_url() { $explicit = (string) AriAccess_Settings::get( 'toolbar', 'statement_url' ); if ( '' !== $explicit ) { return $explicit; } $s = self::get(); if ( '' !== $s['uustatus_url'] ) { return $s['uustatus_url']; } if ( $s['page_id'] && 'publish' === get_post_status( $s['page_id'] ) ) { return (string) get_permalink( $s['page_id'] ); } return ''; } /** * Contact address for accessibility feedback (only once a statement exists). * * @return string */ public static function contact_email() { $s = get_option( self::OPTION, array() ); return is_array( $s ) && ! empty( $s['email'] ) && ! empty( $s['page_id'] ) ? (string) $s['email'] : ''; } /** * Small footer link to the statement. */ public static function footer_link() { $s = self::get(); $url = self::public_url(); if ( ! $s['footer_link'] || '' === $url ) { return; } $label = 'nb' === $s['language'] ? 'Tilgjengelighetserklæring' : __( 'Accessibility statement', 'ariaccess' ); printf( '', esc_url( $url ), esc_html( $label ) ); } /** * Build the statement as block markup. * * @param array $s Statement data. * @return array [ title, content ] */ public static function build( $s ) { $nb = 'nb' === $s['language']; $org = '' !== $s['org'] ? $s['org'] : get_bloginfo( 'name' ); $site = '' !== $s['website'] ? $s['website'] : home_url( '/' ); $date = date_i18n( $nb ? 'j. F Y' : get_option( 'date_format' ), strtotime( $s['review_date'] ) ); $criteria = count( AriAccess_Rules::criteria( $s['standard'] ) ); $standard_text = array( 'no-private' => $nb ? sprintf( 'forskrift om universell utforming av informasjons- og kommunikasjonsteknologiske (IKT)-løsninger, som krever %d suksesskriterier i WCAG 2.0 på nivå A og AA', $criteria ) : sprintf( 'the Norwegian regulation on universal design of ICT, which requires %d WCAG 2.0 success criteria at level A and AA', $criteria ), 'no-public' => $nb ? sprintf( 'forskrift om universell utforming av IKT-løsninger for offentlige virksomheter, som krever %d suksesskriterier i WCAG 2.1 på nivå A og AA', $criteria ) : sprintf( 'the Norwegian regulation on universal design of ICT for public bodies, which requires %d WCAG 2.1 success criteria at level A and AA', $criteria ), 'wcag21aa' => $nb ? 'WCAG 2.1 nivå AA (EN 301 549)' : 'WCAG 2.1 level AA (EN 301 549)', 'wcag22aa' => $nb ? 'WCAG 2.2 nivå AA' : 'WCAG 2.2 level AA', ); $status_text = array( 'full' => $nb ? 'Nettstedet oppfyller kravene.' : 'This website fully conforms to the standard.', 'partial' => $nb ? 'Nettstedet oppfyller kravene delvis. Det betyr at noen deler ikke er universelt utformet ennå. Disse er listet opp nedenfor.' : 'This website partially conforms to the standard. Some parts are not yet accessible; they are listed below.', 'none' => $nb ? 'Nettstedet oppfyller ikke kravene ennå. Vi arbeider med å rette feilene som er listet opp nedenfor.' : 'This website does not yet conform to the standard. We are working on the problems listed below.', ); $method_text = array( 'self' => $nb ? 'Vi har vurdert nettstedet selv, med automatiske tester og manuell kontroll.' : 'We assessed the website ourselves, using automated tests and manual checks.', 'external' => $nb ? 'Nettstedet er vurdert av en ekstern fagperson.' : 'The website was assessed by an external accessibility specialist.', 'mixed' => $nb ? 'Vi har vurdert nettstedet selv og fått hjelp av en ekstern fagperson.' : 'We assessed the website ourselves with help from an external accessibility specialist.', ); $p = function ( $text ) { return "\n

" . $text . "

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

" . esc_html( $text ) . "

\n\n\n"; }; $ul = function ( $items ) { $out = "\n\n\n\n"; }; $c = ''; $c .= $p( $nb ? sprintf( '%s ønsker at alle skal kunne bruke %s, uavhengig av funksjonsevne. Denne erklæringen forteller hvordan nettstedet oppfyller kravene til universell utforming, hva som ikke fungerer ennå, og hvordan du kan gi oss beskjed.', esc_html( $org ), '' . esc_html( wp_parse_url( $site, PHP_URL_HOST ) ) . '' ) : sprintf( '%s wants everyone to be able to use %s, whatever their abilities. This statement explains how the website meets accessibility requirements, what does not work yet, and how to tell us about problems.', esc_html( $org ), '' . esc_html( wp_parse_url( $site, PHP_URL_HOST ) ) . '' ) ); $c .= $h( $nb ? 'Hvilke krav vi følger' : 'Standard we follow' ); $c .= $p( ( $nb ? 'Vi måler nettstedet mot ' : 'We measure the website against ' ) . esc_html( $standard_text[ $s['standard'] ] ) . '. ' . esc_html( $status_text[ $s['status'] ] ) ); $issues = array_filter( array_map( 'trim', preg_split( '/\r\n|\r|\n/', (string) $s['known_issues'] ) ) ); if ( $issues ) { $c .= $h( $nb ? 'Dette fungerer ikke ennå' : 'Known problems' ); $c .= $ul( $issues ); } if ( '' !== trim( $s['alternatives'] ) ) { $c .= $h( $nb ? 'Andre måter å få innholdet på' : 'Other ways to get the content' ); $c .= $p( nl2br( esc_html( $s['alternatives'] ) ) ); } $c .= $h( $nb ? 'Slik vurderte vi nettstedet' : 'How we assessed the website' ); $c .= $p( esc_html( $method_text[ $s['method'] ] ) . ' ' . esc_html( $nb ? 'Automatiske tester finner bare en del av problemene, så vi kontrollerer også med tastatur og skjermleser.' : 'Automated tests find only some problems, so we also check with a keyboard and a screen reader.' ) . ' ' . esc_html( ( $nb ? 'Sist vurdert: ' : 'Last reviewed: ' ) . $date . '.' ) ); $c .= $h( $nb ? 'Gi oss beskjed' : 'Tell us about a problem' ); $contact = array(); if ( '' !== $s['email'] ) { $contact[] = ( $nb ? 'e-post: ' : 'email: ' ) . '' . esc_html( $s['email'] ) . ''; } if ( '' !== $s['phone'] ) { $contact[] = ( $nb ? 'telefon: ' : 'phone: ' ) . esc_html( $s['phone'] ); } $c .= $p( ( $nb ? 'Finner du noe som ikke fungerer for deg, eller trenger du innholdet i en annen form? Kontakt oss på ' : 'If something does not work for you, or you need content in another format, contact us by ' ) . implode( $nb ? ' eller ' : ' or ', $contact ) . '. ' . esc_html( sprintf( $nb ? 'Vi svarer innen %d virkedager.' : 'We reply within %d working days.', (int) $s['response_days'] ) ) ); if ( $nb ) { $c .= $h( 'Klage' ); $c .= $p( 'Hvis du ikke får svar, eller ikke er fornøyd med svaret, kan du melde fra til Tilsynet for universell utforming av IKT (Uutilsynet) på uutilsynet.no.' ); } else { $c .= $h( 'Enforcement' ); $c .= $p( 'If you do not get an answer, or are not satisfied with it, you can contact the national enforcement body. In Norway this is the Authority for Universal Design of ICT (Uutilsynet), uutilsynet.no.' ); } if ( '' !== $s['uustatus_url'] ) { $c .= $p( ( $nb ? 'Den offisielle erklæringen vår ligger på ' : 'Our official statement is published at ' ) . 'uustatus.no.' ); } $title = $nb ? 'Tilgjengelighetserklæring' : 'Accessibility statement'; return array( $title, $c ); } /** * Create or update the statement page (kept as a draft until the owner publishes it). * * @param bool $publish Publish straight away. * @return int Page id. */ public static function write_page( $publish = false ) { $s = self::get(); list( $title, $body ) = self::build( $s ); $existing = $s['page_id'] ? get_post( $s['page_id'] ) : null; $data = array( 'post_title' => $title, 'post_content' => $body, 'post_type' => 'page', ); if ( $existing && 'trash' !== $existing->post_status ) { $data['ID'] = $existing->ID; $data['post_status'] = $publish ? 'publish' : $existing->post_status; $id = wp_update_post( wp_slash( $data ), true ); } else { $data['post_status'] = $publish ? 'publish' : 'draft'; $id = wp_insert_post( wp_slash( $data ), true ); } if ( is_wp_error( $id ) ) { return 0; } $s['page_id'] = (int) $id; update_option( self::OPTION, $s ); return (int) $id; } }