X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/177fd6fefd2e3d5a0ea6591c71d660cabdb3c1a4..baca9ce86a38dc54c4574890ee2d352fd81f78b2:/wp-admin/includes/media.php?ds=sidebyside diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 1000d15b..3938943a 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1,23 +1,54 @@ __('Choose File'), // handler action suffix => tab text + 'type' => __('From Computer'), // handler action suffix => tab text + 'type_url' => __('From URL'), 'gallery' => __('Gallery'), - 'library' => __('Media Library'), + 'library' => __('Media Library') ); return apply_filters('media_upload_tabs', $_default_tabs); } +/** + * Adds the gallery tab back to the tabs array if post has image attachments + * + * @since 2.5.0 + * + * @param array $tabs + * @return array $tabs with gallery if post has image attachment + */ function update_gallery_tab($tabs) { global $wpdb; + if ( !isset($_REQUEST['post_id']) ) { unset($tabs['gallery']); return $tabs; } - if ( intval($_REQUEST['post_id']) ) - $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']))); + + $post_id = intval($_REQUEST['post_id']); + + if ( $post_id ) + $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); + + if ( empty($attachments) ) { + unset($tabs['gallery']); + return $tabs; + } $tabs['gallery'] = sprintf(__('Gallery (%s)'), "$attachments"); @@ -25,74 +56,179 @@ function update_gallery_tab($tabs) { } add_filter('media_upload_tabs', 'update_gallery_tab'); +/** + * {@internal Missing Short Description}} + * + * @since 2.5.0 + */ function the_media_upload_tabs() { + global $redir_tab; $tabs = media_upload_tabs(); + $default = 'type'; if ( !empty($tabs) ) { echo "
\n"; } } -function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { - - $html = get_image_tag($id, $alt, $title, $align, $size); - - $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; +/** + * {@internal Missing Short Description}} + * + * @since 2.5.0 + * + * @param integer $id image attachment id + * @param string $caption image caption + * @param string $alt image alt attribute + * @param string $title image title attribute + * @param string $align image css alignment property + * @param string $url image src url + * @param string|bool $rel image rel attribute + * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) + * @return string the html to insert into editor + */ +function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { + + $html = get_image_tag($id, $alt, '', $align, $size); + + $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; if ( $url ) - $html = "$html"; + $html = '$html"; - $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); + $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); return $html; } +/** + * Adds image shortcode with caption to editor + * + * @since 2.6.0 + * + * @param string $html + * @param integer $id + * @param string $caption image caption + * @param string $alt image alt attribute + * @param string $title image title attribute + * @param string $align image css alignment property + * @param string $url image src url + * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) + * @return string + */ +function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { + + if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) + return $html; + + $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; + + if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) ) + return $html; + + $width = $matches[1]; + + $caption = str_replace( array("\r\n", "\r"), "\n", $caption); + $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); + // convert any remaining line breaks to- | $filename | -
$post->post_mime_type | |
" . mysql2date($post->post_date, get_option('time_format')) . " | |
" . apply_filters('media_meta', '', $post) . " | |
+
+ $image_edit_button + |
+
+ " . __('File name:') . " $filename +" . __('File type:') . " $post->post_mime_type +" . __('Upload date:') . " " . mysql2date( get_option('date_format'), $post->post_date ). ' '; + if ( !empty( $media_dims ) ) + $item .= "" . __('Dimensions:') . " $media_dims \n"; + + $item .= " |
$send $delete | |
$send $thumbnail $delete | |
\n\t\t\t | "; - if ( !empty($field[$field['input']]) ) - $item .= $field[$field['input']]; + $item .= "\t\t |
---|---|
\n\t\t\t | ";
+ if ( !empty( $field[ $field['input'] ] ) )
+ $item .= $field[ $field['input'] ];
elseif ( $field['input'] == 'textarea' ) {
- $item .= "";
+ if ( 'post_content' == $id && user_can_richedit() ) {
+ // sanitize_post() skips the post_content when user_can_richedit
+ $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
+ }
+ // post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit()
+ $item .= "';
} else {
- $item .= "";
+ $item .= "";
}
- if ( !empty($field['helps']) )
- $item .= " " . join( " \n", array_unique((array) $field['helps']) ) . ' '; + if ( !empty( $field['helps'] ) ) + $item .= "" . join( " \n", array_unique( (array) $field['helps'] ) ) . ' '; $item .= " | \n\t\t
$html | |
{$form_fields['_final']} |
" . join( "
\n", array_unique( (array) $field['helps'] ) ) . '
'; + $item .= "' . __('The web browser on your device cannot be used to upload files. You may be able to use the native app for your device instead.') . '
'; + return; + } - $flash_action_url = get_option('siteurl') . "/wp-admin/async-upload.php"; + $upload_action_url = admin_url('async-upload.php'); + $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; + $_type = isset($type) ? $type : ''; + $_tab = isset($tab) ? $tab : ''; - // If Mac and mod_security, no Flash. :( - $flash = true; - if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') ) - $flash = false; + $upload_size_unit = $max_upload_size = wp_max_upload_size(); + $sizes = array( 'KB', 'MB', 'GB' ); - $flash = apply_filters('flash_uploader', $flash); - $post_id = intval($_REQUEST['post_id']); + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { + $upload_size_unit /= 1024; + } + if ( $u < 0 ) { + $upload_size_unit = 0; + $u = 0; + } else { + $upload_size_unit = (int) $upload_size_unit; + } ?> - -