Ticket #23673: 23673.3.diff

File 23673.3.diff, 9.5 KB (added by wonderboymusic, 3 months ago)
  • wp-admin/edit-form-advanced.php

    diff --git wp-admin/edit-form-advanced.php wp-admin/edit-form-advanced.php
    index 1c8b1b7..5650df5 100644
    if ( post_type_supports( $post_type, 'post-formats' ) ) { 
    141141if ( post_type_supports($post_type, 'page-attributes') ) 
    142142        add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); 
    143143 
    144 if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) ) 
     144$theme_post_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ); 
     145if ( $theme_post_support || 'attachment' === $post_type ) { 
     146        if ( $theme_post_support ) 
    145147                add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 
     148        elseif ( 'attachment' === $post_type && ! empty( $post->ID ) && preg_match( '#audio|video/#', $post->post_mime_type ) ) 
     149                add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 
     150} 
    146151 
    147152if ( post_type_supports($post_type, 'excerpt') ) 
    148153        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); 
  • wp-admin/includes/file.php

    diff --git wp-admin/includes/file.php wp-admin/includes/file.php
    index eac8ab5..3e34bf3 100644
    function wp_handle_sideload( &$file, $overrides = false, $time = null ) { 
    469469} 
    470470 
    471471/** 
     472 * Add a Base64 string of image bytes to the Media Library as $filename 
     473 * 
     474 * @since 3.6.0 
     475 * 
     476 * @param string $data Base64 encoded string representing image bytes 
     477 * @param string $mime Mime-type of image data 
     478 * @param string $filename Resulting file's name 
     479 * @param int $parent Optional. If present, the new image will be the parent's thumbnail 
     480 * 
     481 * @return int The new image file's attachment ID, if successful 
     482 */ 
     483function wp_handle_image_data( $data, $mime, $filename, $parent = 0 ) { 
     484        $uploads = wp_upload_dir(); 
     485        if ( strlen( $data ) && $uploads && false === $uploads['error'] ) { 
     486                $ext = '.jpg'; 
     487                switch ( $data ) { 
     488                case 'image/gif': 
     489                        $ext = '.gif'; 
     490                        break; 
     491                case 'image/png': 
     492                        $ext = '.png'; 
     493                        break; 
     494                } 
     495 
     496                $uniqfilename = str_replace( array( '?', '&' ), '-', wp_unique_filename( $uploads['path'], $filename ) ); 
     497                $newfile = $uploads['path'] . '/' . $uniqfilename; 
     498                $put = @file_put_contents( $newfile, base64_decode( $data ) ); 
     499                if ( $put ) { 
     500                        $stat = stat( dirname( $newfile ) ); 
     501                        $perms = $stat['mode'] & 0000666; 
     502                        @chmod( $newfile, $perms ); 
     503 
     504                        $attachment = array( 
     505                                'post_mime_type' => $mime, 
     506                                'post_type' => 'attachment', 
     507                                'post_content' => '', 
     508                        ); 
     509                        $sub_attachment_id = wp_insert_attachment( $attachment, $newfile ); 
     510                        $attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $newfile ); 
     511                        wp_update_attachment_metadata( $sub_attachment_id, $attach_data ); 
     512                        if ( $parent ) 
     513                                update_post_meta( $parent, '_thumbnail_id', $sub_attachment_id ); 
     514 
     515                        return $sub_attachment_id; 
     516                } 
     517        } 
     518} 
     519 
     520/** 
    472521 * Downloads a url to a local temporary file using the WordPress HTTP Class. 
    473522 * Please note, That the calling function must unlink() the file. 
    474523 * 
  • wp-admin/includes/image.php

    diff --git wp-admin/includes/image.php wp-admin/includes/image.php
    index a842287..7f97e69 100644
    function wp_generate_attachment_metadata( $attachment_id, $file ) { 
    116116                if ( $image_meta ) 
    117117                        $metadata['image_meta'] = $image_meta; 
    118118 
     119        } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) { 
     120                $metadata = wp_read_video_metadata( $file ); 
     121                if ( ! empty( $metadata['image']['data'] ) ) { 
     122                        $ext = '.jpg'; 
     123                        switch ( $metadata['image']['mime'] ) { 
     124                        case 'image/gif': 
     125                                $ext = '.gif'; 
     126                                break; 
     127                        case 'image/png': 
     128                                $ext = '.png'; 
     129                                break; 
     130                        } 
     131                        $basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext; 
     132                        wp_handle_image_data( $metadata['image']['data'], $metadata['image']['mime'], $basename, $attachment_id ); 
     133                } 
     134 
     135                // remove the blob of binary data from the array 
     136                unset( $metadata['image']['data'] ); 
     137        } elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) { 
     138                $metadata = wp_read_audio_metadata( $file ); 
     139                if ( ! empty( $metadata['image']['data'] ) ) { 
     140                        $ext = '.jpg'; 
     141                        switch ( $metadata['image']['mime'] ) { 
     142                        case 'image/gif': 
     143                                $ext = '.gif'; 
     144                                break; 
     145                        case 'image/png': 
     146                                $ext = '.png'; 
     147                                break; 
     148                        } 
     149                        $basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext; 
     150                        wp_handle_image_data( $metadata['image']['data'], $metadata['image']['mime'], $basename, $attachment_id ); 
     151                } 
     152 
     153                // remove the blob of binary data from the array 
     154                unset( $metadata['image']['data'] ); 
    119155        } 
    120156 
    121157        return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); 
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index f1f3737..d1cda80 100644
    function wp_enqueue_media( $args = array() ) { 
    15421542 
    15431543        do_action( 'wp_enqueue_media' ); 
    15441544} 
     1545 
     1546/** 
     1547 * Parse ID3v2, ID3v1, and getID3 comments to extract usable data 
     1548 * 
     1549 * @since 3.6.0 
     1550 * 
     1551 * @param array $metadata An existing array with data 
     1552 * @param array $data Data supplied by ID3 tags 
     1553 */ 
     1554function wp_add_id3_tag_data( &$metadata, $data ) { 
     1555        foreach ( array( 'id3v2', 'id3v1' ) as $version ) { 
     1556                if ( ! empty( $data[$version]['comments'] ) ) { 
     1557                        foreach ( $data[$version]['comments'] as $key => $list ) { 
     1558                                if ( ! empty( $list ) ) { 
     1559                                        // fix bug in byte stream analysis 
     1560                                        if ( 'terms_of_use' === $key ) { 
     1561                                                $terms = reset( $list ); 
     1562                                                $metadata[$key] = 0 === strpos( $terms, 'yright notice.' ) ? ( 'Cop' . $terms ) : $terms; 
     1563                                        } else { 
     1564                                                $metadata[$key] = reset( $list ); 
     1565                                        } 
     1566                                } 
     1567                        } 
     1568                        break; 
     1569                } 
     1570        } 
     1571 
     1572        if ( ! empty( $data['id3v2']['APIC'] ) ) { 
     1573                $image = reset( $data['id3v2']['APIC']); 
     1574                if ( ! empty( $image['data'] ) ) { 
     1575                        $metadata['image'] = array( 
     1576                                'data' => base64_encode( $image['data'] ), 
     1577                                'mime' => $image['image_mime'], 
     1578                                'width' => $image['image_width'], 
     1579                                'height' => $image['image_height'] 
     1580                        ); 
     1581                } 
     1582        } elseif ( ! empty( $data['comments']['picture'] ) ) { 
     1583                $image = reset( $data['comments']['picture'] ); 
     1584                if ( ! empty( $image['data'] ) ) { 
     1585                        $metadata['image'] = array( 
     1586                                'data' => base64_encode( $image['data'] ), 
     1587                                'mime' => $image['image_mime'] 
     1588                        ); 
     1589                } 
     1590        } 
     1591} 
     1592 
     1593/** 
     1594 * Retrieve metadata from a video file's ID3 tags 
     1595 * 
     1596 * @since 3.6.0 
     1597 * 
     1598 * @param string $file Path to file. 
     1599 * @return array|boolean Returns array of metadata, if found. 
     1600 */ 
     1601function wp_read_video_metadata( $file ) { 
     1602        if ( ! file_exists( $file ) ) 
     1603                return false; 
     1604 
     1605        $metadata = array(); 
     1606 
     1607        if ( ! class_exists( 'getID3' ) ) 
     1608                require( ABSPATH . WPINC . '/ID3/class-getid3.php' ); 
     1609        $id3 = new getID3(); 
     1610        $data = $id3->analyze( $file ); 
     1611 
     1612        if ( isset( $data['video']['lossless'] ) ) 
     1613                $metadata['lossless'] = $data['video']['lossless']; 
     1614        if ( ! empty( $data['video']['bitrate'] ) ) 
     1615                $metadata['bitrate'] = (int) $data['video']['bitrate']; 
     1616        if ( ! empty( $data['video']['bitrate_mode'] ) ) 
     1617                $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; 
     1618        if ( ! empty( $data['filesize'] ) ) 
     1619                $metadata['filesize'] = (int) $data['filesize']; 
     1620        if ( ! empty( $data['mime_type'] ) ) 
     1621                $metadata['mime_type'] = $data['mime_type']; 
     1622        if ( ! empty( $data['playtime_seconds'] ) ) 
     1623                $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); 
     1624        if ( ! empty( $data['playtime_string'] ) ) 
     1625                $metadata['length_formatted'] = $data['playtime_string']; 
     1626        if ( ! empty( $data['video']['resolution_x'] ) ) 
     1627                $metadata['width'] = (int) $data['video']['resolution_x']; 
     1628        if ( ! empty( $data['video']['resolution_y'] ) ) 
     1629                $metadata['height'] = (int) $data['video']['resolution_y']; 
     1630        if ( ! empty( $data['fileformat'] ) ) 
     1631                $metadata['fileformat'] = $data['fileformat']; 
     1632        if ( ! empty( $data['video']['dataformat'] ) ) 
     1633                $metadata['dataformat'] = $data['video']['dataformat']; 
     1634        if ( ! empty( $data['video']['encoder'] ) ) 
     1635                $metadata['encoder'] = $data['video']['encoder']; 
     1636        if ( ! empty( $data['video']['codec'] ) ) 
     1637                $metadata['codec'] = $data['video']['codec']; 
     1638 
     1639        unset( $data['audio']['streams'] ); 
     1640        $metadata['audio'] = $data['audio']; 
     1641 
     1642        wp_add_id3_tag_data( $metadata, $data ); 
     1643 
     1644        return $metadata; 
     1645} 
     1646 
     1647/** 
     1648 * Retrieve metadata from a audio file's ID3 tags 
     1649 * 
     1650 * @since 3.6.0 
     1651 * 
     1652 * @param string $file Path to file. 
     1653 * @return array|boolean Returns array of metadata, if found. 
     1654 */ 
     1655function wp_read_audio_metadata( $file ) { 
     1656        if ( ! file_exists( $file ) ) 
     1657                return false; 
     1658        $metadata = array(); 
     1659 
     1660        if ( ! class_exists( 'getID3' ) ) 
     1661                require( ABSPATH . WPINC . '/ID3/class-getid3.php' ); 
     1662        $id3 = new getID3(); 
     1663        $data = $id3->analyze( $file ); 
     1664 
     1665        if ( ! empty( $data['audio'] ) ) { 
     1666                unset( $data['audio']['streams'] ); 
     1667                $metadata = $data['audio']; 
     1668        } 
     1669 
     1670        if ( ! empty( $data['fileformat'] ) ) 
     1671                $metadata['fileformat'] = $data['fileformat']; 
     1672        if ( ! empty( $data['filesize'] ) ) 
     1673                $metadata['filesize'] = (int) $data['filesize']; 
     1674        if ( ! empty( $data['mime_type'] ) ) 
     1675                $metadata['mime_type'] = $data['mime_type']; 
     1676        if ( ! empty( $data['playtime_seconds'] ) ) 
     1677                $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); 
     1678        if ( ! empty( $data['playtime_string'] ) ) 
     1679                $metadata['length_formatted'] = $data['playtime_string']; 
     1680 
     1681        wp_add_id3_tag_data( $metadata, $data ); 
     1682 
     1683        return $metadata; 
     1684} 
     1685 No newline at end of file