From 19d613fed256c05c24b351af42731d98e8d39adf Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 30 Sep 2011 06:22:29 +0000 Subject: [PATCH] Merge the four media buttons into one. * Lots of red. * Removes the type_url_form_\$type filter, where \$type is audio, video, file, or image. * Replacement filter is a generic type_url_form_media filter for the new unified form. * Some functions have gone missing; they'll be restored and deprecated in a later pass. see #17578. git-svn-id: https://develop.svn.wordpress.org/trunk@18831 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/css/media.dev.css | 15 ++ wp-admin/includes/media.php | 397 ++++++++---------------------------- 2 files changed, 97 insertions(+), 315 deletions(-) diff --git a/wp-admin/css/media.dev.css b/wp-admin/css/media.dev.css index fdad81f706..c68976ec84 100644 --- a/wp-admin/css/media.dev.css +++ b/wp-admin/css/media.dev.css @@ -362,3 +362,18 @@ h4.media-sub-title { margin-right: 25px; } +p.media-types { + margin: 1em; +} + +tr.not-image { + display: none; +} + +table.not-image tr.not-image { + display: table-row; +} + +table.not-image tr.image-only { + display: none; +} \ No newline at end of file diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index c5edf6edb2..7b15606f6c 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -374,21 +374,7 @@ document.body.className = c; * @since 2.5.0 */ function media_buttons($editor_id = 'content') { - $out = ''; - - if ( is_multisite() ) - $_buttons = get_site_option('mu_media_buttons'); - else - $_buttons = array( 'image' => true, 'video' => true, 'audio' => true ); - - if ( !empty($_buttons['image']) ) - $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image', $editor_id); - if ( !empty($_buttons['video']) ) - $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video', $editor_id); - if ( !empty($_buttons['audio']) ) - $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio', $editor_id); - - $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media', $editor_id); + $out = _media_button(__('Add Media'), 'images/media-button-video.gif?ver=20100531', 'media', $editor_id); $context = apply_filters('media_buttons_context', __('Upload/Insert %s')); @@ -529,20 +515,37 @@ function media_upload_image() { } if ( !empty($_POST['insertonlybutton']) ) { - $alt = $align = ''; - $src = $_POST['insertonly']['src']; if ( !empty($src) && !strpos($src, '://') ) $src = "http://$src"; - $alt = esc_attr($_POST['insertonly']['alt']); - if ( isset($_POST['insertonly']['align']) ) { - $align = esc_attr($_POST['insertonly']['align']); - $class = " class='align$align'"; - } - if ( !empty($src) ) - $html = "$alt"; - $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align); + if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { + $title = esc_attr($_POST['insertonly']['title']); + if ( empty($title) ) + $title = esc_attr( basename($src) ); + + if ( !empty($title) && !empty($src) ) + $html = "$title"; + + $type = 'file'; + if ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) && $ext_type = wp_ext2type( $ext ) + && ( 'audio' == $ext_type || 'video' == $ext_type ) ) + $type = $ext_type; + + $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title ); + } else { + $align = ''; + $alt = esc_attr($_POST['insertonly']['alt']); + if ( isset($_POST['insertonly']['align']) ) { + $align = esc_attr($_POST['insertonly']['align']); + $class = " class='align$align'"; + } + if ( !empty($src) ) + $html = "$alt"; + + $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); + } + return media_send_to_editor($html); } @@ -560,8 +563,12 @@ function media_upload_image() { return media_upload_gallery(); } - if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) - return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id ); + if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { + $type = 'image'; + if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) + $type = $_GET['type']; + return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); + } return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); } @@ -612,180 +619,6 @@ function media_sideload_image($file, $post_id, $desc = null) { } } -/** - * {@internal Missing Short Description}} - * - * @since 2.5.0 - * - * @return unknown - */ -function media_upload_audio() { - $errors = array(); - $id = 0; - - if ( isset($_POST['html-upload']) && !empty($_FILES) ) { - check_admin_referer('media-form'); - // Upload File button was clicked - $id = media_handle_upload('async-upload', $_REQUEST['post_id']); - unset($_FILES); - if ( is_wp_error($id) ) { - $errors['upload_error'] = $id; - $id = false; - } - } - - if ( !empty($_POST['insertonlybutton']) ) { - $href = $_POST['insertonly']['href']; - if ( !empty($href) && !strpos($href, '://') ) - $href = "http://$href"; - - $title = esc_attr($_POST['insertonly']['title']); - if ( empty($title) ) - $title = esc_attr( basename($href) ); - - if ( !empty($title) && !empty($href) ) - $html = "$title"; - - $html = apply_filters('audio_send_to_editor_url', $html, $href, $title); - - return media_send_to_editor($html); - } - - if ( !empty($_POST) ) { - $return = media_upload_form_handler(); - - if ( is_string($return) ) - return $return; - if ( is_array($return) ) - $errors = $return; - } - - if ( isset($_POST['save']) ) { - $errors['upload_notice'] = __('Saved.'); - return media_upload_gallery(); - } - - if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) - return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id ); - - return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id ); -} - -/** - * {@internal Missing Short Description}} - * - * @since 2.5.0 - * - * @return unknown - */ -function media_upload_video() { - $errors = array(); - $id = 0; - - if ( isset($_POST['html-upload']) && !empty($_FILES) ) { - check_admin_referer('media-form'); - // Upload File button was clicked - $id = media_handle_upload('async-upload', $_REQUEST['post_id']); - unset($_FILES); - if ( is_wp_error($id) ) { - $errors['upload_error'] = $id; - $id = false; - } - } - - if ( !empty($_POST['insertonlybutton']) ) { - $href = $_POST['insertonly']['href']; - if ( !empty($href) && !strpos($href, '://') ) - $href = "http://$href"; - - $title = esc_attr($_POST['insertonly']['title']); - if ( empty($title) ) - $title = esc_attr( basename($href) ); - - if ( !empty($title) && !empty($href) ) - $html = "$title"; - - $html = apply_filters('video_send_to_editor_url', $html, $href, $title); - - return media_send_to_editor($html); - } - - if ( !empty($_POST) ) { - $return = media_upload_form_handler(); - - if ( is_string($return) ) - return $return; - if ( is_array($return) ) - $errors = $return; - } - - if ( isset($_POST['save']) ) { - $errors['upload_notice'] = __('Saved.'); - return media_upload_gallery(); - } - - if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) - return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id ); - - return wp_iframe( 'media_upload_type_form', 'video', $errors, $id ); -} - -/** - * {@internal Missing Short Description}} - * - * @since 2.5.0 - * - * @return unknown - */ -function media_upload_file() { - $errors = array(); - $id = 0; - - if ( isset($_POST['html-upload']) && !empty($_FILES) ) { - check_admin_referer('media-form'); - // Upload File button was clicked - $id = media_handle_upload('async-upload', $_REQUEST['post_id']); - unset($_FILES); - if ( is_wp_error($id) ) { - $errors['upload_error'] = $id; - $id = false; - } - } - - if ( !empty($_POST['insertonlybutton']) ) { - $href = $_POST['insertonly']['href']; - if ( !empty($href) && !strpos($href, '://') ) - $href = "http://$href"; - - $title = esc_attr($_POST['insertonly']['title']); - if ( empty($title) ) - $title = basename($href); - if ( !empty($title) && !empty($href) ) - $html = "$title"; - $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title); - return media_send_to_editor($html); - } - - if ( !empty($_POST) ) { - $return = media_upload_form_handler(); - - if ( is_string($return) ) - return $return; - if ( is_array($return) ) - $errors = $return; - } - - if ( isset($_POST['save']) ) { - $errors['upload_notice'] = __('Saved.'); - return media_upload_gallery(); - } - - if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) - return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id ); - - return wp_iframe( 'media_upload_type_form', 'file', $errors, $id ); -} - /** * {@internal Missing Short Description}} * @@ -1607,23 +1440,22 @@ if ( $id ) { * @param unknown_type $errors * @param unknown_type $id */ -function media_upload_type_url_form($type = 'file', $errors = null, $id = null) { +function media_upload_type_url_form($type = null, $errors = null, $id = null) { + if ( null === $type ) + $type = 'image'; + media_upload_header(); $post_id = intval($_REQUEST['post_id']); $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); - - $callback = "type_url_form_$type"; ?>
- -

