Make WordPress Core

Changeset 3303


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

Attachment enhancements from skeltoac. fixes #2074

Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r3295 r3303  
    743743            @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
    744744
     745            // If no filters change the filename, we'll do a default transformation.
     746            if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
     747                $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
     748
     749            $thumbpath = str_replace(basename($file), $thumb, $file);
     750
    745751            // move the thumbnail to it's final destination
    746 
    747             $path = explode('/', $file);
    748             $thumbpath = substr($file, 0, strrpos($file, '/')).'/thumb-'.$path[count($path) - 1];
    749 
    750752            if ($type[2] == 1) {
    751753                if (!imagegif($thumbnail, $thumbpath)) {
     
    772774        return $error;
    773775    } else {
    774         return 1;
     776        return $thumbpath;
    775777    }
    776778}
     
    16341636function wp_handle_upload(&$file, $overrides = false) {
    16351637    // The default error handler.
    1636     function wp_handle_upload_error(&$file, $message) {
    1637         return array('error'=>$message);
     1638    if (! function_exists('wp_handle_upload_error') ) {
     1639        function wp_handle_upload_error(&$file, $message) {
     1640            return array('error'=>$message);
     1641        }
    16381642    }
    16391643
     
    16541658
    16551659    // Accepted MIME types are set here as PCRE. Override with $override['mimes'].
    1656     $mimes = apply_filters('upload_mimes', array(
    1657             'image/jpeg'    =>  'jpg|jpeg|jpe',
    1658             'image/gif' =>  'gif',
    1659             'image/(png|x-png)' =>  'png',
    1660             'image/(bmp|x-bmp|x-ms-bmp)'    =>  'bmp',
    1661             'image/(tiff|x-tiff)'   =>  'tif|tiff',
    1662             'image/(ico|x-ico)' =>  'ico',
    1663             'video/(asf|x-asf|x-ms-asf)'    =>  'asf|asx|wma|wax|wmv|wmx',
    1664             'video/(wmv|x-wmv|x-ms-wmv)'    =>  'wmv',
    1665             'video/(msvideo|x-msvideo)' =>  'avi',
    1666             'video/(quicktime|x-quicktime)' =>  'mov|qt',
    1667             'video/(mpeg|x-mpeg)'   =>  'mpeg|mpg|mpe',
    1668             'text/plain'    =>  'txt|c|cc|h|php',
    1669             'text/richtext' =>  'rtx',
    1670             'text/css'  =>  'css',
    1671             'text/html' =>  'htm|html',
    1672             'text/javascript'   =>  'js',
    1673             'audio/(mpeg|x-mpeg|mpeg3|x-mpeg3)' =>  'mp3',
    1674             'audio/x-realaudio' =>  'ra|ram',
    1675             'audio/(wav|x-wav)' =>  'wav',
    1676             'audio/(ogg|x-ogg)' =>  'ogg',
    1677             'audio/(midi|x-midi)'   =>  'mid|midi',
    1678             'application/pdf'   =>  'pdf',
    1679             'application/msword'    =>  'doc',
    1680             'application/mspowerpoint'  =>  'pot|pps|ppt',
    1681             'application/mswrite'   =>  'wri',
    1682             'application/(msexcel|vnd.ms-excel)'    =>  'xla|xls|xlt|xlw',
    1683             'application/msaccess'  =>  'mdb',
    1684             'application/msproject' =>  'mpp',
    1685             'application/x-shockwave-flash' =>  'swf',
    1686             'application/java'  =>  'class',
    1687             'application/x-tar' =>  'tar',
    1688             'application/(zip|x-zip-compressed)'    =>  'zip',
    1689             'application/(x-gzip|x-gzip-compressed)'    =>  'gz|gzip'));
    1690 
    1691     // For security, we never trust HTTP Content-Type headers unless the user overrides this.
    1692     $trust_content_type = false;
     1660    $mimes = apply_filters('upload_mimes', array (
     1661        'jpg|jpeg|jpe' => 'image/jpeg',
     1662        'gif' => 'image/gif',
     1663        'png' => 'image/png',
     1664        'bmp' => 'image/bmp',
     1665        'tif|tiff' => 'image/tiff',
     1666        'ico' => 'image/x-icon',
     1667        'asf|asx|wax|wmv|wmx' => 'video/asf',
     1668        'avi' => 'video/avi',
     1669        'mov|qt' => 'video/quicktime',
     1670        'mpeg|mpg|mpe' => 'video/mpeg',
     1671        'txt|c|cc|h|php' => 'text/plain',
     1672        'rtx' => 'text/richtext',
     1673        'css' => 'text/css',
     1674        'htm|html' => 'text/html',
     1675        'mp3|mp4' => 'audio/mpeg',
     1676        'ra|ram' => 'audio/x-realaudio',
     1677        'wav' => 'audio/wav',
     1678        'ogg' => 'audio/ogg',
     1679        'mid|midi' => 'audio/midi',
     1680        'wma' => 'audio/wma',
     1681        'rtf' => 'application/rtf',
     1682        'js' => 'application/javascript',
     1683        'pdf' => 'application/pdf',
     1684        'doc' => 'application/msword',
     1685        'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
     1686        'wri' => 'application/vnd.ms-write',
     1687        'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
     1688        'mdb' => 'application/vnd.ms-access',
     1689        'mpp' => 'application/vnd.ms-project',
     1690        'swf' => 'application/x-shockwave-flash',
     1691        'class' => 'application/java',
     1692        'tar' => 'application/x-tar',
     1693        'zip' => 'application/zip',
     1694        'gz|gzip' => 'application/x-gzip',
     1695        'exe' => 'application/x-msdownload'
     1696    ));
    16931697
    16941698    // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
    16951699    $test_form = true;
    16961700    $test_size = true;
     1701
     1702    // If you override this, you must provide $ext and $type!!!!
    16971703    $test_type = true;
    16981704
     
    17171723        return $upload_error_handler($file, __('Specified file failed upload test.'));
    17181724
    1719     // A correct MIME type will pass this test. We can't always determine it programatically, so we'll trust the HTTP headers.
     1725    // A correct MIME type will pass this test.
    17201726    if ( $test_type ) {
    17211727        $type = false;
    17221728        $ext = false;
    1723         foreach ($mimes as $mime_preg => $ext_preg) {
    1724             $mime_preg = '!^' . $mime_preg . '$!i';
     1729        foreach ($mimes as $ext_preg => $mime_match) {
    17251730            $ext_preg = '![^.]\.(' . $ext_preg . ')$!i';
    1726             if ( preg_match($mime_preg, $file['type'], $type) ) {
    1727                 if ( preg_match($ext_preg, $file['name'], $ext) ) {
    1728                     break;
    1729                 } else {
    1730                     return $upload_error_handler($file, __('File extension does not match file type. Try another.'));
    1731                 }
    1732             }
    1733         }
    1734         if (! $type && $ext )
     1731            if ( preg_match($ext_preg, $file['name'], $ext_matches) ) {
     1732                $type = $mime_match;
     1733                $ext = $ext_matches[1];
     1734            }
     1735        }
     1736
     1737        if ( !$type || !$ext )
    17351738            return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
    1736         $type = $type[0];
    1737         $ext = $ext[1];
    17381739    }
    17391740
     
    17551756    $new_file = $uploads['path'] . "/$filename";
    17561757    if ( false === move_uploaded_file($file['tmp_name'], $new_file) )
    1757         die(__('The uploaded file could not be moved to $file.'));
     1758        die(printf(__('The uploaded file could not be moved to %s.'), $file['path']));
    17581759
    17591760    // Set correct file permissions
     
    17651766    $url = $uploads['url'] . "/$filename";
    17661767
    1767     return array('file' => $new_file, 'url' => $url);
     1768    return array('file' => $new_file, 'url' => $url, 'type' => $type);
    17681769}
    17691770
     
    18371838}
    18381839
     1840function the_attachment_links($id = false) {
     1841    $id = (int) $id;
     1842    $post = & get_post($id);
     1843
     1844    if ( $post->post_status != 'attachment' )
     1845        return false;
     1846
     1847    $icon = get_attachment_icon($post->ID);
     1848
    18391849?>
     1850<?php _e('Text linked to file') ?><br/>
     1851<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea>
     1852<?php _e('Text linked to subpost') ?><br/>
     1853<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea>
     1854<?php if ( $icon ) : ?>
     1855<?php _e('Thumbnail linked to file') ?><br/>
     1856<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><img src="<?php echo $thumb ?>" class="attachmentthumb" alt="<?php echo $post->post_title ?>" /></a></textarea>
     1857<?php _e('Thumbnail linked to subpost') ?><br/>
     1858<textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" class="attachmentlink"><img src="<?php echo $icon ?>" class="attachmentthumb" alt="<?php echo $post->post_title ?>" /></a></textarea>
     1859<?php endif; ?>
     1860<?php
     1861}
     1862
     1863function get_udims($width, $height) {
     1864    if ( $height <= 96 && $width <= 128 )
     1865        return array($width, $height);
     1866    elseif ( $width / $height > 4 / 3 )
     1867        return array(128, (int) ($height / $width * 128));
     1868    else
     1869        return array((int) ($width / $height * 96), 96);
     1870}
     1871
     1872?>
  • trunk/wp-admin/edit-pages.php

    r2832 r3303  
    1010<p><?php _e('Pages are like posts except they live outside of the normal blog chronology and can be hierarchical. You can use pages to organize and manage any amount of content.'); ?> <a href="page-new.php"><?php _e('Create a new page'); ?> &raquo;</a></p>
    1111
     12<form name="searchform" action="" method="get">
     13  <fieldset>
     14  <legend><?php _e('Search Pages&hellip;') ?></legend>
     15  <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo wp_specialchars($_GET['s'], 1); ?>" size="17" />
     16  <input type="submit" name="submit" value="<?php _e('Search') ?>"  />
     17  </fieldset>
     18</form>
     19
    1220<?php
    13 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");
     21
     22$show_post_type = 'page';
     23
     24if ( isset($_GET['s']) )
     25    wp();
     26else
     27    $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");
    1428
    1529if ($posts) {
     
    2539    <th scope="col"></th>
    2640  </tr>
    27 <?php page_rows(); ?>
     41<?php
     42if ( isset($_GET['s']) ) {
     43foreach ( $posts as $post ) :
     44    $class = ('alternate' != $class) ? 'alternate' : ''; ?>
     45  <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     46    <th scope="row"><?php echo $post->ID; ?></th>
     47    <td>
     48      <?php echo $pad; ?><?php the_title() ?>
     49    </td>
     50    <td><?php the_author() ?></td>
     51    <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
     52    <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
     53    <td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
     54    <td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
     55  </tr>
     56<?php
     57endforeach;
     58} else {
     59    page_rows();
     60}
     61?>
    2862</table>
    2963
  • trunk/wp-admin/edit.php

    r3202 r3303  
    6666    printf(__('Search for &#8220;%s&#8221;'), wp_specialchars($_GET['s']) );
    6767} else {
    68     if ( ! is_paged() || get_query_var('paged') == 1 )
     68    if ( is_single() )
     69        printf(__('Comments on %s'), $post->post_title);
     70    elseif ( ! is_paged() || get_query_var('paged') == 1 )
    6971        _e('Last 15 Posts');
    7072    else
  • 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 {
  • trunk/wp-admin/post.php

    r3262 r3303  
    7575    if ($post->post_status == 'static')
    7676        include('edit-page-form.php');
     77    elseif ($post->post_status == 'attachment')
     78        include('edit-attachment-form.php');
    7779    else
    7880        include('edit-form-advanced.php');
     
    8587    <?php
    8688    break;
     89
     90case 'editattachment':
     91    $post_id = (int) $_POST['post_ID'];
     92
     93    // Don't let these be changed
     94    unset($_POST['guid']);
     95    $_POST['post_status'] = 'attachment';
     96
     97    // Update the thumbnail filename
     98    $oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
     99    $newmeta['thumb'] = $_POST['thumb'];
     100
     101    if ( '' !== $oldmeta )
     102        update_post_meta($post_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
     103    else
     104        add_post_meta($post_id, '_wp_attachment_metadata', $newmeta);
    87105
    88106case 'editpost':
     
    99117        if ( $_POST['referredby'] == 'redo' )
    100118            $location = get_permalink( $post_ID );
     119    } elseif ($action == 'editattachment') {
     120        $location = 'attachments.php';
    101121    } else {
    102122        $location = 'post.php';
     
    111131
    112132    $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     133
     134    $post = & get_post($post_id);
    113135   
    114136    if ( !current_user_can('edit_post', $post_id) )
    115137        die( __('You are not allowed to delete this post.') );
    116138
    117     if (! wp_delete_post($post_id))
     139    if ( (($post->post_status != 'attachment') && !wp_delete_post($post_id)) || !wp_delete_attachment($post_id))
    118140        die( __('Error in deleting...') );
    119141
    120142    $sendback = $_SERVER['HTTP_REFERER'];
    121143    if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
     144    elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php';
    122145    $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
    123146    header ('Location: ' . $sendback);
  • trunk/wp-admin/wp-admin.css

    r3283 r3303  
    162162    width: 100%;
    163163    overflow-y: hidden;
     164}
     165
     166form#upload th {
     167    text-align: right;
     168}
     169
     170form#upload #post_content, form#upload #post_title {
     171    width: 250px;
     172}
     173
     174form#upload #post_content {
     175    height: 50px;
     176}
     177
     178.attpreview {
     179    width: 1px; /* hug */
     180    text-align: center;
    164181}
    165182
     
    390407}
    391408
    392 #titlediv {
     409#titlediv, #guiddiv {
    393410    margin: 0 8px 0 0;
    394411    padding: 0px;
     
    410427}
    411428
    412 #titlediv input {
     429#titlediv input, #guiddiv input {
    413430    margin: 0px;
    414431    width: 100%;
     
    457474}
    458475
    459 #postexcerpt div {
     476#postexcerpt div, #attachmentlinks div {
    460477    margin-right: 8px;
    461478}
    462479
    463 * html #postexcerpt .dbx-toggle-open {
     480#attachmentlinks textarea {
     481    width: 100%;
     482    height: 2.5em;
     483    margin-bottom: 6px;
     484}
     485
     486* html #postexcerpt .dbx-toggle-open, * html #postexcerpt .dbx-toggle-open {
    464487    padding-right: 8px;
    465488}
    466489
    467 #excerpt {
     490#excerpt, .attachmentlinks {
    468491    margin: 0px;
    469492    height: 4em;
     
    734757}
    735758
    736 #slugdiv input, #passworddiv input, #authordiv select {
     759#slugdiv input, #passworddiv input, #authordiv select, #thumbdiv input, #parentdiv input {
    737760    margin-top: .5em;
    738761    width: 90%;
  • trunk/wp-content/themes/default/attachment.php

    r3251 r3303  
    1212            <h2><a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a> &raquo; <a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    1313            <div class="entrytext">
    14 <?php   $type = explode('/', $post->post_mime_type);
    15     switch ( $type[0] ) {
    16     case 'image' :
    17         $meta = get_post_meta($post->ID, '_wp_attachment_metadata', true);
    18         if ($meta['width'] > 450) : ?>
    19                 <p><a href="<?php echo $post->guid; ?>" title="<?php echo $post->post_title.': '.$meta['width'].'x'.$meta['height'] ?>"><img class="centered" src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" style="width:450px;" /></a></p>
    20 <?php       else : ?>
    21                 <p><img class="centered" src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" /></p>
    22 <?php       endif;
    23         break;
    24     default :
    25 ?>
    26                 <p><a href="<?php echo $post->guid; ?>"><?php echo basename($post->guid); ?></a></p>
    27 <?php
    28     }
    29 ?>
     14                <p class="<?php $link = get_the_attachment_link($post->ID, true, array(450, 800)); /* Doing this now populates the imagesize stuff */ echo $post->iconsize[0] <= 128 ? 'small' : ''; ?>attachment"><?php echo get_the_attachment_link($post->ID, true, array(450, 800)); ?><br /><?php echo basename($post->guid); ?></p>
     15
    3016                <?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    3117   
  • trunk/wp-content/themes/default/style.css

    r2274 r3303  
    264264    margin: 30px 0;
    265265    }
    266    
     266
     267.widecolumn .smallattachment {
     268    text-align: center;
     269    float: left;
     270    width: 128px;
     271    margin: 5px 5px 5px 0px;
     272}
     273
     274.widecolumn .attachment {
     275    text-align: center;
     276    margin: 5px 0px;
     277}
     278
     279.postmetadata {
     280    clear: left;
     281}
     282
    267283#footer {
    268284    padding: 0 0 0 1px;
  • trunk/wp-includes/classes.php

    r3300 r3303  
    9898            $qv['attachment_id'] = $qv['subpost_id'];
    9999           
    100         if ( ('' != $qv['attachment']) || $qv['attachment_id'] ) {
     100        if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) {
    101101            $this->is_single = true;
    102102            $this->is_attachment = true;
    103         }
    104 
    105         if ('' != $qv['name']) {
     103        } elseif ('' != $qv['name']) {
    106104            $this->is_single = true;
    107105        } elseif ( $qv['p'] ) {
     
    116114        } elseif (!empty($qv['s'])) {
    117115            $this->is_search = true;
     116            switch ($qv['show_post_type']) {
     117            case 'page' :
     118                $this->is_page = true;
     119                break;
     120            case 'attachment' :
     121                $this->is_attachment = true;
     122                break;
     123            }
    118124        } else {
    119125        // Look for archive queries.  Dates, categories, authors.
     
    198204            if ( ($this->is_date || $this->is_author || $this->is_category)) {
    199205                $this->is_archive = true;
     206            }
     207
     208            if ( 'attachment' == $qv['show_post_type'] ) {
     209                $this->is_attachment = true;
    200210            }
    201211        }
     
    14141424    var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id');
    14151425
    1416     var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging');
     1426    var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'show_post_type');
    14171427
    14181428    var $query_vars;
  • trunk/wp-includes/functions-post.php

    r3291 r3303  
    209209}
    210210
    211 function wp_insert_attachment($object, $file, $post_parent = 0) {
     211function wp_insert_attachment($object, $file = false, $post_parent = 0) {
    212212    global $wpdb, $user_ID;
    213213
    214214    if ( is_object($object) )
    215215        $object = get_object_vars($object);
    216    
     216
    217217    // Export array as variables
    218218    extract($object);
     
    321321    wp_set_post_cats('', $post_ID, $post_category);
    322322
    323     add_post_meta($post_ID, '_wp_attached_file', $file);
     323    if ( $file )
     324        add_post_meta($post_ID, '_wp_attached_file', $file);
    324325
    325326    clean_post_cache($post_ID);
     
    344345        return false;
    345346
    346     $meta = get_post_meta($postid, 'imagedata', true);
     347    $meta = get_post_meta($postid, '_wp_attachment_metadata', true);
    347348    $file = get_post_meta($postid, '_wp_attached_file', true);
    348349
     
    355356    $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
    356357
    357     if ( ! empty($meta['file']) )
    358         @ unlink($meta['file']);
     358    if ( ! empty($meta['thumb']) ) {
     359        // Don't delete the thumb if another attachment uses it
     360        if (! $foo = $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"))
     361            @ unlink(str_replace(basename($file), $meta['thumb'], $file));
     362    }
    359363
    360364    if ( ! empty($file) )
     
    429433        $postarr['post_date_gmt'] = '';
    430434    }
     435
     436    if ($postarr['post_status'] == 'attachment')
     437        return wp_insert_attachment($postarr);
    431438
    432439    return wp_insert_post($postarr);
     
    511518    if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
    512519        return $post;
     520
     521    if ( 'attachment' == $post->post_status )
     522        return wp_delete_attachment($postid);
    513523
    514524    do_action('delete_post', $postid);
  • trunk/wp-includes/functions.php

    r3298 r3303  
    504504    $original_prev = $prev_value;
    505505    if ( is_array($prev_value) || is_object($prev_value) )
    506         $prev_value = serialize($value);
     506        $prev_value = $wpdb->escape(serialize($prev_value));
    507507
    508508    if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
  • trunk/wp-includes/template-functions-links.php

    r3122 r3303  
    210210    get_currentuserinfo();
    211211
    212     if ( !user_can_edit_post($user_ID, $post->ID) || is_attachment() ) {
     212    if ( !user_can_edit_post($user_ID, $post->ID) ) {
    213213        return;
    214214    }
    215215
    216     $location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&amp;post=$post->ID";
     216    if ( is_attachment() )
     217        $file = 'attachments';
     218    else
     219        $file = 'post';
     220
     221    $location = get_settings('siteurl') . "/wp-admin/{$file}.php?action=edit&amp;post=$post->ID";
    217222    echo $before . "<a href=\"$location\">$link</a>" . $after;
    218223}
  • trunk/wp-includes/template-functions-post.php

    r3229 r3303  
    440440}
    441441
    442 function prepend_attachment($content) {
    443     global $post;
    444 
    445     $p = '<p class="attachment">';
    446 
    447     if ( '' != $post->guid ) {
    448         if ( substr($post->post_mime_type, 0, 6) == 'image/' )
    449             $p .= '<a href="' . $post->guid . '" title="Click for full-size image" ><img class="attachmentimage" src="' . $post->guid . '" alt="' . $post->post_title . '" /></a>';
    450         else
    451             $p .= __('Attachment') . ' (' . $post->post_mime_type . ')';
     442function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
     443    echo get_the_attachment_link($id, $fullsize, $max_dims);
     444}
     445
     446function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
     447    $id = (int) $id;
     448    $_post = & get_post($id);
     449
     450    if ( ('attachment' != $_post->post_status) || ('' == $_post->guid) )
     451        return __('Missing Attachment');
     452
     453    if (! empty($_post->guid) ) {
     454        $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
     455
     456        return "<a href=\"{$_post->guid}\" title=\"{$_post->post_title}\" >{$innerHTML}</a>";
     457
    452458    } else {
    453459        $p .= __('Missing attachment');
    454460    }
    455 
     461    return $p;
     462}
     463
     464function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
     465    $id = (int) $id;
     466    $post = & get_post($id);
     467
     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
     474    if ( !$fullsize && !empty($imagedata['thumb'])
     475            && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
     476            && file_exists($thumbfile) ) {
     477
     478        // We have a thumbnail desired, specified and existing
     479
     480        $src = str_replace(basename($post->guid), $imagedata['thumb'], $post->guid);
     481        $src_file = $thumbfile;
     482        $class = 'attachmentthumb';
     483
     484    } elseif ( substr($mime, 0, 6) == 'image/'
     485            && file_exists($file) ) {
     486
     487        // We have an image without a thumbnail
     488
     489        $src = $post->guid;
     490        $src_file = & $file;
     491        $class = 'attachmentimage';
     492    } elseif (! empty($mime) ) {
     493
     494        // No thumb, no image. We'll look for a mime-related icon instead.
     495        $icon_dir = apply_filters('icon_dir', get_template_directory().'/images');
     496        $icon_dir_uri = apply_filters('icon_dir_uri', get_template_directory_uri().'/images');
     497
     498        $types = array(substr($mime, 0, strpos($mime, '/')), substr($mime, strpos($mime, '/') + 1), str_replace('/', '_', $mime));
     499        $exts = array('jpg', 'gif', 'png');
     500        foreach ($types as $type) {
     501            foreach ($exts as $ext) {
     502                $src_file = "$icon_dir/$type.$ext";
     503                if ( file_exists($src_file) ) {
     504                    $src = "$icon_dir_uri/$type.$ext";
     505                    break 2;
     506                }
     507            }
     508        }
     509    }
     510
     511    if (! isset($src) )
     512        return false;
     513
     514    // Do we need to constrain the image?
     515    if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
     516
     517        $imagesize = getimagesize($src_file);
     518
     519        if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
     520            $actual_aspect = $imagesize[0] / $imagesize[1];
     521            $desired_aspect = $max_dims[0] / $max_dims[1];
     522
     523            if ( $actual_aspect >= $desired_aspect ) {
     524                $height = $actual_aspect * $max_dims[0];
     525                $constraint = "width=\"{$max_dims[0]}\" ";
     526                $post->iconsize = array($max_dims[0], $height);
     527            } else {
     528                $width = $max_dims[1] / $actual_aspect;
     529                $constraint = "height=\"{$max_dims[1]}\" ";
     530                $post->iconsize = array($width, $max_dims[1]);
     531            }
     532        } else {
     533            $post->iconsize = array($imagesize[0], $imagesize[1]);
     534        }
     535    }
     536
     537    $icon = "<img src=\"{$src}\" title=\"{$post->post_title}\" {$constraint}/>";
     538
     539    return apply_filters('attachment_icon', $icon, $post->ID);
     540}
     541
     542function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
     543    $id = (int) $id;
     544
     545    if ( $innerHTML = get_attachment_icon($id, $fullsize, $max_dims))
     546        return $innerHTML;
     547
     548    $post = & get_post($id);
     549
     550    $innerHTML = $post->post_title;
     551
     552    return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
     553}
     554
     555function prepend_attachment($content) {
     556    $p = '<p class="attachment">';
     557    $p .= get_the_attachment_link(false, true, array(400, 300));
    456558    $p .= '</p>';
     559    $p = apply_filters('prepend_attachment', $p);
    457560
    458561    return "$p\n$content";
    459562}
     563
    460564?>
Note: See TracChangeset for help on using the changeset viewer.