Make WordPress Core


Ignore:
Timestamp:
09/30/2011 06:22:29 AM (15 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

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

    r18823 r18831  
    375375 */
    376376function media_buttons($editor_id = 'content') {
    377         $out = '';
    378 
    379         if ( is_multisite() )
    380                 $_buttons = get_site_option('mu_media_buttons');
    381         else
    382                 $_buttons = array( 'image' => true, 'video' => true, 'audio' => true );
    383 
    384         if ( !empty($_buttons['image']) )
    385                 $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image', $editor_id);
    386         if ( !empty($_buttons['video']) )
    387                 $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video', $editor_id);
    388         if ( !empty($_buttons['audio']) )
    389                 $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio', $editor_id);
    390 
    391         $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media', $editor_id);
     377        $out = _media_button(__('Add Media'), 'images/media-button-video.gif?ver=20100531', 'media', $editor_id);
    392378
    393379        $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
    … …  
    530516
    531517        if ( !empty($_POST['insertonlybutton']) ) {
    532                 $alt = $align = '';
    533 
    534518                $src = $_POST['insertonly']['src'];
    535519                if ( !empty($src) && !strpos($src, '://') )
    536520                        $src = "http://$src";
    537                 $alt = esc_attr($_POST['insertonly']['alt']);
    538                 if ( isset($_POST['insertonly']['align']) ) {
    539                         $align = esc_attr($_POST['insertonly']['align']);
    540                         $class = " class='align$align'";
     521
     522                if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
     523                        $title = esc_attr($_POST['insertonly']['title']);
     524                        if ( empty($title) )
     525                                $title = esc_attr( basename($src) );
     526
     527                        if ( !empty($title) && !empty($src) )
     528                                $html = "<a href='" . esc_url($src) . "' >$title</a>";
     529
     530                        $type = 'file';
     531                        if ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) && $ext_type = wp_ext2type( $ext )
     532                                && ( 'audio' == $ext_type || 'video' == $ext_type ) )
     533                                        $type = $ext_type;
     534
     535                        $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title );
     536                } else {
     537                        $align = '';
     538                        $alt = esc_attr($_POST['insertonly']['alt']);
     539                        if ( isset($_POST['insertonly']['align']) ) {
     540                                $align = esc_attr($_POST['insertonly']['align']);
     541                                $class = " class='align$align'";
     542                        }
     543                        if ( !empty($src) )
     544                                $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
     545
     546                        $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
    541547                }
    542                 if ( !empty($src) )
    543                         $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
    544 
    545                 $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
     548
    546549                return media_send_to_editor($html);
    547550        }
    … …  
    561564        }
    562565
    563         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
    564                 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
     566        if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
     567                $type = 'image';
     568                if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
     569                        $type = $_GET['type'];
     570                return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
     571        }
    565572
    566573        return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
    … …  
    611618                return $html;
    612619        }
    613 }
    614 
    615 /**
    616  * {@internal Missing Short Description}}
    617  *
    618  * @since 2.5.0
    619  *
    620  * @return unknown
    621  */
    622 function media_upload_audio() {
    623         $errors = array();
    624         $id = 0;
    625 
    626         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    627                 check_admin_referer('media-form');
    628                 // Upload File button was clicked
    629                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    630                 unset($_FILES);
    631                 if ( is_wp_error($id) ) {
    632                         $errors['upload_error'] = $id;
    633                         $id = false;
    634                 }
    635         }
    636 
    637         if ( !empty($_POST['insertonlybutton']) ) {
    638                 $href = $_POST['insertonly']['href'];
    639                 if ( !empty($href) && !strpos($href, '://') )
    640                         $href = "http://$href";
    641 
    642                 $title = esc_attr($_POST['insertonly']['title']);
    643                 if ( empty($title) )
    644             $title = esc_attr( basename($href) );
    645 
    646                 if ( !empty($title) && !empty($href) )
    647             $html = "<a href='" . esc_url($href) . "' >$title</a>";
    648 
    649                 $html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
    650 
    651                 return media_send_to_editor($html);
    652         }
    653 
    654         if ( !empty($_POST) ) {
    655                 $return = media_upload_form_handler();
    656 
    657                 if ( is_string($return) )
    658                         return $return;
    659                 if ( is_array($return) )
    660                         $errors = $return;
    661         }
    662 
    663         if ( isset($_POST['save']) ) {
    664                 $errors['upload_notice'] = __('Saved.');
    665                 return media_upload_gallery();
    666         }
    667 
    668         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
    669                 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
    670 
    671         return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
    672 }
    673 
    674 /**
    675  * {@internal Missing Short Description}}
    676  *
    677  * @since 2.5.0
    678  *
    679  * @return unknown
    680  */
    681 function media_upload_video() {
    682         $errors = array();
    683         $id = 0;
    684 
    685         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    686                 check_admin_referer('media-form');
    687                 // Upload File button was clicked
    688                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    689                 unset($_FILES);
    690                 if ( is_wp_error($id) ) {
    691                         $errors['upload_error'] = $id;
    692                         $id = false;
    693                 }
    694         }
    695 
    696         if ( !empty($_POST['insertonlybutton']) ) {
    697                 $href = $_POST['insertonly']['href'];
    698                 if ( !empty($href) && !strpos($href, '://') )
    699                         $href = "http://$href";
    700 
    701                 $title = esc_attr($_POST['insertonly']['title']);
    702         if ( empty($title) )
    703             $title = esc_attr( basename($href) );
    704 
    705                 if ( !empty($title) && !empty($href) )
    706             $html = "<a href='" . esc_url($href) . "' >$title</a>";
    707 
    708                 $html = apply_filters('video_send_to_editor_url', $html, $href, $title);
    709 
    710                 return media_send_to_editor($html);
    711         }
    712 
    713         if ( !empty($_POST) ) {
    714                 $return = media_upload_form_handler();
    715 
    716                 if ( is_string($return) )
    717                         return $return;
    718                 if ( is_array($return) )
    719                         $errors = $return;
    720         }
    721 
    722         if ( isset($_POST['save']) ) {
    723                 $errors['upload_notice'] = __('Saved.');
    724                 return media_upload_gallery();
    725         }
    726 
    727         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
    728                 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
    729 
    730         return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
    731 }
    732 
    733 /**
    734  * {@internal Missing Short Description}}
    735  *
    736  * @since 2.5.0
    737  *
    738  * @return unknown
    739  */
    740 function media_upload_file() {
    741         $errors = array();
    742         $id = 0;
    743 
    744         if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
    745                 check_admin_referer('media-form');
    746                 // Upload File button was clicked
    747                 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
    748                 unset($_FILES);
    749                 if ( is_wp_error($id) ) {
    750                         $errors['upload_error'] = $id;
    751                         $id = false;
    752                 }
    753         }
    754 
    755         if ( !empty($_POST['insertonlybutton']) ) {
    756                 $href = $_POST['insertonly']['href'];
    757                 if ( !empty($href) && !strpos($href, '://') )
    758                         $href = "http://$href";
    759 
    760                 $title = esc_attr($_POST['insertonly']['title']);
    761                 if ( empty($title) )
    762                         $title = basename($href);
    763                 if ( !empty($title) && !empty($href) )
    764                         $html = "<a href='" . esc_url($href) . "' >$title</a>";
    765                 $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title);
    766                 return media_send_to_editor($html);
    767         }
    768 
    769         if ( !empty($_POST) ) {
    770                 $return = media_upload_form_handler();
    771 
    772                 if ( is_string($return) )
    773                         return $return;
    774                 if ( is_array($return) )
    775                         $errors = $return;
    776         }
    777 
    778         if ( isset($_POST['save']) ) {
    779                 $errors['upload_notice'] = __('Saved.');
    780                 return media_upload_gallery();
    781         }
    782 
    783         if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
    784                 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
    785 
    786         return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
    787620}
    788621
    … …  
    16081441 * @param unknown_type $id
    16091442 */
    1610 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
     1443function media_upload_type_url_form($type = null, $errors = null, $id = null) {
     1444        if ( null === $type )
     1445                $type = 'image';
     1446
    16111447        media_upload_header();
    16121448
    … …  
    16151451        $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
    16161452        $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    1617 
    1618         $callback = "type_url_form_$type";
    16191453?>
    16201454
    … …  
    16221456<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
    16231457<?php wp_nonce_field('media-form'); ?>
    1624 
    1625 <?php if ( is_callable($callback) ) { ?>
    16261458
    16271459<h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
    … …  
    16911523                var t = addExtImage, src = document.forms[0].src.value;
    16921524
    1693                 if ( ! src ) {
     1525                if ( ! src || jQuery('table.describe').hasClass('not-image') ) {
    16941526                        t.resetImageData();
    16951527                        return false;
    16961528                }
     1529
    16971530                document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />';
    16981531                t.preloadImg = new Image();
    … …  
    17021535        }
    17031536}
     1537
     1538jQuery(document).ready( function($) {
     1539        $('.media-types input').click( function() {
     1540                $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
     1541        });
     1542});
     1543
    17041544//]]>
    17051545</script>
    … …  
    17071547<div id="media-items">
    17081548<div class="media-item media-blank">
    1709 <?php echo apply_filters($callback, call_user_func($callback)); ?>
     1549<?php echo apply_filters( 'type_url_form_media', type_url_form_image( $type ) ); ?>
    17101550</div>
    17111551</div>
    17121552</form>
    17131553<?php
    1714         } else {
    1715                 wp_die( __('Unknown action.') );
    1716         }
    17171554}
    17181555
    … …  
    20281865 * @return unknown
    20291866 */
    2030 function type_url_form_image() {
     1867function type_url_form_image( $default_view = 'image' ) {
    20311868        if ( !apply_filters( 'disable_captions', '' ) ) {
    20321869                $caption = '
    2033                 <tr>
     1870                <tr class="image-only">
    20341871                        <th valign="top" scope="row" class="label">
    20351872                                <span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
    … …  
    20461883                $default_align = 'none';
    20471884
     1885        if ( 'image' == $default_view ) {
     1886                $view = 'image-only';
     1887                $table_class = '';
     1888        } else {
     1889                $view = $table_class = 'not-image';
     1890        }
     1891
    20481892        return '
    2049         <h4 class="media-sub-title">' . __('Insert an image from another web site') . '</h4>
    2050         <table class="describe"><tbody>
     1893        <h4 class="media-sub-title">' . __('Insert media from another web site') . '</h4>
     1894        <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Images' ) . '</label> &nbsp; &nbsp; <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Files' ) . '</label></p>
     1895        <table class="describe ' . $table_class . '"><tbody>
    20511896                <tr>
    20521897                        <th valign="top" scope="row" class="label" style="width:130px;">
    2053                                 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
     1898                                <span class="alignleft"><label for="src">' . __('URL') . '</label></span>
    20541899                                <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
    20551900                        </th>
    … …  
    20591904                <tr>
    20601905                        <th valign="top" scope="row" class="label">
    2061                                 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
     1906                                <span class="alignleft"><label for="title">' . __('Title') . '</label></span>
    20621907                                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    20631908                        </th>
    … …  
    20651910                </tr>
    20661911
    2067                 <tr>
     1912                <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
     1913
     1914                <tr class="image-only">
    20681915                        <th valign="top" scope="row" class="label">
    20691916                                <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
    … …  
    20731920                </tr>
    20741921                ' . $caption . '
    2075                 <tr class="align">
     1922                <tr class="align image-only">
    20761923                        <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
    20771924                        <td class="field">
    … …  
    20871934                </tr>
    20881935
    2089                 <tr>
     1936                <tr class="image-only">
    20901937                        <th valign="top" scope="row" class="label">
    20911938                                <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
    … …  
    20971944                        <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
    20981945                </tr>
    2099         ' . _insert_into_post_button('image') . '
     1946                <tr class="image-only">
     1947                        <td></td>
     1948                        <td>
     1949                                <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
     1950                        </td>
     1951                </tr>
     1952                <tr class="not-image">
     1953                        <td></td>
     1954                        <td>
     1955                                ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . '
     1956                        </td>
     1957                </tr>
    21001958        </tbody></table>
    21011959';
    21021960
    21031961}
    2104 
    2105 /**
    2106  * {@internal Missing Short Description}}
    2107  *
    2108  * @since 2.7.0
    2109  *
    2110  * @return unknown
    2111  */
    2112 function type_url_form_audio() {
    2113         return '
    2114         <table class="describe"><tbody>
    2115                 <tr>
    2116                         <th valign="top" scope="row" class="label">
    2117                                 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
    2118                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2119                         </th>
    2120                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
    2121                 </tr>
    2122                 <tr>
    2123                         <th valign="top" scope="row" class="label">
    2124                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
    2125                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2126                         </th>
    2127                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
    2128                 </tr>
    2129                 <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Still Alive by Jonathan Coulton&#8221;') . '</td></tr>
    2130         ' . _insert_into_post_button('audio') . '
    2131         </tbody></table>
    2132 ';
    2133 }
    2134 
    2135 /**
    2136  * {@internal Missing Short Description}}
    2137  *
    2138  * @since 2.7.0
    2139  *
    2140  * @return unknown
    2141  */
    2142 function type_url_form_video() {
    2143         return '
    2144         <table class="describe"><tbody>
    2145                 <tr>
    2146                         <th valign="top" scope="row" class="label">
    2147                                 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
    2148                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2149                         </th>
    2150                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
    2151                 </tr>
    2152                 <tr>
    2153                         <th valign="top" scope="row" class="label">
    2154                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
    2155                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2156                         </th>
    2157                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
    2158                 </tr>
    2159                 <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Lucy on YouTube&#8221;') . '</td></tr>
    2160         ' . _insert_into_post_button('video') . '
    2161         </tbody></table>
    2162 ';
    2163 }
    2164 
    2165 /**
    2166  * {@internal Missing Short Description}}
    2167  *
    2168  * @since 2.7.0
    2169  *
    2170  * @return unknown
    2171  */
    2172 function type_url_form_file() {
    2173         return '
    2174         <table class="describe"><tbody>
    2175                 <tr>
    2176                         <th valign="top" scope="row" class="label">
    2177                                 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
    2178                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2179                         </th>
    2180                         <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
    2181                 </tr>
    2182                 <tr>
    2183                         <th valign="top" scope="row" class="label">
    2184                                 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
    2185                                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    2186                         </th>
    2187                         <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
    2188                 </tr>
    2189                 <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</td></tr>
    2190         ' . _insert_into_post_button('file') . '
    2191         </tbody></table>
    2192 ';
    2193 }
    2194 
    21951962
    21961963function _insert_into_post_button($type) {
    … …  
    22412008
    22422009add_action('media_upload_image', 'media_upload_image');
    2243 add_action('media_upload_audio', 'media_upload_audio');
    2244 add_action('media_upload_video', 'media_upload_video');
    2245 add_action('media_upload_file', 'media_upload_file');
     2010add_action('media_upload_audio', 'media_upload_image');
     2011add_action('media_upload_video', 'media_upload_image');
     2012add_action('media_upload_file', 'media_upload_image');
    22462013
    22472014add_filter('media_upload_gallery', 'media_upload_gallery');
Note: See TracChangeset for help on using the changeset viewer.