Skip to:
Content

BuddyPress.org

Ticket #3695: 3695.001.diff

File 3695.001.diff, 7.8 KB (added by cnorris23, 13 years ago)
  • bp-themes/bp-default/members/single/profile/edit.php

     
    116116                                <?php do_action( 'bp_custom_profile_edit_fields' ); ?>
    117117
    118118                                <p class="description"><?php bp_the_profile_field_description(); ?></p>
     119                                <?php bp_xprofile_privacy_inputs(); ?>
    119120                        </div>
    120121
    121122                <?php endwhile; ?>
  • bp-xprofile/bp-xprofile-functions.php

     
    602602        return apply_filters( 'bp_xprofile_fullname_field_name', BP_XPROFILE_FULLNAME_FIELD_NAME );
    603603}
    604604
     605function bp_xprofile_privacy_inputs() {
     606        echo bp_get_xprofile_privacy_inputs();
     607}
     608
     609function bp_get_xprofile_privacy_inputs() {
     610        $field_id   = bp_get_the_profile_field_id();
     611        $field_name = bp_get_the_profile_field_name();
     612
     613        // Get the user's profile field privacy setting
     614        $privacy = (array) bp_xprofile_get_meta( $field_id, 'field', 'bp_profile_privacy_' . bp_loggedin_user_id() );
     615
     616        // If they've not setting, use the default
     617        if ( empty( $privacy ) )
     618                $privacy = (array) bp_xprofile_get_meta( $field_id, 'field', 'bp_profile_privacy_default' );
     619
     620        // Fallback for cases where there's no user setting or admin declared default
     621        if ( empty( $privacy ) )
     622                $privacy = array( 'public' );
     623
     624        $inputs = apply_filters( 'bp_xprofile_privacy_inputs', array(
     625                'public' => array(
     626                        'text' => __( 'Everyone', 'buddypress' ),
     627                        'checked' => in_array( 'public', $privacy ) ? 'public' : false,
     628                ),
     629                'logged_in_users' => array(
     630                        'text'    => __( 'Only Logged In Users', 'buddypress' ),
     631                        'checked' => in_array( 'logged_in_users', $privacy ) ? 'logged_in_users' : false,
     632                ),
     633                'friends' => array(
     634                        'text'    => __( 'My Friends', 'buddypress' ),
     635                        'checked' => in_array( 'friends', $privacy ) ? 'friends' : false,
     636                ),
     637                'groups' => array(
     638                        'text'    => __( 'Memebers of My Groups', 'buddypress' ),
     639                        'checked' => in_array( 'groups', $privacy ) ? 'groups' : false,
     640                ),
     641                'none' => array(
     642                        'text'    => __( 'No One', 'buddypress' ),
     643                        'checked' => in_array( 'none', $privacy ) ? 'none' : false,
     644                ),
     645        ) );
     646
     647        foreach ( (array) $inputs as $value => $data ) {
     648                $html[] = $data['text'] . ': <input name="bp_xprofile_field_privacy_options_' . $field_id . '[]" type="checkbox"' . checked( $value, $data['checked'], false ) . ' value="' . $value . '">';
     649        }
     650
     651        $title = '<strong>' . sprintf( __( "Privacy settings for '%s': ", 'buddypress' ), $field_name ) . '</strong>';
     652
     653        return apply_filters( 'bp_xprofile_privacy_inputs_html', $title . join( $html, '&nbsp;&nbsp;&nbsp;' ) );
     654}
     655
    605656?>
     657 No newline at end of file
  • bp-xprofile/bp-xprofile-template.php

     
    109109                for ( $i = 0, $count = count( $this->group->fields ); $i < $count; ++$i ) {
    110110                        $field = &$this->group->fields[$i];
    111111
    112                         if ( !empty( $field->data ) && $field->data->value != null ) {
     112                        if ( !empty( $field->data ) && $field->data->value != null && !bp_profile_field_is_private( $field ) ) {
    113113                                $has_data = true;
     114                                break;
    114115                        }
    115116                }
    116117
     
    138139
    139140                $value = !empty( $field->data ) && !empty( $field->data->value ) ? maybe_unserialize( $field->data->value ) : false;
    140141
    141                 if ( !empty( $value ) ) {
     142                if ( !empty( $value ) && !bp_profile_field_is_private( $field ) ) {
    142143                        $this->field_has_data = true;
    143144                } else {
    144145                        $this->field_has_data = false;
     
    697698                return apply_filters( 'bp_get_profile_field_data', xprofile_get_field_data( $field, $user_id ) );
    698699        }
    699700
     701function bp_profile_field_is_private( $field = '', $user_id = null, $other_user_id = null ) {
     702
     703        // Don't hide fields from super admins, or a user's own fields
     704        if ( is_super_admin() && bp_is_my_profile() )
     705                return false;
     706
     707        // Make every effort to get field data
     708        if ( empty( $field ) ) {
     709                global $field;
     710
     711                // Check one last time, but bail if we have nothing
     712                if ( empty( $field ) )
     713                        return false;
     714        }
     715
     716        // Retrieve the field_id
     717        if ( is_numeric( $field ) )
     718                $field_id = (int) $field;
     719        elseif ( !empty( $field->id ) ) {
     720                $field_id = (int) $field->id;
     721        } else {
     722                $field_id = (int) xprofile_get_field_id_from_name( $field );
     723        }
     724
     725        // Does not compute
     726        if ( empty( $field_id ) )
     727                return false;
     728
     729        // Make sure we have a user_id
     730        if ( null === $user_id )
     731                $user_id = bp_displayed_user_id();
     732
     733        // Does not compute
     734        if ( empty( $user_id ) )
     735                return false;
     736
     737        // Make sure we have a user_id to check in case of a friends check
     738        if ( null === $other_user_id )
     739                $other_user_id = (int) bp_loggedin_user_id();
     740
     741        // Get the user's profile field privacy setting
     742        $privacy = (array) bp_xprofile_get_meta( $field_id, 'field', 'bp_profile_privacy_' . $user_id );
     743
     744        // If they've not setting, use the default
     745        if ( empty( $privacy ) )
     746                $privacy = (array) bp_xprofile_get_meta( $field_id, 'field', 'bp_profile_privacy_default' );
     747
     748        // Fallback for cases where there's no user setting or admin declared default
     749        if ( empty( $privacy ) )
     750                $privacy = array( 'public' );
     751
     752        // Default to private
     753        $retval = true;
     754
     755        // Logged in users only
     756        if ( in_array( 'logged_in_users', $privacy ) ) {
     757
     758                if ( bp_loggedin_user_id() )
     759                        $retval = false;
     760
     761        // Friends
     762        } elseif ( in_array( 'friends', $privacy ) ) {
     763
     764                if ( !$friendship_status = wp_cache_get( 'bp_friendship_status_' . $user_id . '_to_' . $other_user_id, 'bp' ) ) {
     765                        $friendship_status = BP_Friends_Friendship::check_is_friend( $user_id, $other_user_id );
     766                        wp_cache_set( 'bp_friendship_status_' . $user_id . '_to_' . $other_user_id, $friendship_status, 'bp' );
     767                }
     768
     769                if ( 'is_friends' == $friendship_status )
     770                        $retval = false;
     771
     772        // Members of a user's groups
     773        } elseif ( in_array( 'groups', $privacy ) ) {
     774
     775                if ( !$user_group_ids = wp_cache_get( 'bp_group_ids_' . $user_id, 'bp' ) ) {
     776                        $user_group_ids = BP_Groups_Member::get_group_ids( $user_id );
     777                        wp_cache_set( 'bp_group_ids_' . $user_id, $user_group_ids, 'bp' );
     778                }
     779
     780                if ( !$other_user_group_ids = wp_cache_get( 'bp_group_ids_' . $other_user_id, 'bp' ) ) {
     781                        $other_user_group_ids = BP_Groups_Member::get_group_ids( $other_user_id );
     782                        wp_cache_set( 'bp_group_ids_' . $other_user_id, $other_user_group_ids, 'bp' );
     783                }
     784
     785                $mutual_groups = array_intersect( $user_group_ids['groups'], $other_user_group_ids['groups'] );
     786
     787                if ( !empty( $mutual_groups ) )
     788                        $retval = false;
     789
     790        // Anyone can view it
     791        } elseif ( in_array( 'public', $privacy ) ) {
     792                $retval = false;
     793        }
     794
     795        return apply_filters( 'bp_profile_field_is_private', $retval, $field_id, $user_id, $other_user_id, $privacy );
     796}
     797
    700798function bp_profile_group_tabs() {
    701799        global $bp, $group_name;
    702800
  • bp-xprofile/bp-xprofile-screens.php

     
    102102                                        $errors = true;
    103103                                else
    104104                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
     105
     106                                // Now let's do some privacy
     107                                if ( empty( $_POST['bp_xprofile_field_privacy_options_' . $field_id] ) )
     108                                        $privacy = array( 'public' );
     109                                else
     110                                        $privacy = $_POST['bp_xprofile_field_privacy_options_' . $field_id];
     111
     112                                if ( !bp_xprofile_update_field_meta( $field_id, 'bp_profile_privacy_' . bp_displayed_user_id(), $privacy ) )
     113                                        $serrors = true;
     114                                else
     115                                        do_action( 'xprofile_profile_field_privacy_updated', $field_id, $privacy );
     116
    105117                        }
    106118
    107119                        do_action( 'xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors );