Changeset 2320
- Timestamp:
- 01/17/2010 07:42:57 PM (15 years ago)
- Location:
- trunk/bp-xprofile
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-admin.php
r2077 r2320 14 14 $type = preg_replace( '|[^a-z]|i', '', $type ); 15 15 16 $groups = BP_XProfile_Group::get_all(); 16 $groups = BP_XProfile_Group::get( array( 17 'fetch_fields' => true 18 ) ); 17 19 18 20 if ( isset($_GET['mode']) && isset($_GET['group_id']) && 'add_field' == $_GET['mode'] ) { -
trunk/bp-xprofile/bp-xprofile-classes.php
r2277 r2320 26 26 $this->description = $group->description; 27 27 $this->can_delete = $group->can_delete; 28 29 // get the fields for this group.30 $this->fields = $this->get_fields();31 28 } 32 29 … … 78 75 } 79 76 80 function get_fields() { 81 global $wpdb, $bp; 82 83 /* Find the max value for field_order, if it is zero, order by field_id instead -- provides backwards compat ordering */ 84 if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT MAX(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $this->id ) ) ) 85 $order_sql = "ORDER BY id"; 77 /** Static Functions **/ 78 79 function get( $args = '' ) { 80 global $wpdb, $bp; 81 82 $defaults = array( 83 'profile_group_id' => false, 84 'user_id' => $bp->displayed_user->id, 85 'hide_empty_groups' => false, 86 'fetch_fields' => false, 87 'fetch_field_data' => false 88 ); 89 90 $r = wp_parse_args( $args, $defaults ); 91 extract( $r, EXTR_SKIP ); 92 93 if ( $profile_group_id ) 94 $group_id_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id ); 95 96 if ( $hide_empty_groups ) 97 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.id ASC" ) ); 86 98 else 87 $order_sql = "ORDER BY field_order"; 88 89 // Get field ids for the current group. 90 if ( !$fields = $wpdb->get_results( $wpdb->prepare("SELECT id, type FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND parent_id = 0 {$order_sql}", $this->id ) ) ) 91 return false; 92 93 return $fields; 94 } 95 96 /** Static Functions **/ 97 98 function get_all( $hide_empty = false ) { 99 global $wpdb, $bp; 100 101 if ( $hide_empty ) { 102 $sql = $wpdb->prepare( "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id ORDER BY g.id ASC" ); 103 } else { 104 $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_groups} ORDER BY id ASC" ); 105 } 106 107 if ( !$groups_temp = $wpdb->get_results($sql) ) 108 return false; 109 110 for ( $i = 0; $i < count($groups_temp); $i++ ) { 111 $group = new BP_XProfile_Group($groups_temp[$i]->id); 112 $groups[] = $group; 99 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.id ASC" ) ); 100 101 if ( !$fetch_fields ) 102 return $groups; 103 104 /* Get the group ids */ 105 foreach( (array)$groups as $group ) 106 $group_ids[] = $group->id; 107 108 $group_ids = implode( ',', (array) $group_ids ); 109 110 if ( empty( $group_ids ) ) 111 return $groups; 112 113 /* Fetch the fields */ 114 $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, type, group_id FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 ORDER BY field_order" ) ); 115 116 if ( empty( $fields ) ) 117 return $groups; 118 119 if ( $fetch_field_data ) { 120 /* Fetch the field data for the user. */ 121 foreach( (array)$fields as $field ) 122 $field_ids[] = $field->id; 123 124 $field_ids = implode( ',', (array) $field_ids ); 125 126 if ( !empty( $field_ids ) ) 127 $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 ) ); 128 129 if ( !empty( $field_data ) ) { 130 foreach( (array)$fields as $field_key => $field ) { 131 foreach( (array)$field_data as $data ) { 132 if ( $field->id == $data->field_id ) 133 $fields[$field_key]->data->value = $data->value; 134 } 135 } 136 } 137 } 138 139 /* Merge the field array back in with the group array */ 140 foreach( (array)$groups as $group_key => $group ) { 141 foreach( (array)$fields as $field ) { 142 if ( $group->id == $field->group_id ) 143 $groups[$group_key]->fields[] = $field; 144 } 113 145 } 114 146 … … 727 759 global $wpdb, $bp; 728 760 729 $results = $wpdb->get_results( $wpdb->prepare( "SELECT g. name as field_group_name, f.name as field_name, f.type as field_type, d.value as field_data, u.user_login, u.user_nicename, u.user_email FROM {$bp->profile->table_name_groups} g LEFT JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id INNER JOIN {$bp->profile->table_name_data} d ON f.id = d.field_id LEFT JOIN {$wpdb->users} u ON d.user_id = u.ID WHERE d.user_id = %d AND d.value != ''", $user_id ) );761 $results = $wpdb->get_results( $wpdb->prepare( "SELECT g.id as field_group_id, g.name as field_group_name, f.id as field_id, f.name as field_name, f.type as field_type, d.value as field_data, u.user_login, u.user_nicename, u.user_email FROM {$bp->profile->table_name_groups} g LEFT JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id INNER JOIN {$bp->profile->table_name_data} d ON f.id = d.field_id LEFT JOIN {$wpdb->users} u ON d.user_id = u.ID WHERE d.user_id = %d AND d.value != ''", $user_id ) ); 730 762 731 763 if ( $results ) { … … 735 767 736 768 foreach( (array) $results as $field ) { 737 $profile_data[$field->field_name] = array( 'field_group' => $field->field_group_name, 'field_type' => $field->field_type, 'field_data' => $field->field_data ); 769 $profile_data[$field->field_name] = array( 770 'field_group_id' => $field->field_group_id, 771 'field_group_name' => $field->field_group_name, 772 'field_id' => $field->field_id, 773 'field_type' => $field->field_type, 774 'field_data' => $field->field_data 775 ); 738 776 } 739 777 } -
trunk/bp-xprofile/bp-xprofile-filters.php
r2088 r2320 3 3 /* Apply WordPress defined filters */ 4 4 add_filter( 'bp_get_the_profile_field_value', 'wp_filter_kses', 1 ); 5 add_filter( 'bp_get_the_profile_field_name', 'wp_filter_kses', 1 ); 6 5 7 add_filter( 'bp_get_the_site_member_profile_data', 'wp_filter_kses', 1 ); 6 8 add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 ); … … 33 35 add_filter( 'bp_get_the_profile_field_edit_value', 'stripslashes' ); 34 36 add_filter( 'bp_get_the_profile_field_value', 'stripslashes' ); 37 add_filter( 'bp_get_the_profile_field_name', 'stripslashes' ); 35 38 add_filter( 'xprofile_get_field_data', 'stripslashes' ); 36 39 add_filter( 'bp_get_the_profile_field_description', 'stripslashes' ); -
trunk/bp-xprofile/bp-xprofile-templatetags.php
r2168 r2320 20 20 21 21 function bp_xprofile_data_template( $user_id, $profile_group_id ) { 22 23 if ( !$profile_group_id ) { 24 if ( !$this->groups = wp_cache_get( 'xprofile_groups', 'bp' ) ) { 25 $this->groups = BP_XProfile_Group::get_all(true); 26 wp_cache_set( 'xprofile_groups', $this->groups, 'bp' ); 27 } 28 } else { 29 if ( !$this->groups = wp_cache_get( 'xprofile_group_' . $profile_group_id, 'bp' ) ) { 30 $this->groups = new BP_XProfile_Group( $profile_group_id ); 31 wp_cache_set( 'xprofile_group_' . $profile_group_id, 'bp' ); 32 } 33 34 /* We need to put this single group into the same format as multiple group (an array) */ 35 $this->groups = array( $this->groups ); 36 } 22 $this->groups = BP_XProfile_Group::get( array( 23 'profile_group_id' => $profile_group_id, 24 'user_id' => $user_id, 25 'hide_empty_groups' => true, 26 'fetch_fields' => true, 27 'fetch_field_data' => true 28 ) ); 37 29 38 30 $this->group_count = count($this->groups); … … 51 43 52 44 $this->group = $this->groups[$this->current_group]; 53 54 if ( !$fields = wp_cache_get( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, 'bp' ) ) { 55 for ( $i = 0; $i < count($this->group->fields); $i++ ) { 56 /* Don't try and fetch any existing profile data if we are using this loop on the registration page */ 57 $get_data = ( !bp_is_register_page() ) ? true : false; 58 59 $field = new BP_XProfile_Field( $this->group->fields[$i]->id, $this->user_id, $get_data ); 60 $fields[$i] = $field; 61 } 62 63 wp_cache_set( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, $fields, 'bp' ); 64 } 65 66 $this->group->fields = apply_filters( 'xprofile_group_fields', $fields, $this->group->id ); 45 $this->group->fields = apply_filters( 'xprofile_group_fields', $this->group->fields, $this->group->id ); 67 46 $this->field_count = count( $this->group->fields ); 68 47 … … 386 365 $r = wp_parse_args( $args, $defaults ); 387 366 extract( $r, EXTR_SKIP ); 367 368 if ( !method_exists( $field, 'get_children' ) ) 369 $field = new BP_XProfile_Field( $field->id ); 388 370 389 371 $options = $field->get_children(); … … 584 566 585 567 if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) { 586 $groups = BP_XProfile_Group::get _all();568 $groups = BP_XProfile_Group::get( array( 'fetch_fields' => true ) ); 587 569 wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' ); 588 570 }
Note: See TracChangeset
for help on using the changeset viewer.