- Timestamp:
- 11/15/2015 07:13:42 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment-avatar.php
r10206 r10355 29 29 */ 30 30 public function __construct() { 31 // Allowed avatar types 31 // Allowed avatar types. 32 32 $allowed_types = bp_core_get_allowed_avatar_types(); 33 33 … … 37 37 'original_max_filesize' => bp_core_avatar_original_max_filesize(), 38 38 39 // Specific errors for avatars 39 // Specific errors for avatars. 40 40 'upload_error_strings' => array( 41 41 9 => sprintf( __( 'That photo is too big. Please upload one smaller than %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), … … 51 51 * 52 52 * @param array $allowed_types Array of allowed avatar types. 53 *54 53 * @return string comma separated list of allowed avatar types. 55 54 */ … … 92 91 * 93 92 * @param array $file the temporary file attributes (before it has been moved). 94 *95 93 * @return array the file with extra errors if needed. 96 94 */ 97 95 public function validate_upload( $file = array() ) { 98 // Bail if already an error 96 // Bail if already an error. 99 97 if ( ! empty( $file['error'] ) ) { 100 98 return $file; 101 99 } 102 100 103 // File size is too big 101 // File size is too big. 104 102 if ( ! bp_core_check_avatar_size( array( 'file' => $file ) ) ) { 105 103 $file['error'] = 9; 106 104 107 // File is of invalid type 105 // File is of invalid type. 108 106 } elseif ( ! bp_core_check_avatar_type( array( 'file' => $file ) ) ) { 109 107 $file['error'] = 10; 110 108 } 111 109 112 // Return with error code attached 110 // Return with error code attached. 113 111 return $file; 114 112 } … … 122 120 * @uses bp_core_avatar_original_max_width() 123 121 * 124 * @param string $file the absolute path to the file.125 * 122 * @param string $file The absolute path to the file. 123 * @param int $ui_available_width Available width for the UI. 126 124 * @return mixed 127 125 */ 128 126 public static function shrink( $file = '', $ui_available_width = 0 ) { 129 // Get image size 127 // Get image size. 130 128 $avatar_data = parent::get_image_data( $file ); 131 129 132 // Init the edit args 130 // Init the edit args. 133 131 $edit_args = array(); 134 132 … … 136 134 $original_max_width = bp_core_avatar_original_max_width(); 137 135 138 // The ui_available_width is defined and it's smaller than the Avatar original max width 136 // The ui_available_width is defined and it's smaller than the Avatar original max width. 139 137 if ( ! empty( $ui_available_width ) && $ui_available_width < $original_max_width ) { 140 138 /** … … 150 148 } 151 149 152 // Do we need to resize the image ?150 // Do we need to resize the image? 153 151 if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > $original_max_width ) { 154 152 $edit_args = array( … … 158 156 } 159 157 160 // Do we need to rotate the image ?158 // Do we need to rotate the image? 161 159 $angles = array( 162 160 3 => 180, … … 169 167 } 170 168 171 // No need to edit the avatar, original file will be used 169 // No need to edit the avatar, original file will be used. 172 170 if ( empty( $edit_args ) ) { 173 171 return false; 174 172 175 // Add the file to the edit arguments 173 // Add the file to the edit arguments. 176 174 } else { 177 175 $edit_args['file'] = $file; … … 190 188 * 191 189 * @param string $file the absolute path to the file. 192 * 193 * @return boolean 190 * @return bool 194 191 */ 195 192 public static function is_too_small( $file = '' ) { … … 218 215 * @uses BP_Attachment::crop 219 216 * 220 * @param array $args 221 * 217 * @param array $args Array of arguments for the cropping. 222 218 * @return array The cropped avatars (full and thumb). 223 219 */ 224 220 public function crop( $args = array() ) { 225 // Bail if the original file is missing 221 // Bail if the original file is missing. 226 222 if ( empty( $args['original_file'] ) ) { 227 223 return false; … … 235 231 $absolute_path = $this->upload_path . $relative_path; 236 232 237 // Bail if the avatar is not available 233 // Bail if the avatar is not available. 238 234 if ( ! file_exists( $absolute_path ) ) { 239 235 return false; … … 250 246 } 251 247 252 // Bail if the avatar folder is missing for this item_id 248 // Bail if the avatar folder is missing for this item_id. 253 249 if ( ! file_exists( $avatar_folder_dir ) ) { 254 250 return false; 255 251 } 256 252 257 // Delete the existing avatar files for the object 253 // Delete the existing avatar files for the object. 258 254 $existing_avatar = bp_core_fetch_avatar( array( 259 255 'object' => $args['object'], … … 270 266 } 271 267 272 // Make sure we at least have minimal data for cropping 268 // Make sure we at least have minimal data for cropping. 273 269 if ( empty( $args['crop_w'] ) ) { 274 270 $args['crop_w'] = bp_core_avatar_full_width(); … … 279 275 } 280 276 281 // Get the file extension 277 // Get the file extension. 282 278 $data = @getimagesize( $absolute_path ); 283 279 $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg'; … … 301 297 } 302 298 303 // Remove the original 299 // Remove the original. 304 300 @unlink( $absolute_path ); 305 301 306 // Return the full and thumb cropped avatars 302 // Return the full and thumb cropped avatars. 307 303 return $avatar_types; 308 304 } … … 355 351 */ 356 352 public function script_data() { 357 // Get default script data 353 // Get default script data. 358 354 $script_data = parent::script_data(); 359 355 360 // Defaults to Avatar Backbone script 356 // Defaults to Avatar Backbone script. 361 357 $js_scripts = array( 'bp-avatar' ); 362 358 363 // Default object 359 // Default object. 364 360 $object = ''; 365 361 366 // Get the possible item ids 362 // Get the possible item ids. 367 363 $user_id = $this->get_user_id(); 368 364 $group_id = $this->get_group_id(); 369 365 370 366 if ( ! empty( $user_id ) ) { 371 // Should we load the the Webcam Avatar javascript file 367 // Should we load the the Webcam Avatar javascript file. 372 368 if ( bp_avatar_use_webcam() ) { 373 369 $js_scripts = array( 'bp-webcam' ); … … 384 380 ); 385 381 386 // Set feedback messages 382 // Set feedback messages. 387 383 $script_data['feedback_messages'] = array( 388 384 1 => __( 'There was a problem cropping your profile photo.', 'buddypress' ), … … 402 398 ); 403 399 404 // Set feedback messages 400 // Set feedback messages. 405 401 $script_data['feedback_messages'] = array( 406 402 1 => __( 'There was a problem cropping the group profile photo.', 'buddypress' ), … … 422 418 } 423 419 424 // Include the specific css 420 // Include the specific css. 425 421 $script_data['extra_css'] = array( 'bp-avatar' ); 426 422 427 // Include the specific css 423 // Include the specific css. 428 424 $script_data['extra_js'] = $js_scripts; 429 425 430 // Set the object to contextualize the filter 426 // Set the object to contextualize the filter. 431 427 if ( isset( $script_data['bp_params']['object'] ) ) { 432 428 $object = $script_data['bp_params']['object'];
Note: See TracChangeset
for help on using the changeset viewer.