Changeset 6600
- Timestamp:
- 12/10/2012 12:52:16 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
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 -
trunk/bp-core/bp-core-cssjs.php
r6597 r6600 1 1 <?php 2 2 3 // Exit if accessed directly 3 4 if ( !defined( 'ABSPATH' ) ) exit; … … 26 27 }); 27 28 </script> 29 28 30 <?php 29 31 } … … 39 41 */ 40 42 function bp_core_add_jquery_cropper() { 43 wp_enqueue_style( 'jcrop' ); 41 44 wp_enqueue_script( 'jcrop', array( 'jquery' ) ); 42 45 add_action( 'wp_head', 'bp_core_add_cropper_inline_js' ); … … 52 55 */ 53 56 function bp_core_add_cropper_inline_js() { 54 global $bp;55 57 56 $image = apply_filters( 'bp_inline_cropper_image', getimagesize( bp_core_avatar_upload_path() . $bp->avatar_admin->image->dir ) ); 57 $aspect_ratio = 1; 58 // Bail if no image was uploaded 59 $image = apply_filters( 'bp_inline_cropper_image', getimagesize( bp_core_avatar_upload_path() . buddypress()->avatar_admin->image->dir ) ); 60 if ( empty( $image ) ) 61 return; 58 62 63 // 59 64 $full_height = bp_core_avatar_full_height(); 60 65 $full_width = bp_core_avatar_full_width(); 61 66 62 67 // Calculate Aspect Ratio 63 if ( $full_height && ( $full_width != $full_height ) )68 if ( !empty( $full_height ) && ( $full_width != $full_height ) ) { 64 69 $aspect_ratio = $full_width / $full_height; 70 } else { 71 $aspect_ratio = 1; 72 } 65 73 66 $width = $image[0] / 2; 67 $height = $image[1] / 2; 68 ?> 74 // Default cropper coordinates 75 $crop_left = $image[0] / 4; 76 $crop_top = $image[1] / 4; 77 $crop_right = $image[0] - $crop_left; 78 $crop_bottom = $image[1] - $crop_top; ?> 69 79 70 80 <script type="text/javascript"> … … 74 84 onSelect: showPreview, 75 85 onSelect: updateCoords, 76 aspectRatio: <?php echo $aspect_ratio ?>,77 setSelect: [ 50, 50, <?php echo $width ?>, <?php echo $height?> ]86 aspectRatio: <?php echo $aspect_ratio; ?>, 87 setSelect: [ <?php echo $crop_left; ?>, <?php echo $crop_top; ?>, <?php echo $crop_right; ?>, <?php echo $crop_bottom; ?> ] 78 88 }); 79 updateCoords({x: 50, y: 50, w: <?php echo $width ?>, h: <?php echo $height?>});89 updateCoords({x: <?php echo $crop_left; ?>, y: <?php echo $crop_top; ?>, w: <?php echo $crop_right; ?>, h: <?php echo $crop_bottom; ?>}); 80 90 }); 81 91 … … 89 99 function showPreview(coords) { 90 100 if ( parseInt(coords.w) > 0 ) { 91 var rx = <?php echo $full_width; ?> / coords.w; 92 var ry = <?php echo $full_height; ?> / coords.h; 101 var fw = <?php echo $full_width; ?>; 102 var fh = <?php echo $full_height; ?>; 103 var rx = fw / coords.w; 104 var ry = fh / coords.h; 93 105 94 jQuery('#avatar-crop-preview').css({ 95 <?php if ( $image ) : ?> 106 jQuery( '#avatar-crop-preview' ).css({ 96 107 width: Math.round(rx * <?php echo $image[0]; ?>) + 'px', 97 108 height: Math.round(ry * <?php echo $image[1]; ?>) + 'px', 98 <?php endif; ?>99 109 marginLeft: '-' + Math.round(rx * coords.x) + 'px', 100 110 marginTop: '-' + Math.round(ry * coords.y) + 'px' … … 119 129 <style type="text/css"> 120 130 .jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; } 121 .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url('<?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif'); }122 .jcrop-vline { height: 100%; width: 1px !important; }123 .jcrop-hline { width: 100%; height: 1px !important; }124 .jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }125 .jcrop-tracker { width: 100%; height: 100%; }126 .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }127 .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }128 131 #avatar-crop-pane { width: <?php echo bp_core_avatar_full_width() ?>px; height: <?php echo bp_core_avatar_full_height() ?>px; overflow: hidden; } 129 132 #avatar-crop-submit { margin: 20px 0; } 130 #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; } 133 #avatar-upload-form img, 134 #create-group-form img, 135 #group-settings-form img { border: none !important; max-width: none !important; } 131 136 </style> 132 137 -
trunk/bp-xprofile/bp-xprofile-screens.php
r6395 r6600 37 37 */ 38 38 function xprofile_screen_edit_profile() { 39 global $bp;40 39 41 40 if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) ) 42 41 return false; 42 43 $bp = buddypress(); 43 44 44 45 // Make sure a group is set. … … 105 106 106 107 // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. 107 if ( empty( $_POST['field_' . $field_id] ) ) 108 if ( empty( $_POST['field_' . $field_id] ) ) { 108 109 $value = array(); 109 else110 } else { 110 111 $value = $_POST['field_' . $field_id]; 111 112 if ( !xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[$field_id] ) ) 112 } 113 114 if ( !xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[$field_id] ) ) { 113 115 $errors = true; 114 else116 } else { 115 117 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 118 } 116 119 117 120 // Save the visibility level … … 123 126 124 127 // Set the feedback messages 125 if ( !empty( $errors ) ) 128 if ( !empty( $errors ) ) { 126 129 bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' ); 127 else130 } else { 128 131 bp_core_add_message( __( 'Changes saved.', 'buddypress' ) ); 132 } 129 133 130 134 // Redirect back to the edit screen to display the updates and message … … 145 149 */ 146 150 function xprofile_screen_change_avatar() { 147 global $bp; 148 151 152 // Bail if not the correct screen 149 153 if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) ) 150 154 return false; 151 155 156 // Bail if there are action variables 152 157 if ( bp_action_variables() ) { 153 158 bp_do_404(); … … 155 160 } 156 161 162 $bp = buddypress(); 163 157 164 if ( ! isset( $bp->avatar_admin ) ) 158 165 $bp->avatar_admin = new stdClass(); … … 180 187 check_admin_referer( 'bp_avatar_cropstore' ); 181 188 182 if ( !bp_core_avatar_handle_crop( array( 'item_id' => bp_displayed_user_id(), 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) ) 183 bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' ); 184 else { 185 bp_core_add_message( __( 'Your new avatar was uploaded successfully!', 'buddypress' ) ); 189 $args = array( 190 'item_id' => bp_displayed_user_id(), 191 'original_file' => $_POST['image_src'], 192 'crop_x' => $_POST['x'], 193 'crop_y' => $_POST['y'], 194 'crop_w' => $_POST['w'], 195 'crop_h' => $_POST['h'] 196 ); 197 198 if ( ! bp_core_avatar_handle_crop( $args ) ) { 199 bp_core_add_message( __( 'There was a problem cropping your avatar.', 'buddypress' ), 'error' ); 200 } else { 201 bp_core_add_message( __( 'Your new avatar was uploaded successfully.', 'buddypress' ) ); 186 202 do_action( 'xprofile_avatar_uploaded' ); 187 203 }
Note: See TracChangeset
for help on using the changeset viewer.