X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/177fd6fefd2e3d5a0ea6591c71d660cabdb3c1a4..refs/tags/wordpress-2.6.2:/wp-admin/includes/media.php diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 1000d15b..d91ffc23 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -26,11 +26,14 @@ function update_gallery_tab($tabs) { add_filter('media_upload_tabs', 'update_gallery_tab'); function the_media_upload_tabs() { + global $redir_tab; $tabs = media_upload_tabs(); if ( !empty($tabs) ) { echo "\n"; } @@ -55,20 +58,39 @@ function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = fal $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; if ( $url ) - $html = "$html"; + $html = '$html"; $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); return $html; } +function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) { + + if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html; + $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; + + preg_match( '/width="([0-9]+)/', $html, $matches ); + if ( ! isset($matches[1]) ) return $html; + $width = $matches[1]; + + $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html ); + if ( empty($align) ) $align = 'none'; + + $shcode = '[caption id="' . $id . '" align="align' . $align + . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]'; + + return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); +} +add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 ); + function media_send_to_editor($html) { ?> false); + $file = wp_handle_sideload($file_array, $overrides); + + if ( isset($file['error']) ) + return new WP_Error( 'upload_error', $file['error'] ); + + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; + $title = preg_replace('/\.[^.]+$/', '', basename($file)); + $content = ''; + + // use image exif/iptc data for title and caption defaults if possible + if ( $image_meta = @wp_read_image_metadata($file) ) { + if ( trim($image_meta['title']) ) + $title = $image_meta['title']; + if ( trim($image_meta['caption']) ) + $content = $image_meta['caption']; + } + + $title = @$desc; + + // Construct the attachment array + $attachment = array_merge( array( + 'post_mime_type' => $type, + 'guid' => $url, + 'post_parent' => $post_id, + 'post_title' => $title, + 'post_content' => $content, + ), $post_data ); + + // Save the data + $id = wp_insert_attachment($attachment, $file, $post_parent); + if ( !is_wp_error($id) ) { + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + return $url; + } + return $id; +} + // wrap iframe content (produced by $content_func) in a doctype, html head/body etc // any additional function args will be passed to content_func @@ -126,9 +189,12 @@ function wp_iframe($content_func /* ... */) { <?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?> $image_title - $video_title - $audio_title - $media_title + $image_title + $video_title + $audio_title + $media_title EOF; printf($context, $out); } add_action( 'media_buttons', 'media_buttons' ); - -function media_buttons_head() { -$siteurl = get_option('siteurl'); -echo "\n"; -} - -add_action( 'admin_print_scripts', 'media_buttons_head' ); - -function media_admin_css() { - wp_admin_css('css/media'); -} - add_action('media_upload_media', 'media_upload_handler'); function media_upload_form_handler() { @@ -210,6 +256,8 @@ function media_upload_form_handler() { $post['post_title'] = $attachment['post_title']; if ( isset($attachment['post_excerpt']) ) $post['post_excerpt'] = $attachment['post_excerpt']; + if ( isset($attachment['menu_order']) ) + $post['menu_order'] = $attachment['menu_order']; $post = apply_filters('attachment_fields_to_save', $post, $attachment); @@ -232,7 +280,7 @@ function media_upload_form_handler() { if ( isset($_POST['send']) ) { $keys = array_keys($_POST['send']); $send_id = (int) array_shift($keys); - $attachment = $_POST['attachments'][$send_id]; + $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); $html = $attachment['post_title']; if ( !empty($attachment['url']) ) { if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) ) @@ -280,12 +328,36 @@ function media_upload_image() { $errors = $return; } - if ( isset($_POST['save']) ) + if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); + return media_upload_gallery(); + } return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); } +function media_sideload_image($file, $post_id, $desc = null) { + if (!empty($file) ) { + $file_array['name'] = basename($file); + $file_array['tmp_name'] = download_url($file); + $desc = @$desc; + + $id = media_handle_sideload($file_array, $post_id, $desc); + $src = $id; + + if ( is_wp_error($id) ) { + @unlink($file_array['tmp_name']); + return $id; + } + } + + if ( !empty($src) ) { + $alt = @$desc; + $html = "$alt"; + return $html; + } +} + function media_upload_audio() { if ( isset($_POST['html-upload']) && !empty($_FILES) ) { // Upload File button was clicked @@ -318,8 +390,10 @@ function media_upload_audio() { $errors = $return; } - if ( isset($_POST['save']) ) + if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); + return media_upload_gallery(); + } return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id ); } @@ -356,8 +430,10 @@ function media_upload_video() { $errors = $return; } - if ( isset($_POST['save']) ) + if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); + return media_upload_gallery(); + } return wp_iframe( 'media_upload_type_form', 'video', $errors, $id ); } @@ -394,8 +470,10 @@ function media_upload_file() { $errors = $return; } - if ( isset($_POST['save']) ) + if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); + return media_upload_gallery(); + } return wp_iframe( 'media_upload_type_form', 'file', $errors, $id ); } @@ -410,6 +488,7 @@ function media_upload_gallery() { $errors = $return; } + wp_enqueue_script('admin-gallery'); return wp_iframe( 'media_upload_gallery_form', $errors ); } @@ -429,8 +508,9 @@ function media_upload_library() { function image_attachment_fields_to_edit($form_fields, $post) { if ( substr($post->post_mime_type, 0, 5) == 'image' ) { $form_fields['post_title']['required'] = true; + $form_fields['post_excerpt']['label'] = __('Caption'); - $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"'); + $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image'); $form_fields['post_content']['label'] = __('Description'); @@ -546,6 +626,10 @@ function get_attachment_fields_to_edit($post, $errors = null) { \n", 'helps' => __('Enter a link URL or click above for presets.'), ), + 'menu_order' => array( + 'label' => __('Order'), + 'value' => $edit_post->menu_order + ), ); foreach ( get_attachment_taxonomies($post) as $taxonomy ) { @@ -583,7 +667,7 @@ function get_media_items( $post_id, $errors ) { if ( $post && $post->post_type == 'attachment' ) $attachments = array($post->ID => $post); else - $attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC"); + $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); } else { if ( is_array($GLOBALS['wp_the_query']->posts) ) foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) @@ -601,6 +685,8 @@ function get_media_items( $post_id, $errors ) { } function get_media_item( $attachment_id, $args = null ) { + global $redir_tab; + $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true ); $args = wp_parse_args( $args, $default_args ); extract( $args, EXTR_SKIP ); @@ -648,10 +734,27 @@ function get_media_item( $attachment_id, $args = null ) { } $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case + $display_title = wp_html_excerpt($display_title, 60); + + $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; + $order = ''; + + foreach ( $form_fields as $key => $val ) { + if ( 'menu_order' == $key ) { + if ( $gallery ) + $order = ''; + else + $order = ''; + + unset($form_fields['menu_order']); + break; + } + } $item = " $type $toggle_links + $order
$display_title
@@ -676,9 +779,11 @@ function get_media_item( $attachment_id, $args = null ) { if ( $send ) $send = ""; if ( $delete ) - $delete = "" . __('Delete') . ""; + $delete = "" . __('Delete') . ""; if ( ( $send || $delete ) && !isset($form_fields['buttons']) ) - $form_fields['buttons'] = array('tr' => "\t\t\n"); + $form_fields['buttons'] = array('tr' => "\t\t\n"); $hidden_fields = array(); @@ -700,6 +805,7 @@ function get_media_item( $attachment_id, $args = null ) { } $required = $field['required'] ? '*' : ''; + $aria_required = $field['required'] ? " aria-required='true' " : ''; $class = $id; $class .= $field['required'] ? ' form-required' : ''; @@ -707,9 +813,9 @@ function get_media_item( $attachment_id, $args = null ) { if ( !empty($field[$field['input']]) ) $item .= $field[$field['input']]; elseif ( $field['input'] == 'textarea' ) { - $item .= ""; + $item .= ""; } else { - $item .= ""; + $item .= ""; } if ( !empty($field['helps']) ) $item .= "

" . join( "

\n

", array_unique((array) $field['helps']) ) . '

'; @@ -754,7 +860,7 @@ function media_upload_header() { function media_upload_form( $errors = null ) { global $type, $tab; - $flash_action_url = get_option('siteurl') . "/wp-admin/async-upload.php"; + $flash_action_url = admin_url('async-upload.php'); // If Mac and mod_security, no Flash. :( $flash = true; @@ -765,7 +871,6 @@ function media_upload_form( $errors = null ) { $post_id = intval($_REQUEST['post_id']); ?> -
@@ -776,18 +881,22 @@ function media_upload_form( $errors = null ) { get_error_message(); ?>
+ + + -
+

-

+ +

+

- +

-

+
+ @@ -873,23 +986,100 @@ jQuery(function($){

+ +
+
$send $delete
$send $delete +
" . sprintf(__("You are about to delete %s."), $filename) . " " . __('Continue') . " + " . __('Cancel') . "