]*)>(.*?)#is', array( __CLASS__, 'placeholder' ), $html ); return null === $out ? $html : $out; } /** * Embed type for an iframe src. * * @param string $src URL. * @return string map|youtube|vimeo|'' */ public static function type( $src ) { $s = strtolower( html_entity_decode( $src, ENT_QUOTES | ENT_HTML5 ) ); if ( preg_match( '#^(https?:)?//(www\.)?(youtube\.com|youtube-nocookie\.com)/embed/#', $s ) ) { return 'youtube'; } if ( preg_match( '#^(https?:)?//player\.vimeo\.com/#', $s ) ) { return 'vimeo'; } if ( preg_match( '#^(https?:)?//(www\.|maps\.)?google\.[a-z.]+/maps#', $s ) ) { return 'map'; } return ''; } /** * Build the placeholder for one iframe. * * @param array $m Regex match. * @return string */ public static function placeholder( $m ) { $attrs = $m[1]; if ( false !== stripos( $attrs, 'data-goconsent-skip' ) ) { return $m[0]; } $src = Classifier::attr( $attrs, 'src' ); $type = $src ? self::type( $src ) : ''; if ( ! $type ) { return $m[0]; } $iframe = $m[0]; if ( 'youtube' === $type ) { $iframe = preg_replace( '#(https?:)?//(www\.)?youtube\.com/embed/#i', 'https://www.youtube-nocookie.com/embed/', $iframe ); } $w = Classifier::attr( $attrs, 'width' ); $h = Classifier::attr( $attrs, 'height' ); $ratio = ( ctype_digit( (string) $w ) && ctype_digit( (string) $h ) && (int) $h > 0 ) ? ( (int) $w . ' / ' . (int) $h ) : ( 'map' === $type ? '4 / 3' : '16 / 9' ); $max = ctype_digit( (string) $w ) ? 'max-width:' . (int) $w . 'px;' : ''; $title = Classifier::attr( $attrs, 'title' ); if ( 'map' === $type ) { $provider = 'Google Maps'; $label = __( 'Load map', 'goconsent' ); $what = __( 'map', 'goconsent' ); $open = ''; $query = wp_parse_url( html_entity_decode( $src, ENT_QUOTES | ENT_HTML5 ), PHP_URL_QUERY ); if ( $query ) { parse_str( $query, $qs ); if ( ! empty( $qs['q'] ) && is_string( $qs['q'] ) ) { $open = 'https://www.google.com/maps/search/?api=1&query=' . rawurlencode( $qs['q'] ); } } } else { $provider = 'youtube' === $type ? 'YouTube' : 'Vimeo'; $label = __( 'Load video', 'goconsent' ); $what = __( 'video', 'goconsent' ); $open = ''; } /* translators: 1: "map" or "video", 2: provider name. */ $text = sprintf( __( 'This %1$s is provided by %2$s. Loading it shares your IP address with %2$s and may set their cookies.', 'goconsent' ), $what, $provider ); $html = '
'; $html .= '
'; if ( $title ) { $html .= '

' . esc_html( $title ) . '

'; } $html .= '

' . esc_html( $text ) . '

'; $html .= '

'; if ( $open ) { $html .= '' . esc_html__( 'Open in Google Maps', 'goconsent' ) . ' ' . esc_html__( '(opens in a new tab)', 'goconsent' ) . ''; } $html .= '

'; $html .= ''; $html .= '
'; return $html; } }