Skip to:
Content

BuddyPress.org

Changeset 11320


Ignore:
Timestamp:
12/22/2016 08:28:41 PM (10 years ago)
Author:
djpaul
Message:

Avatars: improve robustness of crop process by confirming crop data.

For the 2.2 branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/src/bp-core/bp-core-avatars.php

    r9381 r11320  
    751751                return false;
    752752
    753         $original_file = bp_core_avatar_upload_path() . $original_file;
     753        if ( 'user' === $object ) {
     754                $avatar_dir = 'avatars';
     755        } else {
     756                $avatar_dir = sanitize_key( $args['object'] ) . '-avatars';
     757        }
     758
     759        $original_file = sprintf( '%s/%s/%s/%s', bp_core_avatar_upload_path(), $avatar_dir, $item_id, basename( $original_file ) );
    754760
    755761        if ( !file_exists( $original_file ) )
    756762                return false;
     763
     764        // Capability check.
     765        $has_cap = bp_current_user_can( 'bp_moderate' );
     766        if ( ! $has_cap ) {
     767                if ( 'user' === $object ) {
     768                        $has_cap = bp_loggedin_user_id() === (int) $args['item_id'];
     769                } elseif ( 'group' === $object && bp_is_active( 'groups' ) ) {
     770                        if ( bp_is_group_create() ) {
     771                                $has_cap = (bool) groups_is_user_creator( bp_loggedin_user_id(), $args['item_id'] );
     772                        } else {
     773                                $has_cap = (bool) groups_is_user_admin( bp_loggedin_user_id(), $args['item_id'] );
     774                        }
     775                }
     776        }
     777
     778        if ( ! $has_cap ) {
     779                return false;
     780        }
    757781
    758782        if ( empty( $item_id ) ) {
Note: See TracChangeset for help on using the changeset viewer.