diff --git a/wp-admin/inline-uploading.php b/wp-admin/inline-uploading.php index 997b2fdff1..680ec88712 100644 --- a/wp-admin/inline-uploading.php +++ b/wp-admin/inline-uploading.php @@ -5,7 +5,7 @@ require_once('admin.php'); if (!current_user_can('edit_posts')) die(__('You do not have permission to edit posts.')); -$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment', 'flickrtag'); +$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment'); for ($i=0; $i'), '") ); + wp_delete_attachment($attachment); header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start"); @@ -68,22 +71,26 @@ $attachment = array( // Save the data $id = wp_insert_attachment($attachment, $file, $post); -// Generate the attachment's postmeta. -$imagesize = getimagesize($file); -$imagedata['width'] = $imagesize['0']; -$imagedata['height'] = $imagesize['1']; -list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); -$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; -$imagedata['file'] = $file; -$imagedata['thumb'] = "thumb-$filename"; +if ( preg_match('!^image/!', $attachment['post_mime_type']) ) { + // Generate the attachment's postmeta. + $imagesize = getimagesize($file); + $imagedata['width'] = $imagesize['0']; + $imagedata['height'] = $imagesize['1']; + list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); + $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; + $imagedata['file'] = $file; + $imagedata['thumb'] = "thumb-$filename"; -add_post_meta($id, '_wp_attachment_metadata', $imagedata); + add_post_meta($id, '_wp_attachment_metadata', $imagedata); -if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { - if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) - $error = wp_create_thumbnail($file, 128); - elseif ( $imagedata['height'] > 96 ) - $error = wp_create_thumbnail($file, 96); + if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { + if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) + $error = wp_create_thumbnail($file, 128); + elseif ( $imagedata['height'] > 96 ) + $error = wp_create_thumbnail($file, 96); + } +} else { + add_post_meta($id, '_wp_attachment_metadata', array()); } header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true"); @@ -108,8 +115,11 @@ if ( $post && empty($all) ) { $current_3 = ' class="current"'; } +if (! current_user_can('edit_others_posts') ) + $and_user = "AND post_author = " . $user_ID; + if ( $last ) - $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post") - $num; + $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' $and_user $and_post") - $num; else $start = (int) $start; @@ -119,13 +129,13 @@ if ( $start < 0 ) if ( '' == $sort ) $sort = "post_date_gmt DESC"; -$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, $double", ARRAY_A); +$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_status = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A); -if ( count($images) == 0 ) { +if ( count($attachments) == 0 ) { header("Location: ".basename(__FILE__)."?post=$post&action=upload"); die; -} elseif ( count($images) > $num ) { - $next = $start + count($images) - $num; +} elseif ( count($attachments) > $num ) { + $next = $start + count($attachments) - $num; } else { $next = false; } @@ -139,69 +149,94 @@ if ( $start > 0 ) { } $uwidth_sum = 0; -$images_html = ''; -$images_style = ''; -$images_script = ''; -if ( count($images) > 0 ) { - $images = array_slice( $images, 0, $num ); +$html = ''; +$style = ''; +$script = ''; +if ( count($attachments) > 0 ) { + $attachments = array_slice( $attachments, 0, $num ); $__delete = __('Delete'); - $__attachment_on = __('Link to Page'); - $__attachment_off = __('Link to Image'); - $__thumbnail_on = __('Use Thumbnail'); - $__thumbnail_off = __('Use Full Image'); + $__not_linked = __('Not Linked'); + $__linked_to_page = __('Linked to Page'); + $__linked_to_image = __('Linked to Image'); + $__using_thumbnail = __('Using Thumbnail'); + $__using_original = __('Using Original'); $__no_thumbnail = __('No Thumbnail'); $__close = __('Close Options'); - $__confirmdelete = __('Delete this photo from the server?'); + $__confirmdelete = __('Delete this file from the server?'); $__nothumb = __('There is no thumbnail associated with this photo.'); - $images_script .= "attachmenton = '$__attachment_on';\nattachmentoff = '$__attachment_off';\n"; - $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n"; - foreach ( $images as $key => $image ) { - $attachment_ID = $image['ID']; - $meta = get_post_meta($attachment_ID, '_wp_attachment_metadata', true); + $script .= "notlinked = '$__not_linked'; +linkedtoimage = '$__linked_to_image'; +linkedtopage = '$__linked_to_page'; +usingthumbnail = '$__using_thumbnail'; +usingoriginal = '$__using_original'; +"; + foreach ( $attachments as $key => $attachment ) { + $ID = $attachment['ID']; + $meta = get_post_meta($ID, '_wp_attachment_metadata', true); if (!is_array($meta)) { - $meta = get_post_meta($attachment_ID, 'imagedata', true); // Try 1.6 Alpha meta key + $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key if (!is_array($meta)) { - continue; - } else { - add_post_meta($attachment_ID, '_wp_attachment_metadata', $meta); + $meta = array(); } + add_post_meta($ID, '_wp_attachment_metadata', $meta); } - $image = array_merge($image, $meta); - if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { - $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb']; - $images_script .= "src".$attachment_ID."a = '$src';\nsrc".$attachment_ID."b = '".$image['guid']."';\n"; - $thumb = 'true'; - $thumbtext = $__thumbnail_on; - } else { - $src = $image['guid']; - $thumb = 'false'; - $thumbtext = $__no_thumbnail; - } - list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']); - $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"'; - $uwidth_sum += 128; - $xpadding = (128 - $image['uwidth']) / 2; - $ypadding = (96 - $image['uheight']) / 2; - $images_style .= "#target{$attachment_ID} img { padding: {$ypadding}px {$xpadding}px; }\n"; - $href = get_attachment_link($attachment_ID); - $images_script .= "href{$attachment_ID}a = '$href';\nhref{$attachment_ID}b = '{$image['guid']}';\n"; - $images_html .= " -
- - \ No newline at end of file +