WordPress.org

Make WordPress Core

Changeset 4670


Ignore:
Timestamp:
01/02/2007 07:28:30 PM (11 years ago)
Author:
ryan
Message:

Attachment fixes from mdawaffe. fixes #3411

Location:
trunk
Files:
6 edited

Legend:

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

    r4664 r4670  
    19361936    <tr>
    19371937        <th scope="row"><?php _e( 'URL' ) ?></th>
    1938         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo $post->guid ?></textarea></td>
     1938        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
    19391939    </tr>
    19401940<?php if ( $icon ) : ?>
    19411941    <tr>
    19421942        <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
    1943         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid; ?>"><?php echo $icon ?></a></textarea></td>
     1943        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
    19441944    </tr>
    19451945    <tr>
     
    19501950    <tr>
    19511951        <th scope="row"><?php _e( 'Link to file' ) ?></th>
    1952         <td><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></td>
     1952        <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() );  ?></a></textarea></td>
    19531953    </tr>
    19541954    <tr>
  • trunk/wp-admin/upload-functions.php

    r4657 r4670  
    1414    $class = 'text';
    1515    $innerHTML = get_attachment_innerHTML( $id, false, $dims );
    16     if ( $image_src = strstr($innerHTML, 'src=') ) {
    17         preg_match("/src=(\"|')(.+?)\\1/", $image_src, $matches);
    18         $image_src = $matches[2];
     16    if ( $image_src = get_attachment_icon_src() ) {
    1917        $image_rel = wp_make_link_relative($image_src);
     18        $innerHTML = '&nbsp;' . str_replace($image_src, $image_rel, $innerHTML);
    2019        $class = 'image';
    21         $innerHTML = '&nbsp;' . str_replace($image_src, $image_rel, $innerHTML);
    22         $image_base = str_replace($image_rel, '', $image_src);
    2320    }
    2421
    25     $src_base = get_the_guid();
     22    $src_base = wp_get_attachment_url();
    2623    $src = wp_make_link_relative( $src_base );
    2724    $src_base = str_replace($src, '', $src_base);
     
    3936    $r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-$id' id='attachment-url-base-$id' value='$src_base' />\n";
    4037
    41     if ( isset($attachment_data['thumb']) ) {
    42         $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$image_rel' />\n";
    43         $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$image_base' />\n";
    44     } elseif ( $image_rel )
    45         $r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-$id' id='attachment-is-image-$id' value='1' />\n";
     38    if ( !$thumb_base = wp_get_attachment_thumb_url() )
     39        $thumb_base = wp_mime_type_icon();
     40    if ( $thumb_base ) {
     41        $thumb_rel = wp_make_link_relative( $thumb_base );
     42        $thumb_base = str_replace( $thumb_rel, '', $thumb_base );
     43        $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$thumb_rel' />\n";
     44        $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$thumb_base' />\n";
     45    }
     46    $is_image = (int) wp_attachment_is_image();
     47    $r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-$id' id='attachment-is-image-$id' value='$is_image' />\n";
    4648    if ( isset($width) ) {
    4749        $r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n";
     
    6365        <div id="file-title">
    6466            <h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
    65                     echo "<a href='" . get_the_guid() . "' title='" . __('Direct link to file') . "'>";
     67                    echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
    6668                the_title();
    6769                if ( !isset($attachment_data['width']) && 'inline' != $style )
     
    8082        <div id="upload-file-view" class="alignleft">
    8183<?php       if ( isset($attachment_data['width']) && 'inline' != $style )
    82             echo "<a href='" . get_the_guid() . "' title='" . __('Direct link to file') . "'>";
     84            echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
    8385        echo wp_upload_display( array(171, 128) );
    8486        if ( isset($attachment_data['width']) && 'inline' != $style )
     
    103105        <div id="file-title">
    104106            <h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
    105                     echo "<a href='" . get_the_guid() . "' title='" . __('Direct link to file') . "'>";
     107                    echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
    106108                the_title();
    107109                if ( !isset($attachment_data['width']) && 'inline' != $style )
     
    120122    <div id="upload-file-view" class="alignleft">
    121123<?php       if ( isset($attachment_data['width']) && 'inline' != $style )
    122             echo "<a href='" . get_the_guid() . "' title='" . __('Direct link to file') . "'>";
     124            echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
    123125        echo wp_upload_display( array(171, 128) );
    124126        if ( isset($attachment_data['width']) && 'inline' != $style )
     
    130132            <tr>
    131133                <th scope="row"><label for="url"><?php _e('URL'); ?></label></th>
    132                 <td><input type="text" id="url" class="readonly" value="<?php the_guid(); ?>" readonly="readonly" /></td>
     134                <td><input type="text" id="url" class="readonly" value="<?php echo wp_get_attachment_url(); ?>" readonly="readonly" /></td>
    133135            </tr>
    134136<?php   else : ?>
     
    344346    }
    345347}
    346 
  • trunk/wp-admin/upload-js.php

    r4656 r4670  
    3838                return;
    3939            var thumbEl = $('attachment-thumb-url-' + id);
    40             this.currentImage.isImage = true;
    4140            if ( thumbEl ) {
    4241                this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value );
     
    4443            } else {
    4544                this.currentImage.thumb = false;
    46                 var isImageEl = $('attachment-is-image-' + id);
    47                 if ( !isImageEl )
    48                     this.currentImage.isImage = false;
    4945            }
    5046            this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value );
     
    6157                this.currentImage.height = false;
    6258            }
     59            this.currentImage.isImage = ( 0 == id ? '' : $('attachment-is-image-' + id).value );
    6360            this.currentImage.ID = id;
    6461        },
     
    9794            h += "<form name='uploadoptions' id='uploadoptions' class='alignleft'>";
    9895            h += "<table>";
    99             if ( this.currentImage.thumb ) {
     96            var display = [];
     97            var checked = 'display-title';
     98            if ( 1 == this.currentImage.isImage ) {
     99                checked = 'display-full';
     100                if ( this.currentImage.thumb ) {
     101                    display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> <?php echo attribute_escape(__('Thumbnail')); ?></label><br />");
     102                    checked = 'display-thumb';
     103                }
     104                display.push("<label for='display-full'><input type='radio' name='display' id='display-full' value='full' /> <?php echo attribute_escape(__('Full size')); ?></label>");
     105            } else if ( this.currentImage.thumb ) {
     106                display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> <?php echo attribute_escape(__('Icon')); ?></label>");
     107            }
     108            if ( display.length ) {
     109                display.push("<br /><label for='display-title'><input type='radio' name='display' id='display-title' value='title' /> <?php echo attribute_escape(__('Title')); ?></label>");
    100110                h += "<tr><th style='padding-bottom:.5em'><?php echo attribute_escape(__('Show:')); ?></th><td style='padding-bottom:.5em'>";
    101                 h += "<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' checked='checked' /> <?php echo attribute_escape(__('Thumbnail')); ?></label><br />";
    102                 h += "<label for='display-full'><input type='radio' name='display' id='display-full' value='full' /> <?php echo attribute_escape(__('Full size')); ?></label>";
     111                $A(display).each( function(i) { h += i; } );
    103112                h += "</td></tr>";
    104113            }
     
    118127
    119128            new Insertion.Top('upload-content', h);
     129            var displayEl = $(checked);
     130            if ( displayEl )
     131                displayEl.checked = true;
     132
    120133            if (e) Event.stop(e);
    121134            return false;
     
    145158                h += "<h2>" + this.currentImage.title + "</h2>";
    146159            h += " &#8212; <span>";
    147             h += "<a href='#' onclick='return theFileList.imageView(" + id + ");'><?php attribute_escape(__('Insert')); ?></a>"
     160            h += "<a href='#' onclick='return theFileList.imageView(" + id + ");'><?php echo attribute_escape(__('Insert')); ?></a>"
    148161            h += "</span>";
    149162            h += '</div>'
     
    223236            if ( 'none' != link )
    224237                h += "<a href='" + ( 'file' == link ? ( this.currentImage.srcBase + this.currentImage.src ) : ( this.currentImage.page + "' rel='attachment wp-att-" + this.currentImage.ID ) ) + "' title='" + this.currentImage.title + "'>";
    225             if ( display )
     238            if ( display && 'title' != display )
    226239                h += "<img src='" + ( 'thumb' == display ? ( this.currentImage.thumbBase + this.currentImage.thumb ) : ( this.currentImage.srcBase + this.currentImage.src ) ) + "' alt='" + this.currentImage.title + "' />";
    227240            else
  • trunk/wp-includes/post-template.php

    r4657 r4670  
    332332    $_post = & get_post($id);
    333333
    334     if ( ('attachment' != $_post->post_type) || ('' == $_post->guid) )
     334    if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url() )
    335335        return __('Missing Attachment');
    336336
    337337    $post_title = attribute_escape($_post->post_title);
    338338
    339     if (! empty($_post->guid) ) {
    340         $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
    341 
    342         return "<a href='$_post->guid' title='$post_title'>$innerHTML</a>";
    343 
    344     } else {
    345         $p .= __('Missing Attachment');
    346     }
    347     return $p;
    348 }
    349 
    350 function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
     339    $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
     340    return "<a href='$url' title='$post_title'>$innerHTML</a>";
     341}
     342
     343function get_attachment_icon_src( $id = 0, $fullsize = false ) {
    351344    $id = (int) $id;
    352     $post = & get_post($id);
    353 
    354     $mime = $post->post_mime_type;
     345    if ( !$post = & get_post($id) )
     346        return false;
    355347
    356348    $imagedata = wp_get_attachment_metadata( $post->ID );
     
    359351
    360352    $exts = array('jpg', 'gif', 'png');
    361     if ( !$fullsize && !empty($imagedata['thumb'])
    362             && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
    363             && file_exists($thumbfile) ) {
    364 
     353
     354    if ( !$fullsize && $thumbfile = wp_get_attachment_thumb_file( $post->ID ) ) {
    365355        // We have a thumbnail desired, specified and existing
    366356
    367         $src = str_replace(basename($post->guid), $imagedata['thumb'], $post->guid);
     357        $src = wp_get_attachment_thumb_url( $post->ID );
    368358        $src_file = $thumbfile;
    369359        $class = 'attachmentthumb';
    370 
    371     } elseif ( ( substr($mime, 0, 6) == 'image/' || 'import' == $mime && in_array(substr($file, -3), $exts) )
    372             && file_exists($file) ) {
    373 
     360    } elseif ( wp_attachment_is_image( $post->ID ) ) {
    374361        // We have an image without a thumbnail
    375362
    376         $src = $post->guid;
     363        $src = wp_get_attachment_url( $post->ID );
    377364        $src_file = & $file;
    378365        $class = 'attachmentimage';
    379     } elseif (! empty($mime) ) {
    380 
     366    } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
    381367        // No thumb, no image. We'll look for a mime-related icon instead.
    382         $icon_dir = apply_filters('icon_dir', get_template_directory().'/images');
    383         $icon_dir_uri = apply_filters('icon_dir_uri', get_template_directory_uri().'/images');
    384 
    385         $types = array(substr($mime, 0, strpos($mime, '/')), substr($mime, strpos($mime, '/') + 1), str_replace('/', '_', $mime));
    386         foreach ($types as $type) {
    387             foreach ($exts as $ext) {
    388                 $src_file = "$icon_dir/$type.$ext";
    389                 if ( file_exists($src_file) ) {
    390                     $src = "$icon_dir_uri/$type.$ext";
    391                     break 2;
    392                 }
    393             }
    394         }
    395     }
    396 
    397     if (! isset($src) )
     368
     369        $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
     370        $src_file = $icon_dir . '/' . basename($src);
     371    }
     372
     373    if ( !isset($src) )
    398374        return false;
     375    return array($src, $src_file);
     376}
     377
     378function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
     379    $id = (int) $id;
     380    if ( !$post = & get_post($id) )
     381        return false;
     382
     383    if ( !$src = get_attachment_icon_src( $id, $fullsize ) )
     384        return false;
     385
     386    list($src, $src_file) = $src;
    399387
    400388    // Do we need to constrain the image?
     
    425413    $icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";
    426414
    427     return apply_filters('attachment_icon', $icon, $post->ID);
     415    return apply_filters( 'attachment_icon', $icon, $post->ID );
    428416}
    429417
  • trunk/wp-includes/post.php

    r4637 r4670  
    14111411
    14121412function wp_update_attachment_metadata( $post_id, $data ) {
     1413    $post_id = (int) $post_id;
    14131414    if ( !get_post( $post_id ) )
    14141415        return false;
     
    14241425}
    14251426
     1427function wp_get_attachment_url( $post_id = 0 ) {
     1428    $post_id = (int) $post_id;
     1429    if ( !$post =& get_post( $post_id ) )
     1430        return false;
     1431
     1432    $url = get_the_guid( $post_id );
     1433
     1434    if ( 'attachment' != $post->post_type || !$url )
     1435        return false;
     1436
     1437    return apply_filters( 'wp_get_attachment_url', $url, $post_id );
     1438}
     1439
     1440function wp_get_attachment_thumb_file( $post_id ) {
     1441    $post_id = (int) $post_id;
     1442    if ( !$imagedata = wp_get_attachment_metadata( $post_id ) )
     1443        return false;
     1444
     1445    $file = get_attached_file( $post_id );
     1446
     1447    if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) )
     1448        return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post_id );
     1449    return false;
     1450}
     1451
     1452function wp_get_attachment_thumb_url( $post_id = 0 ) {
     1453    $post_id = (int) $post_id;
     1454    if ( !$url = wp_get_attachment_url( $post_id ) )
     1455        return false;
     1456
     1457    if ( !$thumb = wp_get_attachment_thumb_file( $post_id ) )
     1458        return false;
     1459    return false;
     1460
     1461    $url = str_replace(basename($url), basename($thumb), $url);
     1462
     1463    return apply_filters( 'wp_get_attachment_thumb_url', $url, $post_id );
     1464}
     1465
     1466function wp_attachment_is_image( $post_id = 0 ) {
     1467    $post_id = (int) $post_id;
     1468    if ( !$post =& get_post( $post_id ) )
     1469        return false;
     1470
     1471    if ( !$file = get_attached_file( $post->ID ) )
     1472        return false;
     1473
     1474    $image_exts = array('/jpg', 'jpeg', '/gif', '/png');
     1475
     1476    if ( 'image/' == substr($post->post_mime_type, 0, 6) || 'import' == $post->post_mime_type && in_array(substr($file, -4), $exts) )
     1477        return true;
     1478    return false;
     1479}
     1480
     1481function wp_mime_type_icon( $mime = 0 ) {
     1482    $post_id = 0;
     1483    if ( is_numeric($mime) ) {
     1484        $mime = (int) $mime;
     1485        if ( !$post =& get_post( $mime ) )
     1486            return false;
     1487        $post_id = $post->ID;
     1488        $mime = $post->post_mime_type;
     1489    }
     1490
     1491    if ( empty($mime) )
     1492        return false;
     1493
     1494    $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
     1495    $icon_dir_uri = apply_filters( 'icon_dir_uri', get_template_directory_uri() . '/images' );
     1496
     1497    $types = array(
     1498        substr($mime, 0, strpos($mime, '/')),
     1499        substr($mime, strpos($mime, '/') + 1),
     1500        str_replace('/', '_', $mime)
     1501    );
     1502
     1503    $exts = array('jpg', 'gif', 'png');
     1504
     1505    $src = false;
     1506
     1507    foreach ( $types as $type ) {
     1508        foreach ( $exts as $ext ) {
     1509            $src_file = "$icon_dir/$type.$ext";
     1510            if ( file_exists($src_file) ) {
     1511                $src = "$icon_dir_uri/$type.$ext";
     1512                break 2;
     1513            }
     1514        }
     1515    }
     1516
     1517    return apply_filters( 'wp_mime_type_icon', $src, $mime, $post_id ); // Last arg is 0 if function pass mime type.
     1518}
     1519
    14261520function wp_check_for_changed_slugs($post_id) {
    14271521    if ( !strlen($_POST['wp-old-slug']) )
  • trunk/wp-includes/script-loader.php

    r4633 r4670  
    3636            $this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
    3737            $this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
    38             $this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), '4535' );
     38            $this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), '20061223' );
    3939        }
    4040    }
Note: See TracChangeset for help on using the changeset viewer.