- +
+ @@ -2045,12 +1882,20 @@ function type_url_form_image() { if ( empty($default_align) ) $default_align = 'none'; + if ( 'image' == $default_view ) { + $view = 'image-only'; + $table_class = ''; + } else { + $view = $table_class = 'not-image'; + } + return ' -

' . __('Insert an image from another web site') . '

- +

' . __('Insert media from another web site') . '

+

   

+
@@ -2058,13 +1903,15 @@ function type_url_form_image() { - + + + @@ -2072,7 +1919,7 @@ function type_url_form_image() {

' . __('Alt text for the image, e.g. “The Mona Lisa”') . '

' . $caption . ' - + - + @@ -2096,103 +1943,23 @@ function type_url_form_image() {

' . __('Enter a link URL or click above for presets.') . '

- ' . _insert_into_post_button('image') . ' + + + + + + + +
- + *
- + *

' . __('Link text, e.g. “Ransom Demands (PDF)”') . '

@@ -2086,7 +1933,7 @@ function type_url_form_image() {
+ +
+ ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . ' +
'; } -/** - * {@internal Missing Short Description}} - * - * @since 2.7.0 - * - * @return unknown - */ -function type_url_form_audio() { - return ' - - - - - - - - - - - ' . _insert_into_post_button('audio') . ' -
- - * -
- - * -
' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '
-'; -} - -/** - * {@internal Missing Short Description}} - * - * @since 2.7.0 - * - * @return unknown - */ -function type_url_form_video() { - return ' - - - - - - - - - - - ' . _insert_into_post_button('video') . ' -
- - * -
- - * -
' . __('Link text, e.g. “Lucy on YouTube”') . '
-'; -} - -/** - * {@internal Missing Short Description}} - * - * @since 2.7.0 - * - * @return unknown - */ -function type_url_form_file() { - return ' - - - - - - - - - - - ' . _insert_into_post_button('file') . ' -
- - * -
- - * -
' . __('Link text, e.g. “Ransom Demands (PDF)”') . '
-'; -} - - function _insert_into_post_button($type) { if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') ) return ''; @@ -2240,9 +2007,9 @@ add_filter('async_upload_video', 'get_media_item', 10, 2); add_filter('async_upload_file', 'get_media_item', 10, 2); add_action('media_upload_image', 'media_upload_image'); -add_action('media_upload_audio', 'media_upload_audio'); -add_action('media_upload_video', 'media_upload_video'); -add_action('media_upload_file', 'media_upload_file'); +add_action('media_upload_audio', 'media_upload_image'); +add_action('media_upload_video', 'media_upload_image'); +add_action('media_upload_file', 'media_upload_image'); add_filter('media_upload_gallery', 'media_upload_gallery');