Make WordPress Core

Ticket #24291: 24291.25.diff

File 24291.25.diff, 14.0 KB (added by markjaquith, 11 years ago)

bail after non-image uploads

  • wp-admin/admin-header.php

    $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0- 
    8585$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
    8686$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
    8787
     88if ( false !== $post_format = get_post_format() ) {
     89        if ( ! $post_format ) {
     90                $post_format = 'standard';
     91
     92                if ( ! empty( $_REQUEST['format'] ) && in_array( $_REQUEST['format'], get_post_format_slugs() ) )
     93                        $post_format = $_REQUEST['format'];
     94        }
     95
     96        $admin_body_class .= ' wp-format-' . $post_format;
     97}
     98
    8899if ( wp_is_mobile() )
    89100        $admin_body_class .= ' mobile';
    90101
    $admin_body_class .= ' no-customize-support'; 
    98109</script>
    99110
    100111<?php
    101 // Make sure the customize body classes are correct as early as possible. 
     112// Make sure the customize body classes are correct as early as possible.
    102113if ( current_user_can( 'edit_theme_options' ) )
    103114        wp_customize_support_script();
    104115?>
  • wp-admin/css/wp-admin.css

    body .ui-slider-tooltip { 
    40044004        margin-bottom: 15px;
    40054005}
    40064006
    4007 .wp-format-gallery .post-formats-fields,
    4008 .wp-format-image .post-formats-fields,
    4009 .wp-format-link .post-formats-fields,
    4010 .wp-format-quote .post-formats-fields,
    4011 .wp-format-video .post-formats-fields,
    4012 .wp-format-audio .post-formats-fields,
    4013 .wp-format-gallery .field.wp-format-gallery,
    4014 .wp-format-image .field.wp-format-image,
    4015 .wp-format-chat .field.wp-format-chat,
    4016 .wp-format-link .field.wp-format-link,
    4017 .wp-format-quote .field.wp-format-quote,
    4018 .wp-format-video .field.wp-format-video,
    4019 .wp-format-audio .field.wp-format-audio {
     4007#post-body-content.wp-format-gallery .post-formats-fields,
     4008#post-body-content.wp-format-image .post-formats-fields,
     4009#post-body-content.wp-format-link .post-formats-fields,
     4010#post-body-content.wp-format-quote .post-formats-fields,
     4011#post-body-content.wp-format-video .post-formats-fields,
     4012#post-body-content.wp-format-audio .post-formats-fields,
     4013#post-body-content.wp-format-gallery .field.wp-format-gallery,
     4014#post-body-content.wp-format-image .field.wp-format-image,
     4015#post-body-content.wp-format-chat .field.wp-format-chat,
     4016#post-body-content.wp-format-link .field.wp-format-link,
     4017#post-body-content.wp-format-quote .field.wp-format-quote,
     4018#post-body-content.wp-format-video .field.wp-format-video,
     4019#post-body-content.wp-format-audio .field.wp-format-audio {
    40204020        display: block;
    40214021}
    40224022
    body .ui-slider-tooltip { 
    40324032        font-size: 1.2em;
    40334033}
    40344034
    4035 .wp-format-image label,
    4036 .wp-format-video label,
    4037 .wp-format-audio label {
     4035#post-body-content.wp-format-image label,
     4036#post-body-content.wp-format-video label,
     4037#post-body-content.wp-format-audio label {
    40384038        float: left;
    40394039}
    40404040
    body .ui-slider-tooltip { 
    40434043        overflow: hidden;
    40444044        width: 40%;
    40454045        height: auto;
    4046         padding: 55px 0 20px;
    40474046        border: 1px dashed #dfdfdf;
    40484047        background: #f5f5f5 url(../images/media-button-2x.png) no-repeat 50% 25%;
     4048        box-sizing: border-box;
     4049        position:relative;
    40494050}
    40504051
    40514052.wp-format-media-holder:hover {
    40524053        background-color: #eee;
    40534054}
    40544055
     4056.wp-format-media-holder.drag-over {
     4057        background: rgba( 0, 86, 132, 0.9 );
     4058        border-color:transparent;
     4059}
     4060
     4061.wp-format-media-holder div {
     4062        display: none;
     4063}
     4064.wp-format-media-holder.drag-over div {
     4065        position: absolute;
     4066        top: 10px;
     4067        left: 10px;
     4068        right: 10px;
     4069        bottom: 10px;
     4070        border: 1px dashed #fff;
     4071        display:block;
     4072}
     4073
     4074#poststuff .wp-format-media-holder.drag-over div h3 {
     4075
     4076        position: absolute;
     4077        top: 50%;
     4078        left: 0;
     4079        right: 0;
     4080        -webkit-transform: translateY( -50% );
     4081        -moz-transform:    translateY( -50% );
     4082        -ms-transform:     translateY( -50% );
     4083        -o-transform:      translateY( -50% );
     4084        transform:         translateY( -50% );
     4085
     4086        font-size: 20px;
     4087        font-weight: 200;
     4088        color: #fff;
     4089        padding: 0;
     4090        text-align:center;
     4091        font-family: sans-serif;
     4092}
     4093
     4094#post-body-content.wp-format-image .wp-format-media-holder {
     4095        margin-top: 17px;
     4096}
     4097
    40554098.wp-format-media-preview {
    4056         margin-bottom: 20px;
     4099        margin: 20px 0;
     4100}
     4101
     4102#image-preview img {
     4103        width: auto;
     4104        max-height: 300px;
     4105}
     4106
     4107#post-body-content .wp-format-image p.use-url-or-html {
     4108        padding-top: 10px;
     4109        clear: both;
     4110        width: 40%;
     4111        text-align: center;
     4112}
     4113
     4114body.wp-format-image .attachment-display-settings {
     4115        display: none;
    40574116}
    40584117
    4059 .wp-format-status #titlewrap,
    4060 .wp-format-image .wp-media-buttons .insert-media,
    4061 .wp-format-audio .wp-media-buttons .insert-media,
    4062 .wp-format-video .wp-media-buttons .insert-media,
    4063 .wp-format-aside .wp-media-buttons .insert-media,
    4064 .wp-format-status .wp-media-buttons .insert-media {
     4118body.wp-format-status #titlewrap,
     4119body.wp-format-image .wp-media-buttons .insert-media,
     4120body.wp-format-audio .wp-media-buttons .insert-media,
     4121body.wp-format-video .wp-media-buttons .insert-media,
     4122body.wp-format-aside .wp-media-buttons .insert-media,
     4123body.wp-format-status .wp-media-buttons .insert-media {
    40654124        display: none;
    40664125}
    40674126
    body .ui-slider-tooltip { 
    40724131
    40734132.wp-format-media-select {
    40744133        display: block;
    4075         height: 200px;
     4134        height: 20px;
     4135        padding: 55px 0 20px;
    40764136        text-align: center;
    40774137}
    40784138
    body .ui-slider-tooltip { 
    40814141        max-height: 100%;
    40824142}
    40834143
    4084 .wp-format-media-select {
    4085         height: 20px;
    4086 }
    4087 
    40884144.empty .wp-format-media-metaedit {
    40894145        height: 20px;
    40904146        display: block;
    body .ui-slider-tooltip { 
    41014157#wp_format_video {
    41024158        float: left;
    41034159        margin-right: 23px;
    4104         max-width: 50%;
     4160        max-width: 40%;
    41054161        min-height: 97px;
    41064162}
    41074163
    4108 #icon-edit.wp-format-standard,
     4164body.wp-format-standard #icon-edit,
    41094165.post-format-options .standard {
    41104166        background: url(../images/post-formats32.png) no-repeat -3px -4px;
    41114167}
    41124168
    4113 #icon-edit.wp-format-image,
     4169body.wp-format-image #icon-edit,
    41144170.post-format-options .image {
    41154171        background: url(../images/post-formats32.png) no-repeat  -43px -4px;
    41164172}
    41174173
    4118 #icon-edit.wp-format-gallery,
     4174body.wp-format-gallery #icon-edit,
    41194175.post-format-options .gallery {
    41204176        background: url(../images/post-formats32.png) no-repeat -83px -4px;
    41214177}
    41224178
    4123 #icon-edit.wp-format-audio,
     4179body.wp-format-audio #icon-edit,
    41244180.post-format-options .audio {
    41254181        background: url(../images/post-formats32.png) no-repeat -123px -4px;
    41264182}
    41274183
    4128 #icon-edit.wp-format-video,
     4184body.wp-format-video #icon-edit,
    41294185.post-format-options .video {
    41304186        background: url(../images/post-formats32.png) no-repeat -163px -4px;
    41314187}
    41324188
    4133 #icon-edit.wp-format-chat,
     4189body.wp-format-chat #icon-edit,
    41344190.post-format-options .chat {
    41354191        background: url(../images/post-formats32.png) no-repeat -202px -4px;
    41364192}
    41374193
    4138 #icon-edit.wp-format-status,
     4194body.wp-format-status #icon-edit,
    41394195.post-format-options .status {
    41404196        background: url(../images/post-formats32.png) no-repeat -242px -4px;
    41414197}
    41424198
    4143 #icon-edit.wp-format-aside,
     4199body.wp-format-aside #icon-edit,
    41444200.post-format-options .aside {
    41454201        background: url(../images/post-formats32.png) no-repeat -282px -4px;
    41464202}
    41474203
    4148 #icon-edit.wp-format-quote,
     4204body.wp-format-quote #icon-edit,
    41494205.post-format-options .quote {
    41504206        background: url(../images/post-formats32.png) no-repeat -322px -4px;
    41514207}
    41524208
    4153 #icon-edit.wp-format-link,
     4209body.wp-format-link #icon-edit,
    41544210.post-format-options .link {
    41554211        background: url(../images/post-formats32.png) no-repeat -362px -4px;
    41564212}
  • wp-admin/includes/post-formats.php

    wp_nonce_field( 'show-post-format-ui_' . $post_type, 'show_post_format_ui_nonce' 
    3838                                ?>
    3939                        </div>
    4040                        <?php endif ?>
    41                         <label for="wp_format_image"><?php
    42                                 if ( current_user_can( 'unfiltered_html' ) )
    43                                         _e( 'Image HTML or URL' );
    44                                 else
    45                                         _e( 'Image URL' );
    46                         ?></label>
    47                         <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
    4841                        <div data-format="image" class="wp-format-media-holder hide-if-no-js">
     42                                <div><h3><?php _e( 'Drop image file to upload' ); ?></h3></div>
    4943                                <a href="#" class="wp-format-media-select"
    5044                                        data-choose="<?php esc_attr_e( 'Choose an Image' ); ?>"
    5145                                        data-update="<?php esc_attr_e( 'Select Image' ); ?>">
    5246                                        <?php _e( 'Select / Upload Image' ); ?>
    5347                                </a>
    5448                        </div>
     49                        <div class="wp-format-image-textarea hide-if-js">
     50                                <label for="wp_format_image"><?php
     51                                        if ( current_user_can( 'unfiltered_html' ) )
     52                                                _e( 'Image HTML or URL' );
     53                                        else
     54                                                _e( 'Image URL' );
     55                                ?></label>
     56                                <textarea id="wp_format_image" type="text" name="_format_image" class="widefat"><?php esc_html_e( $format_meta['image'] ); ?></textarea>
     57                        </div>
     58                        <p class="use-url-or-html hide-if-no-js"><span><?php printf( __( '(or %suse an image URL or HTML%s)' ), '<a href="#">', '</a>' ); ?></span>
     59                                <span style="display: none"><?php printf( __( '(or %sselect/upload an image%s)' ), '<a href="#">', '</a>' ); ?></span></p>
    5560                </div>
    5661
    5762                <div class="field wp-format-link">
  • wp-admin/js/post-formats.js

    window.wp = window.wp || {}; 
    66        "use strict";
    77
    88        var mediaFrame, insertMediaButton, container, icon, formatField,
     9                body,
    910                lastMimeType,
    1011                classRegex = /\s?\bwp-format-[^ ]+/g,
    1112                shortHeight = 120,
    window.wp = window.wp || {}; 
    1718                shortContentFormats = ['status', 'aside'],
    1819                noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery'];
    1920
     21        function imageFormatUploadProgress( uploader, file ) {
     22                var $bar = $( '#' + uploader.settings.drop_element + ' .media-progress-bar div' );
     23                $bar.width( file.percent + '%' );
     24        }
     25
     26        function imageFormatUploadStart( uploader ) {
     27                $( '#' + uploader.settings.drop_element + ' .wp-format-media-select' ).append('<div class="media-progress-bar"><div></div></div>');
     28        }
     29
     30        function imageFormatUploadSuccess( attachment ) {
     31                var $holder, $field, html = wp.media.string.image({
     32                        size : 'full',
     33                        align : false,
     34                        link : getUserSetting( 'urlbutton' )
     35                }, attachment.attributes );
     36
     37                $holder = $('.wp-format-media-holder[data-format=image]');
     38                $( '.media-progress-bar', $holder ).remove();
     39
     40                if ( 'image' !== attachment.attributes.type )
     41                        return;
     42
     43                $field = $( '#wp_format_' + $holder.data( 'format' ) );
     44
     45                // set the hidden input's value
     46                $field.val( html );
     47
     48                $( '#image-preview' ).remove();
     49
     50                $holder.parent().prepend( ['<div id="image-preview" class="wp-format-media-preview">',
     51                        '<img src="', attachment.get('url'), '"',
     52                        attachment.get('width') ? ' width="' + attachment.get('width') + '"' : '',
     53                        attachment.get('height') ? ' height="' + attachment.get('height') + '"' : '',
     54                        ' />',
     55                '</div>'].join( '' ) );
     56        }
     57
     58        var uploader = {
     59                dropzone:  $('.wp-format-media-holder[data-format=image]'),
     60                success:   imageFormatUploadSuccess,
     61                plupload:  {},
     62                params:    {}
     63        };
     64        uploader = new wp.Uploader( uploader );
     65        uploader.uploader.bind( 'BeforeUpload', imageFormatUploadStart );
     66        uploader.uploader.bind( 'UploadProgress', imageFormatUploadProgress );
     67
    2068        function switchFormatClass( format ) {
    2169                formatField.val( format );
    2270
    23                 container
    24                         .prop( 'className', container.prop( 'className' ).replace( classRegex, '' ) )
    25                         .addClass( 'wp-format-' + format );
    26 
    27                 icon
    28                         .prop( 'className', icon.prop( 'className' ).replace( classRegex, '' ) )
     71                $.each( [ container, icon, body ], function(i, thing) {
     72                        thing.prop( 'className', thing.prop( 'className' ).replace( classRegex, '' ) )
    2973                        .addClass( 'wp-format-' + format );
     74                });
    3075        }
    3176
    3277        function resizeContent( format, noAnimate ) {
    window.wp = window.wp || {}; 
    137182        }
    138183
    139184        $(function () {
     185                body = $( 'body' );
    140186                container = $( '#post-body-content' );
    141187                icon = $( '.icon32' );
    142188                formatField = $( '#post_format' );
    window.wp = window.wp || {}; 
    163209                        switchFormat( $( e.currentTarget ) );
    164210                } );
    165211
     212                // Toggle select/upload and URL/HTML for images
     213                $( '.use-url-or-html' ).on( 'click', 'a', function(e) {
     214                        e.preventDefault();
     215                        $( '.wp-format-media-holder, .wp-format-image-textarea' ).toggle();
     216                        $(this).closest( 'p' ).find( 'span' ).toggle();
     217                });
     218
    166219                // Media selection
    167220                $( '.wp-format-media-select' ).click( function (e) {
    168221                        e.preventDefault();
    window.wp = window.wp || {}; 
    242295                                        mediaPreview( attachment );
    243296                                } else {
    244297                                        html = wp.media.string.image({
    245                                                 align : getUserSetting( 'align' ),
    246                                                 size : getUserSetting( 'imgsize' ),
     298                                                size: 'full',
     299                                                align : false,
    247300                                                link : getUserSetting( 'urlbutton' )
    248301                                        }, attachment);
    249302
  • wp-includes/post-formats.php

    function get_post_format( $post = null ) { 
    2424        $_format = get_the_terms( $post->ID, 'post_format' );
    2525
    2626        if ( empty( $_format ) )
    27                 return false;
     27                return '';
    2828
    2929        $format = array_shift( $_format );
    3030
    function _post_formats_fix_empty_title( $data, $postarr ) { 
    10121012                $data['post_title'] = _post_formats_generate_title( $data['post_content'], $post_format );
    10131013
    10141014        return $data;
    1015 }
    1016  No newline at end of file
     1015}
  • wp-includes/script-loader.php

    function wp_default_scripts( &$scripts ) { 
    407407                        'comma' => _x( ',', 'tag delimiter' ),
    408408                ) );
    409409
    410                 $scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models' ), false, 1 );
     410                $scripts->add( 'post-formats', "/wp-admin/js/post-formats$suffix.js", array( 'media-models', 'wp-plupload' ), false, 1 );
    411411
    412412                $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
    413413