4 / 3 ) return array(128, (int) ($height / $width * 128)); else return array((int) ($width / $height * 96), 96); } switch($action) { case 'delete': if ( !current_user_can('edit_post', (int) $attachment) ) die(printf(__('You are not allowed to delete this attachment. %sGo back'), '") ); wp_delete_attachment($attachment); header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start"); die; case 'save': $overrides = array('action'=>'save'); $file = wp_handle_upload($_FILES['image'], $overrides); if ( isset($file['error']) ) die($file['error'] . 'Back to Image Uploading'); $url = $file['url']; $file = $file['file']; $filename = basename($file); // Construct the attachment array $attachment = array( 'post_title' => $imgtitle ? $imgtitle : $filename, 'post_content' => $descr, 'post_status' => 'attachment', 'post_parent' => $post, 'post_mime_type' => $_FILES['image']['type'], 'guid' => $url ); // Save the data $id = wp_insert_attachment($attachment, $file, $post); 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); 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"); die; case 'upload': $current_1 = ' class="current"'; $back = $next = false; break; case 'view': // How many images do we show? How many do we query? $num = 5; $double = $num * 2; if ( $post && empty($all) ) { $and_post = "AND post_parent = '$post'"; $current_2 = ' class="current"'; } else { $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_user $and_post") - $num; else $start = (int) $start; if ( $start < 0 ) $start = 0; if ( '' == $sort ) $sort = "post_date_gmt DESC"; $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($attachments) == 0 ) { header("Location: ".basename(__FILE__)."?post=$post&action=upload"); die; } elseif ( count($attachments) > $num ) { $next = $start + count($attachments) - $num; } else { $next = false; } if ( $start > 0 ) { $back = $start - $num; if ( $back < 1 ) $back = '0'; } else { $back = false; } $uwidth_sum = 0; $html = ''; $style = ''; $script = ''; if ( count($attachments) > 0 ) { $attachments = array_slice( $attachments, 0, $num ); $__delete = __('Delete'); $__not_linked = __('Not Linked'); $__linked_to_page = __('Linked to Page'); $__linked_to_image = __('Linked to Image'); $__linked_to_file = __('Linked to File'); $__using_thumbnail = __('Using Thumbnail'); $__using_original = __('Using Original'); $__no_thumbnail = __('No Thumbnail'); $__close = __('Close Options'); $__confirmdelete = __('Delete this file from the server?'); $__nothumb = __('There is no thumbnail associated with this photo.'); $script .= "notlinked = '$__not_linked'; linkedtoimage = '$__linked_to_image'; linkedtopage = '$__linked_to_page'; linkedtofile = '$__linked_to_file'; usingthumbnail = '$__using_thumbnail'; usingoriginal = '$__using_original'; "; foreach ( $attachments as $key => $attachment ) { $ID = $attachment['ID']; $href = get_attachment_link($ID); $meta = get_post_meta($ID, '_wp_attachment_metadata', true); if (!is_array($meta)) { $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key if (!is_array($meta)) { $meta = array(); } add_post_meta($ID, '_wp_attachment_metadata', $meta); } $attachment = array_merge($attachment, $meta); $delete_cancel = "$__delete $__close "; $uwidth_sum += 128; if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) { $image = & $attachment; if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { $src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']); $script .= "src{$ID}a = '$src'; src{$ID}b = '{$image['guid']}'; "; $thumb = 'true'; $thumbtext = $__using_thumbnail; } 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'].'"'; $xpadding = (128 - $image['uwidth']) / 2; $ypadding = (96 - $image['uheight']) / 2; $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n"; $script .= "a{$ID}a = ''; a{$ID}b = ''; img{$ID}a = '\"{$image['post_title']}\"'; img{$ID}b = '\"{$image['post_title']}\"'; "; $html .= "
\"{$image['post_title']}\"
"; } else { $script .= "a{$ID}a = '{$attachment['post_title']}'; a{$ID}b = '{$attachment['post_title']}'; "; $html .= "
{$attachment['post_title']}
"; } } } $images_width = $uwidth_sum + ( count($images) * 6 ) + 35; break; default: die('This script was not meant to be called directly.'); } ?>