Changeset 3757 for trunk/bp-core/bp-core-avatars.php
- Timestamp:
- 01/20/2011 10:53:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-avatars.php
r3742 r3757 1 1 <?php 2 /* 3 Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/ 4 Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/ 5 */ 2 /** 3 * BuddyPress Avatars 4 * 5 * Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/ 6 * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/ 7 */ 6 8 7 9 /*** … … 34 36 if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) { 35 37 if ( !isset( $bp->site_options['fileupload_maxk'] ) ) 36 define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); / * 5mb */38 define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb 37 39 else 38 40 define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 ); … … 45 47 define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' ); 46 48 } 47 add_action( 'bp_init', 'bp_core_set_avatar_constants', 8);49 add_action( 'bp_init', 'bp_core_set_avatar_constants', 3 ); 48 50 49 51 /** … … 164 166 * or thumbnail image. 165 167 */ 166 $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';167 $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';168 $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb'; 169 $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1'; 168 170 $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb'; 169 171 … … 263 265 264 266 // Filter gravatar vars 265 $email 266 $gravatar 267 $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object ); 268 $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&s=' . $grav_size; 267 269 268 270 } else { … … 281 283 282 284 $defaults = array( 283 'item_id' => false,284 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)285 'item_id' => false, 286 'object' => 'user', // user OR group OR blog OR custom type (if you use filters) 285 287 'avatar_dir' => false 286 288 ); … … 372 374 } 373 375 374 / * Filter the upload location */376 // Filter the upload location 375 377 add_filter( 'upload_dir', $upload_dir_filter, 10, 0 ); 376 378 377 379 $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) ); 378 380 379 / * Move the file to the correct upload location. */381 // Move the file to the correct upload location. 380 382 if ( !empty( $bp->avatar_admin->original['error'] ) ) { 381 383 bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' ); … … 383 385 } 384 386 385 / * Get image size */387 // Get image size 386 388 $size = @getimagesize( $bp->avatar_admin->original['file'] ); 387 389 388 / * Check image size and shrink if too large */390 // Check image size and shrink if too large 389 391 if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) { 390 392 $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH ); 391 393 392 / * Check for thumbnail creation errors */394 // Check for thumbnail creation errors 393 395 if ( is_wp_error( $thumb ) ) { 394 396 bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' ); … … 396 398 } 397 399 398 / * Thumbnail is good so proceed */400 // Thumbnail is good so proceed 399 401 $bp->avatar_admin->resized = $thumb; 400 402 } 401 403 402 / * We only want to handle one image after resize. */404 // We only want to handle one image after resize. 403 405 if ( empty( $bp->avatar_admin->resized ) ) 404 406 $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] ); … … 414 416 } 415 417 416 / * Set the url value for the image */418 // Set the url value for the image 417 419 $bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir; 418 420 … … 424 426 425 427 $defaults = array( 426 'object' => 'user',427 'avatar_dir' => 'avatars',428 'item_id' => false,428 'object' => 'user', 429 'avatar_dir' => 'avatars', 430 'item_id' => false, 429 431 'original_file' => false, 430 'crop_w' => BP_AVATAR_FULL_WIDTH,431 'crop_h' => BP_AVATAR_FULL_HEIGHT,432 'crop_x' => 0,433 'crop_y' => 0432 'crop_w' => BP_AVATAR_FULL_WIDTH, 433 'crop_h' => BP_AVATAR_FULL_HEIGHT, 434 'crop_x' => 0, 435 'crop_y' => 0 434 436 ); 435 437 … … 464 466 require_once( ABSPATH . '/wp-admin/includes/file.php' ); 465 467 466 / * Delete the existing avatar files for the object */468 // Delete the existing avatar files for the object 467 469 bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) ); 468 470 469 / * Make sure we at least have a width and height for cropping */471 // Make sure we at least have a width and height for cropping 470 472 if ( !(int)$crop_w ) 471 473 $crop_w = BP_AVATAR_FULL_WIDTH; … … 474 476 $crop_h = BP_AVATAR_FULL_HEIGHT; 475 477 476 / * Set the full and thumb filenames */477 $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';478 // Set the full and thumb filenames 479 $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg'; 478 480 $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg'; 479 481 480 / * Crop the image */481 $full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );482 // Crop the image 483 $full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename ); 482 484 $thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename ); 483 485 484 / * Remove the original */486 // Remove the original 485 487 @unlink( $original_file ); 486 488
Note: See TracChangeset
for help on using the changeset viewer.