Skip to:
Content

BuddyPress.org

Ticket #6586: 6586.02.patch

File 6586.02.patch, 4.6 KB (added by imath, 9 years ago)
  • src/bp-core/bp-core-avatars.php

    diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php
    index 1553725..aa44bab 100644
    function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) { 
    820820                return false;
    821821        }
    822822
     823        $browser_max_width = 0;
     824
     825        // If we have the browser_max_width, set it.
     826        if ( isset( $bp->avatar_admin->browser_max_width ) ) {
     827                $browser_max_width = $bp->avatar_admin->browser_max_width;
     828        }
     829
    823830        // Maybe resize.
    824         $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'] );
     831        $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'], $browser_max_width );
    825832        $bp->avatar_admin->image   = new stdClass();
    826833
    827834        // We only want to handle one image after resize.
    function bp_avatar_ajax_upload() { 
    933940                $bp->avatar_admin = new stdClass();
    934941        }
    935942
     943        // Get the browser max width if available
     944        if ( isset( $bp_params['browser_max_width'] ) ) {
     945                $bp->avatar_admin->browser_max_width =  (int) $bp_params['browser_max_width'];
     946        }
     947
    936948        // Upload the avatar
    937949        $avatar = bp_core_avatar_handle_upload( $_FILES, $bp_params['upload_dir_filter'] );
    938950
  • src/bp-core/classes/class-bp-attachment-avatar.php

    diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php
    index 604ee23..8c47ad8 100644
    class BP_Attachment_Avatar extends BP_Attachment { 
    117117         * Maybe shrink the attachment to fit maximum allowed width.
    118118         *
    119119         * @since 2.3.0
     120         * @since 2.4.0 Add the $browser_max_width parameter, to inform about the Avatar UI width.
    120121         *
    121122         * @uses  bp_core_avatar_original_max_width()
    122123         *
    class BP_Attachment_Avatar extends BP_Attachment { 
    124125         *
    125126         * @return mixed
    126127         */
    127         public static function shrink( $file = '' ) {
     128        public static function shrink( $file = '', $browser_max_width = 0 ) {
    128129                // Get image size
    129130                $avatar_data = parent::get_image_data( $file );
    130131
    131132                // Init the edit args
    132133                $edit_args = array();
    133134
     135                // Defaults to the Avatar original max width constant.
     136                $original_max_width = bp_core_avatar_original_max_width();
     137
     138                // If we have a browser max width and it's smaller than the Avatar original max width
     139                if ( ! empty( $browser_max_width ) && $browser_max_width < $original_max_width ) {
     140                        $original_max_width = $browser_max_width;
     141
     142                        // $original_max_width has to be larger than the avatar's full width
     143                        if ( $original_max_width < bp_core_avatar_full_width() ) {
     144                                $original_max_width = bp_core_avatar_full_width();
     145                        }
     146                }
     147
    134148                // Do we need to resize the image ?
    135                 if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > bp_core_avatar_original_max_width() ) {
     149                if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > $original_max_width ) {
    136150                        $edit_args = array(
    137                                 'max_w' => bp_core_avatar_original_max_width(),
    138                                 'max_h' => bp_core_avatar_original_max_width(),
     151                                'max_w' => $original_max_width,
     152                                'max_h' => $original_max_width,
    139153                        );
    140154                }
    141155
  • src/bp-core/js/bp-plupload.js

    diff --git src/bp-core/js/bp-plupload.js src/bp-core/js/bp-plupload.js
    index d758516..43e77d6 100644
    window.bp = window.bp || {}; 
    6060                 * @param {plupload.Uploader} uploader Uploader instance.
    6161                 */
    6262                this.uploader.bind( 'Init', function( uploader ) {
    63                         var container = $( '#' + self.params.defaults.container ),
    64                             drop_element = $( '#' + self.params.defaults.drop_element );
     63                        var container    = $( '#' + self.params.defaults.container ),
     64                            drop_element = $( '#' + self.params.defaults.drop_element ),
     65                            browser_max_width;
    6566
    6667                        if ( 'html4' === uploader.runtime ) {
    6768                                uploader.settings.multipart_params.html4 = true;
    6869                        }
    6970
     71                        /**
     72                         * Avatars need to be cropped, by default we are using an original
     73                         * max width of 450px, but there can be cases when this max width
     74                         * is larger than the one of the Avatar UI (eg: on mobile). To avoid any
     75                         * difficulties, we're adding a browser_max_width argument to the bp_params
     76                         * object and set it according to the container width. This value will be
     77                         * checked during the upload process to eventually adapt the resized avatar.
     78                         */
     79                        if ( 'bp_avatar_upload' ===  uploader.settings.multipart_params.action ) {
     80                                 uploader.settings.multipart_params.bp_params.browser_max_width = container.width();
     81                        }
     82
    7083                        if ( uploader.features.dragdrop && ! self.params.browser.mobile ) {
    7184                                container.addClass( 'drag-drop' );
    7285                                drop_element.bind( 'dragover.wp-uploader', function() {