Changeset 6070
- Timestamp:
- 06/09/2012 02:40:37 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
bp-themes/bp-default/members/single/profile/edit.php (modified) (2 diffs)
-
bp-xprofile/bp-xprofile-classes.php (modified) (10 diffs)
-
bp-xprofile/bp-xprofile-functions.php (modified) (10 diffs)
-
bp-xprofile/bp-xprofile-screens.php (modified) (1 diff)
-
bp-xprofile/bp-xprofile-template.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-themes/bp-default/members/single/profile/edit.php
r6051 r6070 113 113 114 114 <?php endif; ?> 115 115 116 116 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 117 117 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 118 118 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a> 119 119 </p> 120 120 121 121 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 122 122 <fieldset> 123 123 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 124 124 125 125 <?php bp_profile_visibility_radio_buttons() ?> 126 126 127 127 </fieldset> 128 128 <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> … … 131 131 <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 132 132 <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> 133 </div> 133 </div> 134 134 <?php endif ?> 135 135 -
trunk/bp-xprofile/bp-xprofile-classes.php
r5961 r6070 154 154 if ( empty( $group_ids ) ) 155 155 return $groups; 156 156 157 157 // Support arrays and comma-separated strings 158 158 $exclude_fields_cs = wp_parse_id_list( $exclude_fields ); 159 159 160 160 // Visibility - Handled here so as not to be overridden by sloppy use of the 161 161 // exclude_fields parameter. See bp_xprofile_get_hidden_fields_for_user() 162 162 $exclude_fields_cs = array_merge( $exclude_fields_cs, bp_xprofile_get_hidden_fields_for_user( $user_id ) ); 163 163 164 164 $exclude_fields_cs = implode( ',', $exclude_fields_cs ); 165 165 166 166 if ( !empty( $exclude_fields_cs ) ) { 167 $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields_cs})" ); 167 $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields_cs})" ); 168 168 } else { 169 169 $exclude_fields_sql = ''; … … 231 231 } 232 232 } 233 233 234 234 if ( $fetch_visibility_level ) { 235 235 $fields = self::fetch_visibility_level( $user_id, $fields ); … … 283 283 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) ); 284 284 } 285 285 286 286 /** 287 287 * Fetch the field visibility level for the fields returned by the query … … 295 295 function fetch_visibility_level( $user_id, $fields ) { 296 296 global $wpdb, $bp; 297 297 298 298 // Get the user's visibility level preferences 299 299 $visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); 300 300 301 301 // Get the admin-set preferences 302 302 $admin_set_levels = self::fetch_default_visibility_levels(); 303 303 304 304 foreach( (array)$fields as $key => $field ) { 305 305 // Does the admin allow this field to be customized? 306 306 $allow_custom = !empty( $admin_set_levels[$field->id]['allow_custom'] ) && 'disabled' != $admin_set_levels[$field->id]['allow_custom']; 307 307 308 308 // Look to see if the user has set the visibility for this field 309 309 if ( $allow_custom && isset( $visibility_levels[$field->id] ) ) { 310 310 $field_visibility = $visibility_levels[$field->id]; 311 } else { 311 } else { 312 312 // If no admin-set default is saved, fall back on a global default 313 313 $field_visibility = !empty( $admin_set_levels[$field->id]['default'] ) ? $admin_set_levels[$field->id]['default'] : apply_filters( 'bp_xprofile_default_visibility_level', 'public' ); 314 314 } 315 315 316 316 $fields[$key]->visibility_level = $field_visibility; 317 317 } 318 318 319 319 return $fields; 320 320 } 321 321 322 322 /** 323 323 * Fetch the admin-set preferences for all fields … … 330 330 function fetch_default_visibility_levels() { 331 331 global $wpdb, $bp; 332 332 333 333 $levels = $wpdb->get_results( $wpdb->prepare( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" ) ); 334 334 335 335 // Arrange so that the field id is the key and the visibility level the value 336 336 $default_visibility_levels = array(); 337 337 foreach( $levels as $level ) { 338 338 if ( 'default_visibility' == $level->meta_key ) { 339 $default_visibility_levels[$level->object_id]['default'] = $level->meta_value; 339 $default_visibility_levels[$level->object_id]['default'] = $level->meta_value; 340 340 } else if ( 'allow_custom_visibility' == $level->meta_key ) { 341 $default_visibility_levels[$level->object_id]['allow_custom'] = $level->meta_value; 342 } 343 } 344 341 $default_visibility_levels[$level->object_id]['allow_custom'] = $level->meta_value; 342 } 343 } 344 345 345 return $default_visibility_levels; 346 346 } 347 347 348 348 /* ADMIN AREA HTML. 349 349 * TODO: Get this out of here and replace with standard loops … … 464 464 $this->data = $this->get_field_data( $user_id ); 465 465 } 466 466 467 467 $this->default_visibility = bp_xprofile_get_meta( $id, 'field', 'default_visibility' ); 468 468 469 469 if ( empty( $this->default_visibility ) ) { 470 470 $this->default_visibility = 'public'; 471 471 } 472 472 473 473 $this->allow_custom_visibility = 'disabled' == bp_xprofile_get_meta( $id, 'field', 'allow_custom_visibility' ) ? 'disabled' : 'allowed'; 474 474 } … … 728 728 } 729 729 730 if ( $this->type != $type ) { 730 if ( $this->type != $type ) { 731 731 $class = 'display: none;'; 732 732 } 733 733 734 734 if ( empty( $this->default_visibility ) ) { 735 735 $this->default_visibility = 'public'; … … 887 887 888 888 <div id="titlediv"> 889 889 890 890 <div id="titlewrap"> 891 891 <h3><label for="default-visibility"><?php _e( "Default Visibility", 'buddypress' ); ?></label></h3> 892 892 <ul> 893 893 <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?> 894 <li><input type="radio" name="default-visibility" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_visibility, $level['id'] ) ?>> <?php echo esc_html( $level['label'] ) ?></li> 894 <li><input type="radio" name="default-visibility" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_visibility, $level['id'] ) ?>> <?php echo esc_html( $level['label'] ) ?></li> 895 895 <?php endforeach ?> 896 896 </ul> 897 897 </div> 898 898 899 899 <div id="titlewrap"> 900 900 <h3><label for="allow-custom-visibility"><?php _e( "Per-Member Visibility", 'buddypress' ); ?></label></h3> 901 901 <ul> 902 902 <li><input type="radio" name="allow-custom-visibility" value="allowed" <?php checked( $this->allow_custom_visibility, 'allowed' ) ?>> <?php _e( "Let members change the this field's visibility", 'buddypress' ) ?></li> 903 903 904 904 <li><input type="radio" name="allow-custom-visibility" value="disabled" <?php checked( $this->allow_custom_visibility, 'disabled' ) ?>> <?php _e( 'Enforce the default visibility for all members', 'buddypress' ) ?></li> 905 905 </ul> 906 906 </div> 907 907 </div> 908 908 909 909 <?php endif ?> 910 910 … … 1089 1089 return $profile_data; 1090 1090 } 1091 1091 1092 1092 /** 1093 1093 * Get the user's field data id by the id of the xprofile field … … 1099 1099 function get_fielddataid_byid( $field_id, $user_id ) { 1100 1100 global $wpdb, $bp; 1101 1101 1102 1102 if ( empty( $field_id ) || empty( $user_id ) ) { 1103 1103 $fielddata_id = 0; 1104 1104 } else { 1105 $fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) ); 1106 } 1107 1105 $fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) ); 1106 } 1107 1108 1108 return $fielddata_id; 1109 1109 } -
trunk/bp-xprofile/bp-xprofile-functions.php
r6060 r6070 152 152 * @param mixed $field The ID of the field, or the $name of the field. 153 153 * @param int $user_id The ID of the user 154 * @param string $multi_format How should array data be returned? 'comma' if you want a 154 * @param string $multi_format How should array data be returned? 'comma' if you want a 155 155 * comma-separated string; 'array' if you want an array 156 156 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed. … … 180 180 $data[] = apply_filters( 'xprofile_get_field_data', $value, $field_id, $user_id ); 181 181 } 182 182 183 183 if ( 'comma' == $multi_format ) { 184 184 $data = implode( ', ', $data ); … … 269 269 return false; 270 270 } 271 271 272 272 // Check against a whitelist 273 273 $allowed_values = bp_xprofile_get_visibility_levels(); … … 275 275 return false; 276 276 } 277 277 278 278 // Stored in an array in usermeta 279 279 $current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); 280 280 281 281 if ( !$current_visibility_levels ) { 282 282 $current_visibility_levels = array(); 283 283 } 284 284 285 285 $current_visibility_levels[$field_id] = $visibility_level; 286 286 287 287 return bp_update_user_meta( $user_id, 'bp_xprofile_visibility_levels', $current_visibility_levels ); 288 288 } … … 637 637 function bp_xprofile_get_visibility_levels() { 638 638 global $bp; 639 639 640 640 return apply_filters( 'bp_xprofile_get_visibility_levels', $bp->profile->visibility_levels ); 641 641 } … … 662 662 $displayed_user_id = bp_displayed_user_id(); 663 663 } 664 664 665 665 if ( !$displayed_user_id ) { 666 666 return array(); 667 667 } 668 668 669 669 if ( !$current_user_id ) { 670 670 $current_user_id = bp_loggedin_user_id(); 671 671 } 672 672 673 673 // @todo - This is where you'd swap out for current_user_can() checks 674 674 675 675 if ( $current_user_id ) { 676 676 // Current user is logged in 677 677 if ( $displayed_user_id == $current_user_id ) { 678 678 // If you're viewing your own profile, nothing's private 679 $hidden_fields = array(); 680 679 $hidden_fields = array(); 680 681 681 } else if ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) { 682 682 // If the current user and displayed user are friends, show all 683 683 $hidden_fields = array(); 684 684 685 685 } else { 686 // current user is logged-in but not friends, so exclude friends-only 687 $hidden_levels = array( 'friends' ); 686 // current user is logged-in but not friends, so exclude friends-only 687 $hidden_levels = array( 'friends' ); 688 688 $hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels ); 689 689 } 690 690 691 691 } else { 692 692 // Current user is not logged in, so exclude friends-only and loggedin … … 694 694 $hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels ); 695 695 } 696 696 697 697 return apply_filters( 'bp_xprofile_get_hidden_fields_for_user', $hidden_fields, $displayed_user_id, $current_user_id ); 698 698 } … … 713 713 $levels = (array)$levels; 714 714 } 715 715 716 716 $user_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); 717 717 … … 734 734 } 735 735 } 736 736 737 737 // Never allow the fullname field to be excluded 738 738 if ( in_array( 1, $field_ids ) ) { … … 740 740 unset( $field_ids[$key] ); 741 741 } 742 742 743 743 return $field_ids; 744 744 } -
trunk/bp-xprofile/bp-xprofile-screens.php
r5792 r6070 114 114 else 115 115 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 116 116 117 117 // Save the visibility level 118 118 $visibility_level = !empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public'; -
trunk/bp-xprofile/bp-xprofile-template.php
r6069 r6070 158 158 // or this is a registration page 159 159 $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() ); 160 160 161 161 // We only need to fetch visibility levels when viewing your own profile 162 162 if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) { … … 165 165 $fetch_visibility_level_default = false; 166 166 } 167 167 168 168 $defaults = array( 169 169 'user_id' => bp_displayed_user_id(), … … 425 425 $defaults = array( 426 426 'type' => false, 427 'null_on_required' => false 427 'null_on_required' => false 428 428 ); 429 429 … … 730 730 function bp_get_the_profile_field_visibility_level() { 731 731 global $field; 732 732 733 733 $retval = !empty( $field->visibility_level ) ? $field->visibility_level : 'public'; 734 734 735 735 return apply_filters( 'bp_get_the_profile_field_visibility_level', $retval ); 736 736 } … … 747 747 function bp_get_the_profile_field_visibility_level_label() { 748 748 global $field; 749 749 750 750 $level = !empty( $field->visibility_level ) ? $field->visibility_level : 'public'; 751 751 $fields = bp_xprofile_get_visibility_levels(); 752 752 753 753 return apply_filters( 'bp_get_the_profile_field_visibility_level_label', $fields[$level]['label'] ); 754 754 } … … 906 906 * Return the field visibility radio buttons 907 907 */ 908 function bp_profile_get_visibility_radio_buttons() { 908 function bp_profile_get_visibility_radio_buttons() { 909 909 $html = '<ul class="radio">'; 910 910 911 911 foreach( bp_xprofile_get_visibility_levels() as $level ) { 912 912 $checked = $level['id'] == bp_get_the_profile_field_visibility_level() ? ' checked="checked" ' : ''; 913 913 914 914 $html .= '<li><label for="see-field_' . esc_attr( $level['id'] ) . '"><input type="radio" id="see-field_' . esc_attr( $level['id'] ) . '" name="field_' . bp_get_the_profile_field_id() . '_visibility" value="' . esc_attr( $level['id'] ) . '"' . $checked . ' /> ' . esc_html( $level['label'] ) . '</label></li>'; 915 915 } 916 916 917 917 $html .= '</ul>'; 918 918 919 919 return apply_filters( 'bp_profile_get_visibility_radio_buttons', $html ); 920 920 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)