Changeset 10039 for trunk/src/bp-core/bp-core-avatars.php
- Timestamp:
- 08/09/2015 05:07:56 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-avatars.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-avatars.php
r10012 r10039 1 1 <?php 2 3 2 /** 4 3 * BuddyPress Avatars. 5 */ 6 7 // Exit if accessed directly 4 * 5 * @package BuddyPress 6 */ 7 8 // Exit if accessed directly. 8 9 defined( 'ABSPATH' ) || exit; 9 10 10 /** *11 /** 11 12 * Set up the constants we need for avatar support. 12 13 */ … … 326 327 /** Sanity Checks *********************************************************/ 327 328 328 // Get a fallback for the 'alt' parameter, create html output 329 // Get a fallback for the 'alt' parameter, create html output. 329 330 if ( empty( $params['alt'] ) ) { 330 331 $params['alt'] = __( 'Profile Photo', 'buddypress' ); … … 332 333 $html_alt = ' alt="' . esc_attr( $params['alt'] ) . '"'; 333 334 334 // Filter image title and create html string 335 // Filter image title and create html string. 335 336 $html_title = ''; 336 337 … … 351 352 } 352 353 353 // Set CSS ID and create html string 354 // Set CSS ID and create html string. 354 355 $html_css_id = ''; 355 356 … … 531 532 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id . $html_width . $html_height . $html_alt . $html_title . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir ); 532 533 533 // ...or only the URL534 // ...or only the URL 534 535 } else { 535 536 … … 612 613 } 613 614 614 // No avatar was found, and we've been told not to use a gravatar.615 // No avatar was found, and we've been told not to use a gravatar. 615 616 } else { 616 617 … … 644 645 * @param array|string $args { 645 646 * Array of function parameters. 646 * @type bool|int $item_id ID of the item whose avatar you're deleting. 647 * Defaults to the current item of type $object. 648 * @type string $object Object type of the item whose avatar you're 649 * deleting. 'user', 'group', 'blog', or custom. Default: 'user'. 647 * @type bool|int $item_id ID of the item whose avatar you're deleting. 648 * Defaults to the current item of type $object. 649 * @type string $object Object type of the item whose avatar you're 650 * deleting. 'user', 'group', 'blog', or custom. 651 * Default: 'user'. 650 652 * @type bool|string $avatar_dir Subdirectory where avatar is located. 651 * Default: false, which falls back on the default location652 * corresponding to the $object.653 * Default: false, which falls back on the default location 654 * corresponding to the $object. 653 655 * } 654 656 * @return bool True on success, false on failure. … … 730 732 */ 731 733 function bp_avatar_ajax_delete() { 732 // Bail if not a POST action 734 // Bail if not a POST action. 733 735 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 734 736 wp_send_json_error(); … … 810 812 } 811 813 812 // Setup some variables 814 // Setup some variables. 813 815 $bp = buddypress(); 814 816 $upload_path = bp_core_avatar_upload_path(); 815 817 816 // Upload the file 818 // Upload the file. 817 819 $avatar_attachment = new BP_Attachment_Avatar(); 818 820 $bp->avatar_admin->original = $avatar_attachment->upload( $file, $upload_dir_filter ); 819 821 820 // In case of an error, stop the process and display a feedback to the user 822 // In case of an error, stop the process and display a feedback to the user. 821 823 if ( ! empty( $bp->avatar_admin->original['error'] ) ) { 822 824 bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' ); … … 824 826 } 825 827 826 // Maybe resize 828 // Maybe resize. 827 829 $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'] ); 828 830 $bp->avatar_admin->image = new stdClass(); … … 838 840 } 839 841 840 // Check for WP_Error on what should be an image 842 // Check for WP_Error on what should be an image. 841 843 if ( is_wp_error( $bp->avatar_admin->image->dir ) ) { 842 844 bp_core_add_message( sprintf( __( 'Upload failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->image->dir->get_error_message() ), 'error' ); … … 844 846 } 845 847 846 // If the uploaded image is smaller than the "full" dimensions, throw a warning 848 // If the uploaded image is smaller than the "full" dimensions, throw a warning. 847 849 if ( $avatar_attachment->is_too_small( $bp->avatar_admin->image->file ) ) { 848 850 bp_core_add_message( sprintf( __( 'You have selected an image that is smaller than recommended. For best results, upload a picture larger than %d x %d pixels.', 'buddypress' ), bp_core_avatar_full_width(), bp_core_avatar_full_height() ), 'error' ); 849 851 } 850 852 851 // Set the url value for the image 853 // Set the url value for the image. 852 854 $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir; 853 855 … … 1005 1007 1006 1008 /** 1007 * Handle avatar webcam capture. 1008 * 1009 * @since BuddyPress (2.3.0) 1010 * 1011 * @param string $data Base64 encoded image. 1012 * @param int $item_id. 1009 * Handle avatar webcam capture. 1013 1010 * 1014 * @return bool True on success, false on failure. 1015 */ 1011 * @since BuddyPress (2.3.0) 1012 * 1013 * @param string $data Base64 encoded image. 1014 * @param int $item_id Item to associate. 1015 * 1016 * @return bool True on success, false on failure. 1017 */ 1016 1018 function bp_avatar_handle_capture( $data = '', $item_id = 0 ) { 1017 1019 if ( empty( $data ) || empty( $item_id ) ) { … … 1021 1023 $avatar_dir = bp_core_avatar_upload_path() . '/avatars'; 1022 1024 1023 // It's not a regular upload, we may need to create this folder 1025 // It's not a regular upload, we may need to create this folder. 1024 1026 if ( ! file_exists( $avatar_dir ) ) { 1025 1027 if ( ! wp_mkdir_p( $avatar_dir ) ) { … … 1040 1042 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', $avatar_dir . '/' . $item_id, $item_id, 'user', 'avatars' ); 1041 1043 1042 // It's not a regular upload, we may need to create this folder 1044 // It's not a regular upload, we may need to create this folder. 1043 1045 if( ! is_dir( $avatar_folder_dir ) ) { 1044 1046 if ( ! wp_mkdir_p( $avatar_folder_dir ) ) { … … 1449 1451 } 1450 1452 1451 // See if the value has already been calculated and stashed in the $bp global 1453 // See if the value has already been calculated and stashed in the $bp global. 1452 1454 if ( isset( $bp->avatar->$type ) ) { 1453 1455 $retval = $bp->avatar->$type; 1454 1456 } else { 1455 // If this value has been set in a constant, just use that 1457 // If this value has been set in a constant, just use that. 1456 1458 if ( defined( $constant ) ) { 1457 1459 $retval = constant( $constant ); 1458 1460 } else { 1459 1461 1460 // Use cached upload dir data if available 1462 // Use cached upload dir data if available. 1461 1463 if ( ! empty( $bp->avatar->upload_dir ) ) { 1462 1464 $upload_dir = $bp->avatar->upload_dir; 1463 1465 1464 // No cache, so query for it 1466 // No cache, so query for it. 1465 1467 } else { 1466 1468 1467 // Get upload directory information from current site 1469 // Get upload directory information from current site. 1468 1470 $upload_dir = bp_upload_dir(); 1469 1471 1470 // Stash upload directory data for later use 1472 // Stash upload directory data for later use. 1471 1473 $bp->avatar->upload_dir = $upload_dir; 1472 1474 } 1473 1475 1474 // Directory does not exist and cannot be created 1476 // Directory does not exist and cannot be created. 1475 1477 if ( ! empty( $upload_dir['error'] ) ) { 1476 1478 $retval = ''; … … 1488 1490 } 1489 1491 1490 // Stash in $bp for later use 1492 // Stash in $bp for later use. 1491 1493 $bp->avatar->$type = $retval; 1492 1494 }
Note: See TracChangeset
for help on using the changeset viewer.