Make WordPress Core


Ignore:
Timestamp:
12/13/2005 07:19:56 PM (20 years ago)
Author:
ryan
Message:

Attachment enhancements from skeltoac. fixes #2074

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/inline-uploading.php

    r3295 r3303  
    2626$images_width = 1;
    2727
    28 function get_udims($width, $height) {
    29     if ( $height <= 96 && $width <= 128 )
    30         return array($width, $height);
    31     elseif ( $width / $height > 4 / 3 )
    32         return array(128, (int) ($height / $width * 128));
    33     else
    34         return array((int) ($width / $height * 96), 96);
    35 }
    36 
    3728switch($action) {
    3829case 'delete':
     
    5647
    5748$url = $file['url'];
     49$type = $file['type'];
    5850$file = $file['file'];
    5951$filename = basename($file);
     
    6557    'post_status' => 'attachment',
    6658    'post_parent' => $post,
    67     'post_mime_type' => $_FILES['image']['type'],
     59    'post_mime_type' => $type,
    6860    'guid' => $url
    6961    );
     
    8072    $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
    8173    $imagedata['file'] = $file;
    82     $imagedata['thumb'] = "thumb-$filename";
    8374
    8475    add_post_meta($id, '_wp_attachment_metadata', $imagedata);
     
    8677    if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
    8778        if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
    88             $error = wp_create_thumbnail($file, 128);
     79            $thumb = wp_create_thumbnail($file, 128);
    8980        elseif ( $imagedata['height'] > 96 )
    90             $error = wp_create_thumbnail($file, 96);
     81            $thumb = wp_create_thumbnail($file, 96);
     82
     83        if ( @file_exists($thumb) ) {
     84            $newdata = $imagedata;
     85            $newdata['thumb'] = basename($thumb);
     86            update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
     87        } else {
     88            $error = $thumb;
     89        }
    9190    }
    9291} else {
     
    163162    $__using_thumbnail = __('Using Thumbnail');
    164163    $__using_original = __('Using Original');
     164    $__using_title = __('Using Title');
     165    $__using_filename = __('Using Filename');
     166    $__using_icon = __('Using Icon');
    165167    $__no_thumbnail = '<del>'.__('No Thumbnail').'</del>';
    166168    $__send_to_editor = __('Send to editor');
     
    174176usingthumbnail = '$__using_thumbnail';
    175177usingoriginal = '$__using_original';
     178usingtitle = '$__using_title';
     179usingfilename = '$__using_filename';
     180usingicon = '$__using_icon';
    176181var aa = new Array();
    177182var ab = new Array();
     
    180185var srca = new Array();
    181186var srcb = new Array();
     187var title = new Array();
     188var filename = new Array();
     189var icon = new Array();
    182190";
    183191    foreach ( $attachments as $key => $attachment ) {
     
    194202        $attachment = array_merge($attachment, $meta);
    195203        $send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
    196 <a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>
     204<!--<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post\">$__delete</a>-->
    197205        <a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
    198206";
     
    235243";
    236244        } else {
    237             $script .= "aa[{$ID}] = '<a id=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
    238 ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$attachment['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$attachment['post_title']}\">{$attachment['post_title']}</a>';
     245            $title = $attachment['post_title'];
     246            $filename = basename($attachment['guid']);
     247            if ( $icon = get_attachment_icon($ID) )
     248                $toggle_icon = "<a id=\"I{$ID}\" onclick=\"toggleOtherIcon({$ID});return false;\" href=\"javascript:void()\">$__using_title</a>";
     249            $script .= "aa[{$ID}] = '<a id=\"{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">{$attachment['post_title']}</a>';
     250ab[{$ID}] = '<a id=\"{$ID}\" href=\"{$filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">{$attachment['post_title']}</a>';
     251title[{$ID}] = '{$attachment['post_title']}';
     252filename[{$ID}] = '{$filename}';
     253icon[{$ID}] = '{$icon}';
    239254";
    240255            $html .= "<div id='target{$ID}' class='attwrap left'>
    241     <div id='div{$ID}' class='otherwrap' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
     256    <div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
    242257        <a id=\"{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$attachment['post_title']}</a>
    243258    </div>
     
    247262    <div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
    248263    <a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
     264    {$toggle_icon}
    249265    {$send_delete_cancel}
    250266</div>
     
    321337    od=document.getElementById('div'+n);
    322338    ol=document.getElementById('L'+n);
     339    oi=document.getElementById(n);
     340    ih=oi.innerHTML;
    323341    if ( ol.innerHTML == linkedtofile ) {
    324342        od.innerHTML = aa[n];
     
    328346        ol.innerHTML = linkedtofile;
    329347    }
     348    oi=document.getElementById(n);
     349    oi.innerHTML = ih;
    330350}
    331351function toggleImage(n) {
     
    339359        oi.innerHTML = usingthumbnail;
    340360    }
     361}
     362function toggleOtherIcon(n) {
     363    od = document.getElementById('div'+n);
     364    o = document.getElementById(n);
     365    oi = document.getElementById('I'+n);
     366    if ( oi.innerHTML == usingtitle ) {
     367        o.innerHTML = filename[n];
     368        oi.innerHTML = usingfilename;
     369    } else if ( oi.innerHTML == usingfilename ) {
     370        o.innerHTML = icon[n];
     371        oi.innerHTML = usingicon;
     372    } else {
     373        o.innerHTML = title[n];
     374        oi.innerHTML = usingtitle;
     375    }
     376    if ( oi.innerHTML == usingicon )
     377        od.className = 'otherwrap usingicon';
     378    else
     379        od.classname = 'otherwrap usingtext';
    341380}
    342381
     
    402441.otherwrap {
    403442    margin-right: 5px;
    404     height: 90px;
    405443    overflow: hidden;
    406444    background-color: #f9fcfe;
    407445    float: left;
    408     padding: 3px;
    409446}
    410447.otherwrap a {
    411448    display: block;
    412     width: 122px;
    413449}
    414450.otherwrap a, .otherwrap a:hover, .otherwrap a:active, .otherwrap a:visited {
    415451    color: blue;
     452}
     453.usingicon {
     454    padding: 0px;
     455    height: 96px;
     456    text-align: center;
     457}
     458.usingicon a {
     459    width: 128px;
     460}
     461.usingtext {
     462    padding: 3px;
     463    height: 90px;
     464    text-align: left;
     465}
     466.usingtext a {
     467    width: 122px;
    416468}
    417469.filetype {
Note: See TracChangeset for help on using the changeset viewer.