Make WordPress Core


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

Attachment fixes from mdawaffe. fixes #3411

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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']) )
Note: See TracChangeset for help on using the changeset viewer.