Make WordPress Core


Ignore:
Timestamp:
07/02/2008 11:07:56 PM (17 years ago)
Author:
mdawaffe
Message:

crazyhorse: merge with log:trunk@8151:8240

File:
1 edited

Legend:

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

    r8067 r8242  
    6363}
    6464
     65function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
     66
     67    if ( empty($alt) ) return $html;
     68    $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
     69
     70    preg_match( '/width="([0-9]+)/', $html, $matches );
     71    if ( ! isset($matches[1]) ) return $html;
     72    $width = $matches[1];
     73
     74    $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
     75    if ( empty($align) ) $align = 'none';
     76
     77    $shcode = '[wp_caption id="' . $id . '" align="align' . $align
     78    . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/wp_caption]';
     79
     80    return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
     81}
     82add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
     83
    6584function media_send_to_editor($html) {
    6685    ?>
    6786<script type="text/javascript">
    68 <!--
    69 top.send_to_editor('<?php echo addslashes($html); ?>');
    70 top.tb_remove();
    71 -->
     87/* <![CDATA[ */
     88var win = window.dialogArguments || opener || parent || top;
     89win.send_to_editor('<?php echo addslashes($html); ?>');
     90/* ]]> */
    7291</script>
    7392    <?php
     
    116135}
    117136
    118 
    119 function media_sideload_image($file, $post_id, $desc = null) {
    120 
    121     if (!empty($file) ) {
    122         // Upload File button was clicked
    123        
    124         $file_array['name'] = basename($file);
    125         $file_array['tmp_name'] = download_url($file);
    126         $desc = @$desc;
    127        
    128         $sideload = media_handle_sideload($file_array, $post_id, $desc);
    129 
    130         $id = $sideload['id'];
    131         $src = $sideload['src'];
    132        
    133         unset($file_array['tmp_name']);
    134         unset($file_array);
    135        
    136         if ( is_wp_error($id) ) {
    137             $errors['upload_error'] = $id;
    138             $id = false;
    139         }
    140     }
    141    
    142     if ( !empty($src) && !strpos($src, '://') )
    143        
    144         $src = "http://$src";
    145         $alt = @$desc;
    146        
    147         if ( !empty($src) )
    148             $html = "<img src='$src' alt='$alt' />";
    149             return $html;
    150    
    151 }
    152 
    153137function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
    154138    $overrides = array('test_form'=>false);
     
    187171    if ( !is_wp_error($id) ) {
    188172        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    189     }
    190 
    191     return array('id' => $id, 'src' => $url);
    192 
     173        return $url;
     174    }
     175    return $id;
    193176}
    194177
     
    347330
    348331    return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
     332}
     333
     334function media_sideload_image($file, $post_id, $desc = null) {
     335    if (!empty($file) ) {
     336        $file_array['name'] = basename($file);
     337        $file_array['tmp_name'] = download_url($file);
     338        $desc = @$desc;
     339       
     340        $id = media_handle_sideload($file_array, $post_id, $desc);
     341        $src = $id;
     342
     343        unset($file_array);
     344
     345        if ( is_wp_error($id) ) {
     346            $errors['upload_error'] = $id;
     347            return $id;
     348        }
     349    }
     350
     351    if ( !empty($src) ) {
     352        $alt = @$desc;
     353        $html = "<img src='$src' alt='$alt' />";
     354        return $html;
     355    }
    349356}
    350357
     
    861868            post_params : {
    862869                "post_id" : "<?php echo $post_id; ?>",
    863                 "auth_cookie" : "<?php echo $_COOKIE[AUTH_COOKIE]; ?>",
     870                "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
    864871                "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
    865872                "type" : "<?php echo $type; ?>",
Note: See TracChangeset for help on using the changeset viewer.