WordPress.org

Make WordPress Core

Ticket #23622: 23622.diff

File 23622.diff, 3.2 KB (added by Otto42, 9 years ago)

Add Google Maps and Drive support for embeds

  • wp-includes/media.php

     
    10831083        if ( ! apply_filters( 'load_default_embeds', true ) )
    10841084                return;
    10851085        wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
     1086        wp_embed_register_handler( 'googlemaps', '#https?://maps.google.com/(maps)?.+#i', 'wp_embed_handler_googlemaps' );
     1087        wp_embed_register_handler( 'googledocs', '#https?://docs.google.com/(document|spreadsheet|presentation)/.*#i', 'wp_embed_handler_googledrive' );
     1088
    10861089}
    10871090
    10881091/**
     
    11101113}
    11111114
    11121115/**
     1116 * The Google Maps embed handler callback. Google Maps does not support oEmbed.
     1117 *
     1118 * @see WP_Embed::register_handler()
     1119 * @see WP_Embed::shortcode()
     1120 *
     1121 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1122 * @param array $attr Embed attributes.
     1123 * @param string $url The original URL that was matched by the regex.
     1124 * @param array $rawattr The original unmodified attributes.
     1125 * @return string The embed HTML.
     1126 */
     1127function wp_embed_handler_googlemaps( $matches, $attr, $url, $rawattr ) {
     1128        if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
     1129                $width  = (int) $rawattr['width'];
     1130                $height = (int) $rawattr['height'];
     1131        } else {
     1132                list( $width, $height ) = wp_expand_dimensions( 425, 326, $attr['width'], $attr['height'] );
     1133        }
     1134        return apply_filters( 'embed_googlemaps', "<iframe width='{$width}' height='{$height}' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='{$url}&output=embed'></iframe>" );
     1135}
     1136
     1137/**
     1138 * The Google Drive embed handler callback. Google Drive does not support oEmbed.
     1139 * Handles documents, spreadsheets, and presentations from Google Drive.
     1140 *
     1141 * @see WP_Embed::register_handler()
     1142 * @see WP_Embed::shortcode()
     1143 *
     1144 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1145 * @param array $attr Embed attributes.
     1146 * @param string $url The original URL that was matched by the regex.
     1147 * @param array $rawattr The original unmodified attributes.
     1148 * @return string The embed HTML.
     1149 */
     1150function wp_embed_handler_googledrive( $matches, $attr, $url, $rawattr ) {
     1151        if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
     1152                $width  = (int) $rawattr['width'];
     1153                $height = (int) $rawattr['height'];
     1154        } else {
     1155                list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] );
     1156        }
     1157       
     1158        $extra = '';
     1159        if ( $matches[1] == 'spreadsheet' ) {
     1160                $url .= '&widget=true';
     1161        } elseif ( $matches[1] == 'document' ) {
     1162                $url .= '?embedded=true';
     1163        } elseif ( $matches[1] == 'presentation' ) {
     1164                $url = str_replace( '/pub', '/embed', $url);
     1165                $extra = 'allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"';
     1166        }
     1167
     1168        return apply_filters( 'embed_googledrive', "<iframe width='{$width}' height='{$height}' frameborder='0' src='{$url}' {$extra}></iframe>" );
     1169}
     1170
     1171/**
    11131172 * Converts a shorthand byte value to an integer byte value.
    11141173 *
    11151174 * @since 2.3.0