Ticket #2682: 2682a.patch
File 2682a.patch, 16.0 KB (added by , 19 years ago) |
---|
-
wp-admin/admin-functions.php
1905 1905 return array((int) ($width / $height * $hmax), $hmax); 1906 1906 } 1907 1907 1908 function wp_attach_upload($file_array, $post) { 1909 1910 $url = $file_array['url']; 1911 $type = $file_array['type']; 1912 $imgtitle = $file_array['title']; 1913 $descr = $file_array['description']; 1914 $file = addslashes($file_array['file']); 1915 $filename = basename($file); 1916 1917 // Construct the attachment array 1918 $attachment = array( 1919 'post_title' => $imgtitle ? $imgtitle : $filename, 1920 'post_content' => $descr, 1921 'post_type' => 'attachment', 1922 'post_parent' => $post, 1923 'post_mime_type' => $type, 1924 'guid' => $url 1925 ); 1926 1927 //remove ABSPATH from db storage 1928 $relfile = str_replace(addslashes(ABSPATH), '', $file); 1929 1930 // Save the data (also inserts _wp_attached_file meta data as $relfile) 1931 $id = wp_insert_attachment($attachment, $relfile, $post); 1932 1933 if ( preg_match('!^image/!', $type) ) { 1934 1935 $imagesize = getimagesize($file); 1936 $attachdata['width'] = $imagesize['0']; 1937 $attachdata['height'] = $imagesize['1']; 1938 1939 if ( $attachdata['width'] * $attachdata['height'] < 3 * 1024 * 1024 ) { 1940 if ( $attachdata['width'] > 128 && $attachdata['width'] >= $attachdata['height'] * 4 / 3 ) 1941 $thumb = wp_create_thumbnail($file, 128); 1942 elseif ( $attachdata['height'] > 96 ) 1943 $thumb = wp_create_thumbnail($file, 96); 1944 1945 if ( @file_exists($thumb) ) { 1946 $attachdata['thumb'] = basename($thumb); 1947 } 1948 } 1949 1950 add_post_meta($id, '_wp_attachment_metadata', $attachdata); 1951 } 1952 1953 do_action('wp_attach_upload', $id); 1954 1955 return $id; 1956 } 1957 1908 1958 function wp_import_cleanup($id) { 1909 1959 wp_delete_attachment($id); 1910 1960 } … … 1959 2009 } 1960 2010 1961 2011 function the_attachment_links($id = false) { 1962 $id = (int) $id; 1963 $post = & get_post($id); 2012 $post = get_attachment($id); 1964 2013 1965 2014 if ( $post->post_type != 'attachment' ) 1966 2015 return false; … … 1981 2030 <?php 1982 2031 } 1983 2032 2033 // deprecated, use wp_shrink_dimensions 1984 2034 function get_udims($width, $height) { 1985 if ( $height <= 96 && $width <= 128 ) 1986 return array($width, $height); 1987 elseif ( $width / $height > 4 / 3 ) 1988 return array(128, (int) ($height / $width * 128)); 1989 else 1990 return array((int) ($width / $height * 96), 96); 2035 return wp_shrink_dimensions($width, $height); 1991 2036 } 1992 2037 1993 2038 ?> -
wp-admin/inline-uploading.php
50 50 51 51 $overrides = array('action'=>'save'); 52 52 53 $file = wp_handle_upload($_FILES['image'], $overrides);53 $file_array = wp_handle_upload($_FILES['image'], $overrides); 54 54 55 if ( isset($file ['error']) )56 die($file ['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">'.__('Back to Image Uploading').'</a>');55 if ( isset($file_array['error']) ) 56 die($file_array['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">'.__('Back to Image Uploading').'</a>'); 57 57 58 $url = $file['url']; 59 $type = $file['type']; 60 $file = $file['file']; 61 $filename = basename($file); 58 $file_array['title'] = $imgtitle; 59 $file_array['description'] = $descr; 62 60 63 // Construct the attachment array 64 $attachment = array( 65 'post_title' => $imgtitle ? $imgtitle : $filename, 66 'post_content' => $descr, 67 'post_type' => 'attachment', 68 'post_parent' => $post, 69 'post_mime_type' => $type, 70 'guid' => $url 71 ); 61 $id = wp_attach_upload($file_array, $post); 72 62 73 // Save the data74 $id = wp_insert_attachment($attachment, $file, $post);75 76 if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {77 // Generate the attachment's postmeta.78 $imagesize = getimagesize($file);79 $imagedata['width'] = $imagesize['0'];80 $imagedata['height'] = $imagesize['1'];81 list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);82 $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";83 $imagedata['file'] = $file;84 85 add_post_meta($id, '_wp_attachment_metadata', $imagedata);86 87 if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {88 if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )89 $thumb = wp_create_thumbnail($file, 128);90 elseif ( $imagedata['height'] > 96 )91 $thumb = wp_create_thumbnail($file, 96);92 93 if ( @file_exists($thumb) ) {94 $newdata = $imagedata;95 $newdata['thumb'] = basename($thumb);96 update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);97 } else {98 $error = $thumb;99 }100 }101 } else {102 add_post_meta($id, '_wp_attachment_metadata', array());103 }104 105 63 header("Location: " . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0"); 106 64 die(); 107 65 … … 138 96 if ( '' == $sort ) 139 97 $sort = "post_date_gmt DESC"; 140 98 141 $attachments = $wpdb->get_results("SELECT ID , post_date, post_title, post_mime_type, guidFROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);99 $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A); 142 100 143 101 if ( count($attachments) == 0 ) { 144 102 header("Location: " . basename(__FILE__) ."?post=$post&action=upload" ); … … 200 158 "; 201 159 foreach ( $attachments as $key => $attachment ) { 202 160 $ID = $attachment['ID']; 203 $href = get_attachment_link($ID); 204 $meta = get_post_meta($ID, '_wp_attachment_metadata', true); 205 if (!is_array($meta)) { 206 $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key 207 if (!is_array($meta)) { 208 $meta = array(); 209 } 210 add_post_meta($ID, '_wp_attachment_metadata', $meta); 211 } 212 $attachment = array_merge($attachment, $meta); 161 $att_post = get_attachment($ID); 162 $title = $att_post->post_title; 163 $description = $att_post->post_content; 164 $mime = $att_post->post_mime_type; 165 $guid = $att_post->guid; 166 $attachment = $att_post->attachment_metadata; 213 167 $noscript = "<noscript> 214 168 <div class='caption'><a href=\"".basename(__FILE__)."?action=links&attachment={$ID}&post={$post}&all={$all}&start={$start}\">Choose Links</a></div> 215 169 </noscript> … … 219 173 <a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a> 220 174 "; 221 175 $uwidth_sum += 128; 222 if ( preg_match('!^image/!', $ attachment['post_mime_type']) ) {176 if ( preg_match('!^image/!', $mime ) ) { 223 177 $image = & $attachment; 224 178 if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { 225 $src = str_replace(basename($ image['guid']), $image['thumb'], $image['guid']);179 $src = str_replace(basename($guid), $image['thumb'], $guid); 226 180 $script .= "srca[{$ID}] = '$src'; 227 srcb[{$ID}] = '{$ image['guid']}';181 srcb[{$ID}] = '{$guid}'; 228 182 "; 229 183 $thumb = 'true'; 230 184 $thumbtext = $__using_thumbnail; 231 185 } else { 232 $src = $ image['guid'];186 $src = $guid; 233 187 $thumb = 'false'; 234 188 $thumbtext = $__no_thumbnail; 235 189 } 236 list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);190 list($image['uwidth'], $image['uheight']) = wp_shrink_dimensions($image['width'], $image['height']); 237 191 $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"'; 238 192 $xpadding = (128 - $image['uwidth']) / 2; 239 193 $ypadding = (96 - $image['uheight']) / 2; 240 194 $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n"; 241 $title = wp_specialchars($ image['post_title'], ENT_QUOTES);242 $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\" $href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';243 ab[{$ID}] = '<a class=\"imagelink\" href=\"{$ image['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';195 $title = wp_specialchars($title, ENT_QUOTES); 196 $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\"{$image['link']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">'; 197 ab[{$ID}] = '<a class=\"imagelink\" href=\"{$guid}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">'; 244 198 imga[{$ID}] = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />'; 245 imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$ image['guid']}\" alt=\"{$title}\" $height_width />';199 imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$guid}\" alt=\"{$title}\" $height_width />'; 246 200 "; 247 201 $html .= "<div id='target{$ID}' class='attwrap left'> 248 202 <div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\"> … … 258 212 </div> 259 213 "; 260 214 } else { 261 $title = wp_specialchars($ attachment['post_title'], ENT_QUOTES);262 $filename = basename($ attachment['guid']);215 $title = wp_specialchars($title, ENT_QUOTES); 216 $filename = basename($guid); 263 217 $icon = get_attachment_icon($ID); 264 218 $toggle_icon = "<a id=\"I{$ID}\" onclick=\"toggleOtherIcon({$ID});return false;\" href=\"javascript:void()\">$__using_title</a>"; 265 $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" href=\" $href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';266 ab[{$ID}] = '<a id=\"p{$ID}\" href=\"{$ filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';219 $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" href=\"{$attachment['link']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">'; 220 ab[{$ID}] = '<a id=\"p{$ID}\" href=\"{$guid}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">'; 267 221 title[{$ID}] = '{$title}'; 268 222 filename[{$ID}] = '{$filename}'; 269 223 icon[{$ID}] = '{$icon}'; 270 224 "; 271 225 $html .= "<div id='target{$ID}' class='attwrap left'> 272 226 <div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\"> 273 <a id=\"p{$ID}\" href=\"{$ attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$title}</a>227 <a id=\"p{$ID}\" href=\"{$guid}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$title}</a> 274 228 </div> 275 229 {$noscript} 276 230 </div> 277 231 "; 278 232 $popups .= "<div id='popup{$ID}' class='popup'> 279 <div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$ attachment['post_mime_type'])."</div>233 <div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$mime)."</div> 280 234 <a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a> 281 235 {$toggle_icon} 282 236 {$send_delete_cancel} … … 644 598 <body> 645 599 <ul id="upload-menu"> 646 600 <li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__) . "?action=upload&post=$post&all=$all&start=$start"; ?>"><?php _e('Upload'); ?></a></li> 647 <?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post' ") ) { ?>601 <?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post' AND post_type = 'attachment'") ) { ?> 648 602 <li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__) . "?action=view&post=$post&all=false"; ?>"><?php _e('Browse'); ?></a></li> 649 603 <?php } ?> 650 604 <?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment'")) { ?> -
wp-includes/functions-post.php
386 386 // Don't delete the thumb if another attachment uses it 387 387 if (! $wpdb->get_row("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%".$wpdb->escape($meta['thumb'])."%' AND post_id <> $postid")) { 388 388 $thumbfile = str_replace(basename($file), $meta['thumb'], $file); 389 $thumbfile = apply_filters('wp_delete_file', $thumbfile); 389 //add ABSPATH back 390 $thumbfile = apply_filters('wp_delete_file', addslashes(ABSPATH) . $thumbfile); 390 391 @ unlink($thumbfile); 391 392 } 392 393 } 394 395 //add ABSPATH back 396 $file = apply_filters('wp_delete_file', addslashes(ABSPATH) . $file); 393 397 394 $file = apply_filters('wp_delete_file', $file);395 396 398 if ( ! empty($file) ) 397 399 @ unlink($file); 398 400 -
wp-includes/functions.php
1671 1671 echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />'; 1672 1672 } 1673 1673 1674 function get_attachment($id) { 1675 $id = (int) $id; 1676 $post = & get_post($id); 1677 1678 if ( $post->post_type != 'attachment' ) 1679 return false; 1680 1681 $meta = get_post_meta($id, '_wp_attachment_metadata', true); 1682 if (!is_array($meta)) { 1683 $meta = get_post_meta($id, 'imagedata', true); // Try 1.6 Alpha meta key 1684 if (!is_array($meta)) { 1685 $meta = array(); 1686 } 1687 add_post_meta($id, '_wp_attachment_metadata', $meta); 1688 } 1689 1690 // remove file meta data from serialized array 1691 if(isset($meta['file'])) { 1692 unset($meta['file']); 1693 update_post_meta($id, '_wp_attachment_metadata', $meta); 1694 } 1695 // use _wp_attached_file instead & add ABSPATH back 1696 $meta['file'] = addslashes(ABSPATH) . get_post_meta($id, '_wp_attached_file', true); 1697 $meta['link'] = get_attachment_link($id); 1698 1699 $post->attachment_metadata = $meta; 1700 1701 return apply_filters('get_attachment',$post); 1702 } 1703 1674 1704 ?> -
wp-includes/template-functions-post.php
444 444 } 445 445 446 446 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) { 447 $id = (int) $id; 448 $_post = & get_post($id); 447 $_post = get_attachment($id); 449 448 450 449 if ( ('attachment' != $_post->post_type) || ('' == $_post->guid) ) 451 450 return __('Missing Attachment'); … … 462 461 } 463 462 464 463 function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) { 465 $id = (int) $id; 466 $post = & get_post($id); 467 464 $post = get_attachment($id); 465 $imagedata = $post->attachment_metadata; 466 467 $title = $post->post_title; 468 468 $mime = $post->post_mime_type; 469 470 $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true); 471 472 $file = get_post_meta($post->ID, '_wp_attached_file', true); 473 469 $guid = $post->guid; 470 474 471 if ( !$fullsize && !empty($imagedata['thumb']) 475 && ($thumbfile = str_replace(basename($ file), $imagedata['thumb'], $file))472 && ($thumbfile = str_replace(basename($imagedata['file']), $imagedata['thumb'], $imagedata['file'])) 476 473 && file_exists($thumbfile) ) { 477 474 478 475 // We have a thumbnail desired, specified and existing 479 476 480 $src = str_replace(basename($ post->guid), $imagedata['thumb'], $post->guid);477 $src = str_replace(basename($guid), $imagedata['thumb'], $guid); 481 478 $src_file = $thumbfile; 482 479 $class = 'attachmentthumb'; 483 480 484 481 } elseif ( substr($mime, 0, 6) == 'image/' 485 && file_exists($ file) ) {482 && file_exists($imagedata['file']) ) { 486 483 487 484 // We have an image without a thumbnail 488 485 489 $src = $ post->guid;490 $src_file = & $ file;486 $src = $guid; 487 $src_file = & $imagedata['file']; 491 488 $class = 'attachmentimage'; 492 489 } elseif (! empty($mime) ) { 493 490 … … 523 520 if ( $actual_aspect >= $desired_aspect ) { 524 521 $height = $actual_aspect * $max_dims[0]; 525 522 $constraint = "width=\"{$max_dims[0]}\" "; 526 $post->iconsize = array($max_dims[0], $height);527 523 } else { 528 524 $width = $max_dims[1] / $actual_aspect; 529 525 $constraint = "height=\"{$max_dims[1]}\" "; 530 $post->iconsize = array($width, $max_dims[1]);531 526 } 532 } else {533 $post->iconsize = array($imagesize[0], $imagesize[1]);534 527 } 535 528 } 536 529 537 $icon = "<img src=\"{$src}\" title=\"{$ post->post_title}\" alt=\"{$post->post_title}\" {$constraint}/>";530 $icon = "<img src=\"{$src}\" title=\"{$title}\" alt=\"{$title}\" {$constraint}/>"; 538 531 539 532 return apply_filters('attachment_icon', $icon, $post->ID); 540 533 } … … 545 538 if ( $innerHTML = get_attachment_icon($id, $fullsize, $max_dims)) 546 539 return $innerHTML; 547 540 548 $post = & get_post($id);541 $post = get_attachment($id); 549 542 550 543 $innerHTML = $post->post_title; 551 544