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 ) { |
820 | 820 | return false; |
821 | 821 | } |
822 | 822 | |
| 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 | |
823 | 830 | // 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 ); |
825 | 832 | $bp->avatar_admin->image = new stdClass(); |
826 | 833 | |
827 | 834 | // We only want to handle one image after resize. |
… |
… |
function bp_avatar_ajax_upload() { |
933 | 940 | $bp->avatar_admin = new stdClass(); |
934 | 941 | } |
935 | 942 | |
| 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 | |
936 | 948 | // Upload the avatar |
937 | 949 | $avatar = bp_core_avatar_handle_upload( $_FILES, $bp_params['upload_dir_filter'] ); |
938 | 950 | |
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 { |
117 | 117 | * Maybe shrink the attachment to fit maximum allowed width. |
118 | 118 | * |
119 | 119 | * @since 2.3.0 |
| 120 | * @since 2.4.0 Add the $browser_max_width parameter, to inform about the Avatar UI width. |
120 | 121 | * |
121 | 122 | * @uses bp_core_avatar_original_max_width() |
122 | 123 | * |
… |
… |
class BP_Attachment_Avatar extends BP_Attachment { |
124 | 125 | * |
125 | 126 | * @return mixed |
126 | 127 | */ |
127 | | public static function shrink( $file = '' ) { |
| 128 | public static function shrink( $file = '', $browser_max_width = 0 ) { |
128 | 129 | // Get image size |
129 | 130 | $avatar_data = parent::get_image_data( $file ); |
130 | 131 | |
131 | 132 | // Init the edit args |
132 | 133 | $edit_args = array(); |
133 | 134 | |
| 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 | |
134 | 148 | // 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 ) { |
136 | 150 | $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, |
139 | 153 | ); |
140 | 154 | } |
141 | 155 | |
diff --git src/bp-core/js/bp-plupload.js src/bp-core/js/bp-plupload.js
index d758516..85d311c 100644
|
|
window.bp = window.bp || {}; |
60 | 60 | * @param {plupload.Uploader} uploader Uploader instance. |
61 | 61 | */ |
62 | 62 | this.uploader.bind( 'Init', function( uploader ) { |
63 | | var container = $( '#' + self.params.defaults.container ), |
| 63 | var container = $( '#' + self.params.defaults.container ), |
64 | 64 | drop_element = $( '#' + self.params.defaults.drop_element ); |
65 | 65 | |
66 | 66 | if ( 'html4' === uploader.runtime ) { |
67 | 67 | uploader.settings.multipart_params.html4 = true; |
68 | 68 | } |
69 | 69 | |
| 70 | /** |
| 71 | * Avatars need to be cropped, by default we are using an original |
| 72 | * max width of 450px, but there can be cases when this max width |
| 73 | * is larger than the one of the Avatar UI (eg: on mobile). To avoid any |
| 74 | * difficulties, we're adding a browser_max_width argument to the bp_params |
| 75 | * object and set it according to the container width. This value will be |
| 76 | * checked during the upload process to eventually adapt the resized avatar. |
| 77 | */ |
| 78 | if ( 'bp_avatar_upload' === uploader.settings.multipart_params.action ) { |
| 79 | uploader.settings.multipart_params.bp_params.browser_max_width = container.width(); |
| 80 | } |
| 81 | |
70 | 82 | if ( uploader.features.dragdrop && ! self.params.browser.mobile ) { |
71 | 83 | container.addClass( 'drag-drop' ); |
72 | 84 | drop_element.bind( 'dragover.wp-uploader', function() { |