getElementsByTagName( 'meta' ) ) as $m ) { if ( 'viewport' !== strtolower( (string) $m->getAttribute( 'name' ) ) ) { continue; } $parts = array_filter( array_map( 'trim', explode( ',', (string) $m->getAttribute( 'content' ) ) ), 'strlen' ); $keep = array(); foreach ( $parts as $p ) { $kv = array_map( 'trim', explode( '=', $p, 2 ) ); $k = strtolower( $kv[0] ); $v = isset( $kv[1] ) ? strtolower( $kv[1] ) : ''; if ( 'user-scalable' === $k && in_array( $v, array( 'no', '0' ), true ) ) { continue; } if ( 'maximum-scale' === $k && is_numeric( $v ) && (float) $v < 5 ) { continue; } $keep[] = $p; } if ( count( $keep ) !== count( $parts ) ) { $m->setAttribute( 'content', implode( ', ', $keep ) ); $changed = true; } } return $changed; } /** No
and no role="main": mark the builder's content wrapper. Returns the main element (existing or marked) or null. Filter: scanpoof_fix_main. */ function scanpoof_fix_main( DOMDocument $dom, &$changed ) { $xp = new DOMXPath( $dom ); $main = $xp->query( '//main | //*[@role="main"]' )->item( 0 ); if ( $main ) { return $main; } foreach ( scanpoof_main_candidates() as $sel ) { $q = '#' === $sel[0] ? '//*[@id="' . substr( $sel, 1 ) . '"]' : "//*[contains(concat(' ', normalize-space(@class), ' '), ' " . substr( $sel, 1 ) . " ')]"; $el = $xp->query( $q )->item( 0 ); // Never mark the header, the footer or a navigation block as the main content. if ( $el && ! in_array( strtolower( $el->nodeName ), array( 'header', 'footer', 'nav', 'aside', 'body', 'html' ), true ) ) { $el->setAttribute( 'role', 'main' ); $el->setAttribute( 'data-sp-fix', 'main' ); $changed = true; return $el; } } return null; } /** No skip link: add one as the first thing in , pointing at the main content. Hidden until it has keyboard focus. Filter: scanpoof_fix_skip_link. */ function scanpoof_fix_skip_link( DOMDocument $dom, $main ) { $body = $dom->getElementsByTagName( 'body' )->item( 0 ); if ( ! $body || ! $main ) { return false; } $xp = new DOMXPath( $dom ); // An existing skip link: an in-page link near the top whose text says skip / jump to content. foreach ( $xp->query( '//a[starts-with(@href, "#")]' ) as $a ) { if ( preg_match( '/\b(skip|jump)\b/i', $a->textContent . ' ' . $a->getAttribute( 'aria-label' ) ) ) { return false; } } $id = (string) $main->getAttribute( 'id' ); if ( '' === $id ) { $id = 'scanpoof-main'; $main->setAttribute( 'id', $id ); } if ( ! $main->hasAttribute( 'tabindex' ) ) { $main->setAttribute( 'tabindex', '-1' ); // so the jump also moves keyboard focus } $a = $dom->createElement( 'a' ); $a->setAttribute( 'href', '#' . $id ); $a->setAttribute( 'class', 'scanpoof-skip' ); $a->setAttribute( 'data-sp-fix', 'skip' ); $a->appendChild( $dom->createTextNode( function_exists( '__' ) ? __( 'Skip to content', 'scanpoof' ) : 'Skip to content' ) ); $body->insertBefore( $a, $body->firstChild ); return true; } /** Inline letter/word/line spacing with !important: keep the value, drop the !important. Filter: scanpoof_fix_inline_spacing. */ function scanpoof_fix_inline_spacing( DOMDocument $dom ) { $changed = false; $xp = new DOMXPath( $dom ); foreach ( $xp->query( '//*[@style]' ) as $el ) { $s = (string) $el->getAttribute( 'style' ); $new = preg_replace( '/((?:letter-spacing|word-spacing|line-height)\s*:[^;!]*?)\s*!\s*important/i', '$1', $s ); if ( is_string( $new ) && $new !== $s ) { $el->setAttribute( 'style', $new ); $changed = true; } } return $changed; } /** All structure fixes, in a safe order. Returns whether anything changed. */ function scanpoof_fix_structure( DOMDocument $dom ) { $changed = false; $f = function ( $name ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- all callers pass scanpoof-prefixed names. return function_exists( 'apply_filters' ) ? apply_filters( $name, true ) : true; }; if ( $f( 'scanpoof_fix_zoom' ) && scanpoof_fix_zoom( $dom ) ) { $changed = true; } $main = null; if ( $f( 'scanpoof_fix_main' ) ) { $main = scanpoof_fix_main( $dom, $changed ); } if ( $f( 'scanpoof_fix_skip_link' ) && scanpoof_fix_skip_link( $dom, $main ) ) { $changed = true; } if ( $f( 'scanpoof_fix_inline_spacing' ) && scanpoof_fix_inline_spacing( $dom ) ) { $changed = true; } return $changed; }