Changeset 6600 for trunk/bp-core/bp-core-avatars.php
- Timestamp:
- 12/10/2012 12:52:16 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/bp-core/bp-core-avatars.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-avatars.php
r6564 r6600 483 483 484 484 $uploadErrors = array( 485 0 => __( "There is no error, the file uploaded with success", 'buddypress'),486 1 => __( "Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format( bp_core_avatar_original_max_filesize() ),487 2 => __( "Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format( bp_core_avatar_original_max_filesize() ),488 3 => __( "The uploaded file was only partially uploaded", 'buddypress'),489 4 => __( "No file was uploaded", 'buddypress'),490 6 => __( "Missing a temporary folder", 'buddypress')485 0 => __( 'The image was uploaded successfully', 'buddypress' ), 486 1 => __( 'The image exceeds the maximum allowed file size of: ', 'buddypress' ) . size_format( bp_core_avatar_original_max_filesize() ), 487 2 => __( 'The image exceeds the maximum allowed file size of: ', 'buddypress' ) . size_format( bp_core_avatar_original_max_filesize() ), 488 3 => __( 'The uploaded file was only partially uploaded.', 'buddypress' ), 489 4 => __( 'The image was not uploaded.', 'buddypress' ), 490 6 => __( 'Missing a temporary folder.', 'buddypress' ) 491 491 ); 492 492 493 if ( ! bp_core_check_avatar_upload( $file ) ) {493 if ( ! bp_core_check_avatar_upload( $file ) ) { 494 494 bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' ); 495 495 return false; 496 496 } 497 497 498 if ( ! bp_core_check_avatar_size( $file ) ) {499 bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), 'error' );500 return false; 501 } 502 503 if ( ! bp_core_check_avatar_type( $file ) ) {498 if ( ! bp_core_check_avatar_size( $file ) ) { 499 bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), 'error' ); 500 return false; 501 } 502 503 if ( ! bp_core_check_avatar_type( $file ) ) { 504 504 bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' ); 505 505 return false; … … 531 531 532 532 $resized = $editor->resize( bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false ); 533 if ( ! is_wp_error( $resized ) ) 533 if ( ! is_wp_error( $resized ) ) { 534 534 $thumb = $editor->save( $editor->generate_filename() ); 535 else535 } else { 536 536 $error = $resized; 537 } 537 538 538 539 // Check for thumbnail creation errors 539 if ( false === $error && is_wp_error( $thumb ) ) 540 if ( false === $error && is_wp_error( $thumb ) ) { 540 541 $error = $thumb; 541 542 } 543 544 // Thumbnail is good so proceed 542 545 if ( false === $error ) { 543 // Thumbnail is good so proceed544 546 $bp->avatar_admin->resized = $thumb; 545 547 } … … 556 558 557 559 // We only want to handle one image after resize. 558 if ( empty( $bp->avatar_admin->resized ) ) 560 if ( empty( $bp->avatar_admin->resized ) ) { 559 561 $bp->avatar_admin->image->dir = str_replace( bp_core_avatar_upload_path(), '', $bp->avatar_admin->original['file'] ); 560 else {562 } else { 561 563 $bp->avatar_admin->image->dir = str_replace( bp_core_avatar_upload_path(), '', $bp->avatar_admin->resized['path'] ); 562 564 @unlink( $bp->avatar_admin->original['file'] ); … … 593 595 function bp_core_avatar_handle_crop( $args = '' ) { 594 596 595 $ defaults =array(597 $r = wp_parse_args( $args, array( 596 598 'object' => 'user', 597 599 'avatar_dir' => 'avatars', … … 602 604 'crop_x' => 0, 603 605 'crop_y' => 0 604 ); 605 606 $r = wp_parse_args( $args, $defaults ); 606 ) ); 607 607 608 608 /*** … … 615 615 extract( $r, EXTR_SKIP ); 616 616 617 if ( !$original_file)617 if ( empty( $original_file ) ) 618 618 return false; 619 619 … … 623 623 return false; 624 624 625 if ( !$item_id )625 if ( empty( $item_id ) ) { 626 626 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir ); 627 else627 } else { 628 628 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 629 } 629 630 630 631 if ( !file_exists( $avatar_folder_dir ) ) … … 638 639 639 640 // Make sure we at least have a width and height for cropping 640 if ( !(int) $crop_w )641 if ( empty( $crop_w ) ) { 641 642 $crop_w = bp_core_avatar_full_width(); 642 643 if ( !(int) $crop_h ) 643 } 644 645 if ( empty( $crop_h ) ) { 644 646 $crop_h = bp_core_avatar_full_height(); 647 } 648 649 // Get the file extension 650 $data = @getimagesize( $original_file ); 651 $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg'; 645 652 646 653 // Set the full and thumb filenames 647 $full_filename = wp_hash( $original_file . time() ) . '-bpfull. jpg';648 $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb. jpg';654 $full_filename = wp_hash( $original_file . time() ) . '-bpfull.' . $ext; 655 $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.' . $ext; 649 656 650 657 // Crop the image 651 $full_cropped = wp_crop_image( $original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename);658 $full_cropped = wp_crop_image( $original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename ); 652 659 $thumb_cropped = wp_crop_image( $original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename ); 653 660 654 661 // Check for errors 655 if ( ! $full_cropped || ! $thumb_cropped|| is_wp_error( $full_cropped ) || is_wp_error( $thumb_cropped ) )662 if ( empty( $full_cropped ) || empty( $thumb_cropped ) || is_wp_error( $full_cropped ) || is_wp_error( $thumb_cropped ) ) 656 663 return false; 657 664 … … 684 691 685 692 // If passed an object, assume $user->user_id 686 if ( is_object( $user ) ) 693 if ( is_object( $user ) ) { 687 694 $id = $user->user_id; 688 695 689 696 // If passed a number, assume it was a $user_id 690 else if ( is_numeric( $user ) )697 } else if ( is_numeric( $user ) ) { 691 698 $id = $user; 692 699 693 700 // If passed a string and that string returns a user, get the $id 694 else if ( is_string( $user ) && ( $user_by_email = get_user_by( 'email', $user ) ) )701 } elseif ( is_string( $user ) && ( $user_by_email = get_user_by( 'email', $user ) ) ) { 695 702 $id = $user_by_email->ID; 703 } 696 704 697 705 // If somehow $id hasn't been assigned, return the result of get_avatar 698 if ( empty( $id ) ) 706 if ( empty( $id ) ) { 699 707 return !empty( $avatar ) ? $avatar : $default; 700 701 if ( !$alt ) 708 } 709 710 // Image alt tag 711 if ( empty( $alt ) ) { 702 712 $alt = sprintf( __( 'Avatar of %s', 'buddypress' ), bp_core_get_user_displayname( $id ) ); 713 } 703 714 704 715 // Let BuddyPress handle the fetching of the avatar
Note: See TracChangeset
for help on using the changeset viewer.