+ $media_dims = '';
+ $meta = wp_get_attachment_metadata( $post->ID );
+ if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
+ $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
+ $media_dims = apply_filters( 'media_meta', $media_dims, $post );
+
+ $image_edit_button = '';
+ if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
+ $nonce = wp_create_nonce( "image_editor-$post->ID" );
+ $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
+ }
+
+ $attachment_url = get_permalink( $attachment_id );
+
+ $item = "
+ $type_html
+ $toggle_links
+ $order
+ $display_title
+ <table class='slidetoggle describe $class'>
+ <thead class='media-item-info' id='media-head-$post->ID'>
+ <tr valign='top'>
+ <td class='A1B1' id='thumbnail-head-$post->ID'>
+ <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
+ <p>$image_edit_button</p>
+ </td>
+ <td>
+ <p><strong>" . __('File name:') . "</strong> $filename</p>
+ <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
+ <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>';
+ if ( !empty( $media_dims ) )
+ $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
+
+ $item .= "</td></tr>\n";
+
+ $item .= "
+ </thead>
+ <tbody>
+ <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
+ <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
+
+ $defaults = array(
+ 'input' => 'text',
+ 'required' => false,
+ 'value' => '',
+ 'extra_rows' => array(),
+ );
+
+ if ( $send )
+ $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
+ if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
+ if ( !EMPTY_TRASH_DAYS ) {
+ $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>';
+ } elseif ( !MEDIA_TRASH ) {
+ $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
+ <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p>
+ <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
+ <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
+ </div>";
+ } else {
+ $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
+ <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
+ }
+ } else {
+ $delete = '';
+ }
+
+ $thumbnail = '';
+ $calling_post_id = 0;
+ if ( isset( $_GET['post_id'] ) )
+ $calling_post_id = absint( $_GET['post_id'] );
+ elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
+ $calling_post_id = $post->post_parent;
+ if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
+ && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
+ $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
+ $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
+ }
+
+ if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
+ $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" );
+
+ $hidden_fields = array();
+
+ foreach ( $form_fields as $id => $field ) {
+ if ( $id[0] == '_' )
+ continue;
+
+ if ( !empty( $field['tr'] ) ) {
+ $item .= $field['tr'];
+ continue;
+ }
+
+ $field = array_merge( $defaults, $field );
+ $name = "attachments[$attachment_id][$id]";
+
+ if ( $field['input'] == 'hidden' ) {
+ $hidden_fields[$name] = $field['value'];
+ continue;
+ }
+
+ $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
+ $aria_required = $field['required'] ? " aria-required='true' " : '';
+ $class = $id;
+ $class .= $field['required'] ? ' form-required' : '';
+
+ $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
+ if ( !empty( $field[ $field['input'] ] ) )
+ $item .= $field[ $field['input'] ];
+ elseif ( $field['input'] == 'textarea' ) {
+ 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 .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
+ } else {
+ $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
+ }
+ if ( !empty( $field['helps'] ) )
+ $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
+ $item .= "</td>\n\t\t</tr>\n";
+
+ $extra_rows = array();
+
+ if ( !empty( $field['errors'] ) )
+ foreach ( array_unique( (array) $field['errors'] ) as $error )
+ $extra_rows['error'][] = $error;
+
+ if ( !empty( $field['extra_rows'] ) )
+ foreach ( $field['extra_rows'] as $class => $rows )
+ foreach ( (array) $rows as $html )
+ $extra_rows[$class][] = $html;
+
+ foreach ( $extra_rows as $class => $rows )
+ foreach ( $rows as $html )
+ $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
+ }
+
+ if ( !empty( $form_fields['_final'] ) )
+ $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
+ $item .= "\t</tbody>\n";
+ $item .= "\t</table>\n";
+
+ foreach ( $hidden_fields as $name => $value )
+ $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
+
+ if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
+ $parent = (int) $_REQUEST['post_id'];
+ $parent_name = "attachments[$attachment_id][post_parent]";
+ $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
+ }
+
+ return $item;
+}
+
+function get_compat_media_markup( $attachment_id, $args = null ) {
+ $post = get_post( $attachment_id );
+
+ $default_args = array(
+ 'errors' => null,
+ 'in_modal' => false,
+ );
+
+ $user_can_edit = current_user_can( 'edit_post', $attachment_id );
+
+ $args = wp_parse_args( $args, $default_args );
+ $args = apply_filters( 'get_media_item_args', $args );
+
+ $form_fields = array();
+
+ if ( $args['in_modal'] ) {
+ foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
+ $t = (array) get_taxonomy($taxonomy);
+ if ( ! $t['public'] || ! $t['show_ui'] )
+ continue;
+ if ( empty($t['label']) )
+ $t['label'] = $taxonomy;
+ if ( empty($t['args']) )
+ $t['args'] = array();
+
+ $terms = get_object_term_cache($post->ID, $taxonomy);
+ if ( false === $terms )
+ $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
+
+ $values = array();
+
+ foreach ( $terms as $term )
+ $values[] = $term->slug;
+ $t['value'] = join(', ', $values);
+ $t['taxonomy'] = true;
+
+ $form_fields[$taxonomy] = $t;
+ }
+ }
+
+ // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
+ // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
+ $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
+
+ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
+
+ unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
+ $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
+ $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
+
+ $media_meta = apply_filters( 'media_meta', '', $post );