WordPress.org

Make WordPress Core

Changeset 24000


Ignore:
Timestamp:
04/16/2013 11:06:31 AM (9 years ago)
Author:
SergeyBiryukov
Message:
  • Add start/end markers to the regex patterns in audio and video embed handlers.
  • Move the handler functions registration to wp_maybe_load_embeds().
  • Rename both functions to match the wp_embed_handler_* pattern.
  • Move the functions closer to wp_embed_handler_googlevideo().

props kovshenin. fixes #24092.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r23992 r24000  
    13261326        return;
    13271327    wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
     1328    wp_embed_register_handler( 'audio', '#^https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')$#i', apply_filters( 'wp_audio_embed_handler', 'wp_embed_handler_audio' ), 9999 );
     1329    wp_embed_register_handler( 'video', '#^https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')$#i', apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' ), 9999 );
    13281330}
    13291331
     
    13501352
    13511353    return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
     1354}
     1355
     1356/**
     1357 * Audio embed handler callback.
     1358 *
     1359 * @since 3.6.0
     1360 *
     1361 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1362 * @param array $attr Embed attributes.
     1363 * @param string $url The original URL that was matched by the regex.
     1364 * @param array $rawattr The original unmodified attributes.
     1365 * @return string The embed HTML.
     1366 */
     1367function wp_embed_handler_audio( $matches, $attr, $url, $rawattr ) {
     1368    $audio = $url;
     1369    if ( shortcode_exists( 'audio' ) )
     1370        $audio = do_shortcode( '[audio src="' . $url . '" /]' );
     1371    return apply_filters( 'wp_embed_handler_audio', $audio, $attr, $url, $rawattr );
     1372}
     1373
     1374/**
     1375 * Video embed handler callback.
     1376 *
     1377 * @since 3.6.0
     1378 *
     1379 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     1380 * @param array $attr Embed attributes.
     1381 * @param string $url The original URL that was matched by the regex.
     1382 * @param array $rawattr The original unmodified attributes.
     1383 * @return string The embed HTML.
     1384 */
     1385function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) {
     1386    $dimensions = '';
     1387    $video = $url;
     1388    if ( shortcode_exists( 'video' ) ) {
     1389        if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
     1390            $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
     1391            $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
     1392        } elseif ( strstr( $url, home_url() ) ) {
     1393            $id = attachment_url_to_postid( $url );
     1394            if ( ! empty( $id ) ) {
     1395                $meta = wp_get_attachment_metadata( $id );
     1396                if ( ! empty( $meta['width'] ) )
     1397                    $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] );
     1398                if ( ! empty( $meta['height'] ) )
     1399                    $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] );
     1400            }
     1401        }
     1402        $video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
     1403    }
     1404    return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr );
    13521405}
    13531406
     
    19962049
    19972050/**
    1998  * Audio embed handler callback.
    1999  *
    2000  * @since 3.6.0
    2001  *
    2002  * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    2003  * @param array $attr Embed attributes.
    2004  * @param string $url The original URL that was matched by the regex.
    2005  * @param array $rawattr The original unmodified attributes.
    2006  * @return string The embed HTML.
    2007  */
    2008 function wp_audio_embed( $matches, $attr, $url, $rawattr ) {
    2009     $audio = $url;
    2010     if ( shortcode_exists( 'audio' ) )
    2011         $audio = do_shortcode( '[audio src="' . $url . '" /]' );
    2012     return apply_filters( 'wp_audio_embed', $audio, $attr, $url, $rawattr );
    2013 }
    2014 wp_embed_register_handler( 'wp_audio_embed', '#https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')#i', apply_filters( 'wp_audio_embed_handler', 'wp_audio_embed' ), 9999 );
    2015 
    2016 /**
    2017  * Video embed handler callback.
    2018  *
    2019  * @since 3.6.0
    2020  *
    2021  * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
    2022  * @param array $attr Embed attributes.
    2023  * @param string $url The original URL that was matched by the regex.
    2024  * @param array $rawattr The original unmodified attributes.
    2025  * @return string The embed HTML.
    2026  */
    2027 function wp_video_embed( $matches, $attr, $url, $rawattr ) {
    2028     $dimensions = '';
    2029     $video = $url;
    2030     if ( shortcode_exists( 'video' ) ) {
    2031         if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) {
    2032             $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] );
    2033             $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] );
    2034         } elseif ( strstr( $url, home_url() ) ) {
    2035             $id = attachment_url_to_postid( $url );
    2036             if ( ! empty( $id ) ) {
    2037                 $meta = wp_get_attachment_metadata( $id );
    2038                 if ( ! empty( $meta['width'] ) )
    2039                     $dimensions .= sprintf( 'width="%d" ', (int) $meta['width'] );
    2040                 if ( ! empty( $meta['height'] ) )
    2041                     $dimensions .= sprintf( 'height="%d" ', (int) $meta['height'] );
    2042             }
    2043         }
    2044         $video = do_shortcode( '[video ' . $dimensions . 'src="' . $url . '" /]' );
    2045     }
    2046     return apply_filters( 'wp_video_embed', $video, $attr, $url, $rawattr );
    2047 }
    2048 wp_embed_register_handler( 'wp_video_embed', '#https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')#i', apply_filters( 'wp_video_embed_handler', 'wp_video_embed' ), 9999 );
    2049 
    2050 /**
    20512051 * Return suitable HTML code for output based on the content related to the global $post
    20522052 * If found, remove the content from the @global $post's post_content field
Note: See TracChangeset for help on using the changeset viewer.