Make WordPress Core


Ignore:
Timestamp:
07/15/2008 02:01:08 AM (16 years ago)
Author:
mdawaffe
Message:

crazyhorse: merge with log:trunk@8240:8334

File:
1 edited

Legend:

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

    r8329 r8335  
    2727
    2828function the_media_upload_tabs() {
     29    global $redir_tab;
    2930    $tabs = media_upload_tabs();
    3031
    3132    if ( !empty($tabs) ) {
    3233        echo "<ul id='sidemenu'>\n";
    33         if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
     34        if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
     35            $current = $redir_tab;
     36        elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
    3437            $current = $_GET['tab'];
    3538        else {
     
    6568function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
    6669
    67     if ( empty($alt) ) return $html;
     70    // CAPTIONS_OFF is temporary. Do not use it.
     71    if ( empty($alt) || ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) ) return $html;
    6872    $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
    6973
     
    7579    if ( empty($align) ) $align = 'none';
    7680
    77     $shcode = '[wp_caption id="' . $id . '" align="align' . $align
    78     . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/wp_caption]';
     81    $shcode = '[caption id="' . $id . '" align="align' . $align
     82    . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
    7983
    8084    return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
     
    155159            $content = $image_meta['caption'];
    156160    }
    157    
     161
    158162    $title = @$desc;
    159163
     
    232236    $out = <<<EOF
    233237
    234     <a href="{$image_upload_iframe_src}&amp;TB_iframe=true" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
    235     <a href="{$video_upload_iframe_src}&amp;TB_iframe=true" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
    236     <a href="{$audio_upload_iframe_src}&amp;TB_iframe=true" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
    237     <a href="{$media_upload_iframe_src}&amp;TB_iframe=true" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
     238    <a href="{$image_upload_iframe_src}&amp;TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
     239    <a href="{$video_upload_iframe_src}&amp;TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
     240    <a href="{$audio_upload_iframe_src}&amp;TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
     241    <a href="{$media_upload_iframe_src}&amp;TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
    238242
    239243EOF;
     
    326330    }
    327331
    328     if ( isset($_POST['save']) )
     332    if ( isset($_POST['save']) ) {
    329333        $errors['upload_notice'] = __('Saved.');
     334        return media_upload_gallery();
     335    }
    330336
    331337    return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
     
    337343        $file_array['tmp_name'] = download_url($file);
    338344        $desc = @$desc;
    339        
     345
    340346        $id = media_handle_sideload($file_array, $post_id, $desc);
    341347        $src = $id;
    342348
    343         unset($file_array);
    344 
    345349        if ( is_wp_error($id) ) {
    346             $errors['upload_error'] = $id;
     350            @unlink($file_array['tmp_name']);
    347351            return $id;
    348352        }
     
    388392    }
    389393
    390     if ( isset($_POST['save']) )
     394    if ( isset($_POST['save']) ) {
    391395        $errors['upload_notice'] = __('Saved.');
     396        return media_upload_gallery();
     397    }
    392398
    393399    return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
     
    426432    }
    427433
    428     if ( isset($_POST['save']) )
     434    if ( isset($_POST['save']) ) {
    429435        $errors['upload_notice'] = __('Saved.');
     436        return media_upload_gallery();
     437    }
    430438
    431439    return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
     
    464472    }
    465473
    466     if ( isset($_POST['save']) )
     474    if ( isset($_POST['save']) ) {
    467475        $errors['upload_notice'] = __('Saved.');
     476        return media_upload_gallery();
     477    }
    468478
    469479    return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
     
    500510    if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
    501511        $form_fields['post_title']['required'] = true;
    502         $form_fields['post_excerpt']['label'] = __('Caption');
    503         $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"');
     512
     513        // CAPTIONS_OFF is temporary. Do not use it.
     514        if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) {
     515            $form_fields['post_excerpt']['label'] = __('Alternate Text');
     516            $form_fields['post_excerpt']['helps'][] = __('Alt text for the image, e.g. "The Mona Lisa"');
     517        } else {
     518            $form_fields['post_excerpt']['label'] = __('Caption');
     519            $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
     520        }
    504521
    505522        $form_fields['post_content']['label'] = __('Description');
     
    590607    $link = get_attachment_link($post->ID);
    591608
     609    // CAPTIONS_OFF is temporary. Do not use it.
     610    if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF )
     611        $alt = __('Alternate Text');
     612    else
     613        $alt = __('Caption');
     614
    592615    $form_fields = array(
    593616        'post_title'   => array(
     
    596619        ),
    597620        'post_excerpt' => array(
    598             'label'      => __('Caption'),
     621            'label'      => $alt,
    599622            'value'      => $edit_post->post_excerpt,
    600623        ),
     
    676699
    677700function get_media_item( $attachment_id, $args = null ) {
     701    global $redir_tab;
     702
    678703    $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true );
    679704    $args = wp_parse_args( $args, $default_args );
     
    723748
    724749    $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
     750    $display_title = wp_html_excerpt($display_title, 60);
     751
     752    $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
     753    $order = '';
     754
     755    foreach ( $form_fields as $key => $val ) {
     756        if ( 'menu_order' == $key ) {
     757            if ( $gallery )
     758                $order = '<div class="menu_order"> <input class="menu_order_input" type="text" id="attachments['.$attachment_id.'][menu_order]" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" /></div>';
     759            else
     760                $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
     761
     762            unset($form_fields['menu_order']);
     763            break;
     764        }
     765    }
    725766
    726767    $item = "
    727768    $type
    728769    $toggle_links
     770    $order
    729771    <div class='filename new'>$display_title</div>
    730772    <table class='slidetoggle describe $class'>
     
    9601002</div>
    9611003
     1004<script type="text/javascript">
     1005//<![CDATA[
     1006var addExtImage = {
     1007
     1008    width : '',
     1009    height : '',
     1010    align : 'alignnone',
     1011
     1012    insert : function() {
     1013        var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
     1014
     1015        if ( '' == f.src.value || '' == t.width ) return false;
     1016
     1017        if ( f.title.value ) {
     1018            title = f.title.value.replace(/['"<>]+/g, '');
     1019            title = ' title="'+title+'"';
     1020        }
     1021
     1022        if ( f.alt.value ) {
     1023            alt = f.alt.value.replace(/['"<>]+/g, '');
     1024<?php if ( ! defined('CAPTIONS_OFF') || true != CAPTIONS_OFF ) { // CAPTIONS_OFF is temporary. Do not use it. ?>
     1025            caption = f.alt.value.replace(/'/g, '&#39;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
     1026<?php } ?>
     1027        }
     1028
     1029        cls = caption ? '' : ' class="'+t.align+'"';
     1030
     1031        html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
     1032
     1033        if ( f.url.value )
     1034            html = '<a href="'+f.url.value+'">'+html+'</a>';
     1035
     1036        if ( caption )
     1037            html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
     1038
     1039        var win = window.dialogArguments || opener || parent || top;
     1040        win.send_to_editor(html);
     1041    },
     1042
     1043    resetImageData : function() {
     1044        var t = addExtImage;
     1045
     1046        t.width = t.height = '';
     1047        document.getElementById('go_button').style.color = '#bbb';
     1048        if ( ! document.forms[0].src.value )
     1049            document.getElementById('status_img').src = 'images/required.gif';
     1050        else document.getElementById('status_img').src = 'images/no.png';
     1051    },
     1052
     1053    updateImageData : function() {
     1054        var t = addExtImage;
     1055
     1056        t.width = t.preloadImg.width;
     1057        t.height = t.preloadImg.height;
     1058        document.getElementById('go_button').style.color = '#333';
     1059        document.getElementById('status_img').src = 'images/yes.png';
     1060    },
     1061
     1062    getImageData : function() {
     1063        var t = addExtImage, src = document.forms[0].src.value;
     1064
     1065        if ( ! src ) {
     1066            t.resetImageData();
     1067            return false;
     1068        }
     1069        document.getElementById('status_img').src = 'images/loading.gif';
     1070        t.preloadImg = new Image();
     1071        t.preloadImg.onload = t.updateImageData;
     1072        t.preloadImg.onerror = t.resetImageData;
     1073        t.preloadImg.src = src;
     1074    }
     1075}
     1076//]]>
     1077</script>
     1078
    9621079<div id="media-items">
    9631080<div class="media-item media-blank">
     
    9711088
    9721089function media_upload_gallery_form($errors) {
     1090    global $redir_tab;
     1091
     1092    $redir_tab = 'gallery';
    9731093    media_upload_header();
    9741094
    9751095    $post_id = intval($_REQUEST['post_id']);
    976 
    9771096    $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
    978 
    9791097?>
    9801098
     
    9941112<?php wp_nonce_field('media-form'); ?>
    9951113<?php //media_upload_form( $errors ); ?>
    996 
     1114<table class="widefat">
     1115<thead><tr>
     1116<th><?php _e('Media'); ?></th>
     1117<th class="order-head"><?php _e('Order'); ?></th>
     1118</tr></thead>
     1119</table>
    9971120<div id="media-items">
    9981121<?php echo get_media_items($post_id, $errors); ?>
    9991122</div>
     1123<p class="ml-submit">
    10001124<input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
    10011125<input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" />
     
    10031127<input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
    10041128<input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
     1129</p>
    10051130</form>
    10061131<?php
     
    11541279
    11551280function type_form_image() {
    1156     return '
     1281    $form = '
    11571282    <table class="describe"><tbody>
    11581283        <tr>
     1284            <th valign="top" scope="row" class="label" style="width:120px;">
     1285                <span class="alignleft"><label for="src">' . __('Source') . '</label></span>
     1286                <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span>
     1287            </th>
     1288            <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()"></td>
     1289        </tr>
     1290
     1291        <tr>
    11591292            <th valign="top" scope="row" class="label">
    1160                 <span class="alignleft"><label for="insertonly[src]">' . __('Image URL') . '</label></span>
     1293                <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
    11611294                <span class="alignright"><abbr title="required" class="required">*</abbr></span>
    11621295            </th>
    1163             <td class="field"><input id="insertonly[src]" name="insertonly[src]" value="" type="text" aria-required="true"></td>
    1164         </tr>
     1296            <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
     1297        </tr>
     1298';
     1299    // CAPTIONS_OFF is temporary. Do not use it.
     1300    if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) {
     1301        $form .= '
    11651302        <tr>
    11661303            <th valign="top" scope="row" class="label">
    1167                 <span class="alignleft"><label for="insertonly[alt]">' . __('Description') . '</label></span>
    1168                 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
     1304                <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
    11691305            </th>
    1170             <td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text" aria-required="true"></td>
    1171         </tr>
    1172         <tr><td></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr>
     1306            <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
     1307            <p class="help">' . __('Alt text for the image, e.g. "The Mona Lisa"') . '</p></td>
     1308        </tr>
     1309';
     1310
     1311    } else {
     1312        $form .= '
     1313        <tr>
     1314            <th valign="top" scope="row" class="label">
     1315                <span class="alignleft"><label for="alt">' . __('Image Caption') . '</label></span>
     1316            </th>
     1317            <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
     1318            <p class="help">' . __('Also used as alternate text for the image') . '</p></td>
     1319        </tr>
     1320';
     1321    }
     1322        $form .= '
    11731323        <tr class="align">
    1174             <th valign="top" scope="row" class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></th>
     1324            <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
    11751325            <td class="field">
    1176                 <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio" checked="checked" />
    1177                 <label for="image-align-none-0" class="align image-align-none-label">' . __('None') . '</label>
    1178                 <input name="insertonly[align]" id="image-align-left-0" value="left" type="radio" />
    1179                 <label for="image-align-left-0" class="align image-align-left-label">' . __('Left') . '</label>
    1180                 <input name="insertonly[align]" id="image-align-center-0" value="center" type="radio" />
    1181                 <label for="image-align-center-0" class="align image-align-center-label">' . __('Center') . '</label>
    1182                 <input name="insertonly[align]" id="image-align-right-0" value="right" type="radio" />
    1183                 <label for="image-align-right-0" class="align image-align-right-label">' . __('Right') . '</label>
     1326                <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" />
     1327                <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
     1328                <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" />
     1329                <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
     1330                <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" />
     1331                <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
     1332                <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" />
     1333                <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
    11841334            </td>
    11851335        </tr>
     1336
     1337        <tr>
     1338            <th valign="top" scope="row" class="label">
     1339                <span class="alignleft"><label for="url">' . __('Link URL') . '</label></span>
     1340            </th>
     1341            <td class="field"><input id="url" name="url" value="" type="text" /><br />
     1342
     1343            <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
     1344            <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
     1345            <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
     1346        </tr>
     1347
    11861348        <tr>
    11871349            <td></td>
    11881350            <td>
    1189                 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
     1351                <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" />
    11901352            </td>
    11911353        </tr>
    11921354    </tbody></table>
    11931355';
     1356
     1357    return $form;
    11941358}
    11951359
     
    12781442}
    12791443
     1444// support a GET parameter for disabling the flash uploader
     1445function media_upload_use_flash($flash) {
     1446        if ( array_key_exists('flash', $_REQUEST) )
     1447                $flash = !empty($_REQUEST['flash']);
     1448        return $flash;
     1449}
     1450
     1451add_filter('flash_uploader', 'media_upload_use_flash');
     1452
     1453function media_upload_flash_bypass() {
     1454        echo '<p class="upload-flash-bypass">';
     1455        printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) );
     1456        echo '</p>';
     1457}
     1458
     1459add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
     1460
     1461function media_upload_html_bypass() {
     1462        echo '<p class="upload-html-bypass">';
     1463        if ( array_key_exists('flash', $_REQUEST) )
     1464                // the user manually selected the browser uploader, so let them switch back to Flash
     1465                printf( __('You are using the Browser uploader.  Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) );
     1466        else
     1467                // the user probably doesn't have Flash
     1468                printf( __('You are using the Browser uploader.') );
     1469
     1470        echo '</p>';
     1471}
     1472
     1473add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
     1474add_action('post-html-upload-ui', 'media_upload_html_bypass');
     1475
     1476// make sure the GET parameter sticks when we submit a form
     1477function media_upload_bypass_url($url) {
     1478        if ( array_key_exists('flash', $_REQUEST) )
     1479                $url = add_query_arg('flash', intval($_REQUEST['flash']));
     1480        return $url;
     1481}
     1482
     1483add_filter('media_upload_form_url', 'media_upload_bypass_url');
     1484
     1485
     1486
    12801487add_filter('async_upload_image', 'get_media_item', 10, 2);
    12811488add_filter('async_upload_audio', 'get_media_item', 10, 2);
Note: See TracChangeset for help on using the changeset viewer.