Ticket #3074: 3074.04.patch
File 3074.04.patch, 7.1 KB (added by , 14 years ago) |
---|
-
bp-themes/bp-default/members/single/profile/profile-loop.php
9 9 <?php do_action( 'bp_before_profile_field_content' ) ?> 10 10 11 11 <div class="bp-widget <?php bp_the_profile_group_slug() ?>"> 12 <?php if ( 1 != bp_get_the_profile_group_id() ) : ?>13 <h4><?php bp_the_profile_group_name() ?></h4>14 <?php endif; ?>15 12 13 <h4><?php bp_the_profile_group_name() ?></h4> 14 16 15 <table class="profile-fields"> 16 17 17 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 18 18 19 19 <?php if ( bp_field_has_data() ) : ?> … … 33 33 <?php do_action( 'bp_profile_field_item' ) ?> 34 34 35 35 <?php endwhile; ?> 36 36 37 </table> 37 38 </div> 38 39 -
bp-xprofile/bp-xprofile-classes.php
113 113 'profile_group_id' => false, 114 114 'user_id' => $bp->displayed_user->id, 115 115 'hide_empty_groups' => false, 116 'hide_empty_fields' => false, 116 117 'fetch_fields' => false, 117 118 'fetch_field_data' => false, 118 119 'exclude_groups' => false, … … 157 158 return $groups; 158 159 159 160 if ( $fetch_field_data ) { 161 160 162 // Fetch the field data for the user. 161 foreach( (array) $fields as $field )163 foreach( (array) $fields as $field ) { 162 164 $field_ids[] = $field->id; 165 } 163 166 164 $field_ids = implode( ',', (array) $field_ids ); 167 // Get field data if fields exist 168 if ( !empty( $field_ids ) ) { 165 169 166 if ( !empty( $field_ids ) ) 167 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids} ) AND user_id = %d", $user_id ) ); 170 // Remove data-less fields, if necessary 171 $exclude_empty_data = ''; 172 if ( $hide_empty_fields ) 173 $exclude_empty_data = $wpdb->prepare( "AND (value != '' AND value IS NOT NULL)" ); 174 175 $field_ids_sql = implode( ',', (array) $field_ids ); 176 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) {$exclude_empty_data} AND user_id = %d", $user_id ) ); 177 } 168 178 169 if ( !empty( $field_data ) ) { 170 foreach( (array)$fields as $field_key => $field ) { 171 foreach( (array)$field_data as $data ) { 172 if ( $field->id == $data->field_id ) 179 // Field data was found 180 if ( !empty( $field_data ) && !is_wp_error( $field_data ) ) { 181 182 // Loop through fields 183 foreach( (array) $fields as $field_key => $field ) { 184 185 // Loop through data in each field 186 foreach( (array) $field_data as $data ) { 187 188 // Assign correct data value to each field 189 if ( $field->id == $data->field_id ) { 173 190 $fields[$field_key]->data->value = $data->value; 191 } 174 192 } 175 193 } 176 194 } 177 195 } 178 196 179 197 // Merge the field array back in with the group array 180 foreach( (array) $groups as $group_key => $group ) {181 foreach( (array) $fields as $field ) {182 if ( $group->id == $field->group_id ) 198 foreach( (array) $groups as $group_key => $group ) { 199 foreach( (array) $fields as $field ) { 200 if ( $group->id == $field->group_id ) { 183 201 $groups[$group_key]->fields[] = $field; 202 } 184 203 } 204 205 if ( empty( $group->fields ) ) { 206 unset( $groups[$group_key] ); 207 } 208 209 // Reset indexes 210 $groups = array_values( $groups ); 185 211 } 186 212 187 213 return $groups; -
bp-xprofile/bp-xprofile-template.php
20 20 var $in_the_loop; 21 21 var $user_id; 22 22 23 function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {24 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );23 function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { 24 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); 25 25 } 26 26 27 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {27 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { 28 28 $this->groups = BP_XProfile_Group::get( array( 29 29 'profile_group_id' => $profile_group_id, 30 30 'user_id' => $user_id, 31 31 'hide_empty_groups' => $hide_empty_groups, 32 'hide_empty_fields' => $hide_empty_fields, 32 33 'fetch_fields' => $fetch_fields, 33 34 'fetch_field_data' => $fetch_field_data, 34 35 'exclude_groups' => $exclude_groups, … … 152 153 function bp_has_profile( $args = '' ) { 153 154 global $bp, $profile_template; 154 155 156 // Only show empty fields on the Dashboard or the user profile edit screen 157 $hide_empty_fields = ( bp_is_user_profile_edit() || is_admin() || is_network_admin() ); 158 155 159 $defaults = array( 156 'user_id' => $bp->displayed_user->id,160 'user_id' => $bp->displayed_user->id, 157 161 'profile_group_id' => false, 158 162 'hide_empty_groups' => true, 163 'hide_empty_fields' => $hide_empty_fields, 159 164 'fetch_fields' => true, 160 165 'fetch_field_data' => true, 161 166 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude … … 165 170 $r = wp_parse_args( $args, $defaults ); 166 171 extract( $r, EXTR_SKIP ); 167 172 168 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );173 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); 169 174 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); 170 175 } 171 176 … … 189 194 } 190 195 function bp_get_field_css_class( $class = false ) { 191 196 global $profile_template; 192 197 static $alt_row; 198 199 $alt_row = ( $alt_row === 1 ) ? 2 : 1; 193 200 $css_classes = array(); 194 201 195 202 if ( $class ) … … 201 208 // Set a class with the field name (sanitized) 202 209 $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 203 210 204 if ( $profile_template->current_field % 2 == 1 ) 205 $css_classes[] = 'alt'; 206 No newline at end of file 211 // Add alt row class 212 $css_classes[] = ( $alt_row === 1 ) ? '' : 'alt'; 207 213 208 214 $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) ); 209 215