Changeset 8242 for branches/crazyhorse/wp-admin/includes/media.php
- Timestamp:
- 07/02/2008 11:07:56 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crazyhorse/wp-admin/includes/media.php
r8067 r8242 63 63 } 64 64 65 function 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 } 82 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 ); 83 65 84 function media_send_to_editor($html) { 66 85 ?> 67 86 <script type="text/javascript"> 68 <!-- 69 top.send_to_editor('<?php echo addslashes($html); ?>');70 top.tb_remove();71 --> 87 /* <![CDATA[ */ 88 var win = window.dialogArguments || opener || parent || top; 89 win.send_to_editor('<?php echo addslashes($html); ?>'); 90 /* ]]> */ 72 91 </script> 73 92 <?php … … 116 135 } 117 136 118 119 function media_sideload_image($file, $post_id, $desc = null) {120 121 if (!empty($file) ) {122 // Upload File button was clicked123 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 153 137 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 154 138 $overrides = array('test_form'=>false); … … 187 171 if ( !is_wp_error($id) ) { 188 172 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; 193 176 } 194 177 … … 347 330 348 331 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); 332 } 333 334 function 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 } 349 356 } 350 357 … … 861 868 post_params : { 862 869 "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]; ?>", 864 871 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>", 865 872 "type" : "<?php echo $type; ?>",
Note: See TracChangeset
for help on using the changeset viewer.