Changeset 1021 for trunk/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 02/06/2009 03:07:48 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-xprofile/bp-xprofile-classes.php (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-classes.php
r850 r1021 29 29 global $wpdb, $bp; 30 30 31 $sql = $wpdb->prepare("SELECT * FROM " . $bp['profile']['table_name_groups'] . "WHERE id = %d", $id);31 $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id); 32 32 33 33 if ( $group = $wpdb->get_row($sql) ) { … … 47 47 48 48 if ( $this->id != null ) { 49 $sql = $wpdb->prepare("UPDATE " . $bp['profile']['table_name_groups'] . "SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id);50 } else { 51 $sql = $wpdb->prepare("INSERT INTO " . $bp['profile']['table_name_groups'] . "(name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description);49 $sql = $wpdb->prepare("UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id); 50 } else { 51 $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description); 52 52 } 53 53 … … 64 64 return false; 65 65 66 $sql = $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_groups'] . " WHERE id = %d", $this->id);66 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ); 67 67 68 68 if ( $wpdb->query($sql) === false) { … … 85 85 86 86 // Get field ids for the current group. 87 $sql = $wpdb->prepare("SELECT id, type FROM " . $bp['profile']['table_name_fields'] . "WHERE group_id = %d AND parent_id = 0 ORDER BY id", $this->id);87 $sql = $wpdb->prepare("SELECT id, type FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND parent_id = 0 ORDER BY id", $this->id); 88 88 89 89 if(!$fields = $wpdb->get_results($sql)) … … 143 143 144 144 if ( $hide_empty ) { 145 $sql = $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 ORDER BY g.id ASC");146 } else { 147 $sql = $wpdb->prepare( "SELECT * FROM " . $bp['profile']['table_name_groups'] . " ORDER BY id ASC");145 $sql = $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 ORDER BY g.id ASC" ); 146 } else { 147 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} ORDER BY id ASC" ); 148 148 } 149 149 … … 163 163 164 164 // Validate Form 165 if ( $_POST['group_name'] == '') {165 if ( empty( $_POST['group_name'] ) ) { 166 166 $message = __('Please make sure you give the group a name.', 'buddypress'); 167 167 return false; … … 204 204 } 205 205 206 $sql = $wpdb->prepare( "SELECT * FROM " . $bp['profile']['table_name_fields'] . " WHERE id = %d", $id);206 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ); 207 207 208 208 if ( $field = $wpdb->get_row($sql) ) { … … 233 233 return false; 234 234 235 $sql = $wpdb->prepare("DELETE FROM " . $bp['profile']['table_name_fields'] . " WHERE id = %d OR parent_id = %d", $this->id, $this->id);235 $sql = $wpdb->prepare("DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ); 236 236 237 237 if ( $wpdb->query($sql) === false ) … … 248 248 249 249 if ( $this->id != null ) { 250 $sql = $wpdb->prepare("UPDATE " . $bp['profile']['table_name_fields'] . "SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, is_public = %d, order_by = %s WHERE id = %d", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->is_public, $this->order_by, $this->id);251 } else { 252 $sql = $wpdb->prepare("INSERT INTO " . $bp['profile']['table_name_fields'] . "(group_id, parent_id, type, name, description, is_required, is_public, order_by) VALUES (%d, 0, %s, %s, %s, %d, %d, %s)", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->is_public, $this->order_by);250 $sql = $wpdb->prepare("UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, is_public = %d, order_by = %s WHERE id = %d", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->is_public, $this->order_by, $this->id); 251 } else { 252 $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, is_public, order_by) VALUES (%d, 0, %s, %s, %s, %d, %d, %s)", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->is_public, $this->order_by); 253 253 } 254 254 if ( $wpdb->query($sql) !== false ) { … … 298 298 299 299 if ( $num > 0 ) { 300 $sql = $wpdb->prepare( "INSERT INTO " . $bp['profile']['table_name_fields'] . "(group_id, parent_id, type, name, description, is_required, option_order) VALUES (%d, %d, 'option', %s, %s, 0, %d)", $this->group_id, $parent_id, $name, $description, $option_order);300 $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order) VALUES (%d, %d, 'option', %s, %s, 0, %d)", $this->group_id, $parent_id, $name, $description, $option_order); 301 301 $wpdb->query($sql); 302 302 } … … 334 334 if ( $option_value != "" ) { 335 335 // don't insert an empty option. 336 $sql = $wpdb->prepare("INSERT INTO " . $bp['profile']['table_name_fields'] . "(group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default);336 $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default); 337 337 338 338 if ( $wpdb->query($sql) === false ) { … … 464 464 465 465 if ( !$this->is_required ) { 466 $html .= '<a class="clear-value" style="text-decoration: none;" href="javascript:clear(\'field_' . $this->id . '\');"><img src="' . $bp ['profile']['image_base']. '/cross.gif" alt="Clear" /> Clear</a>';466 $html .= '<a class="clear-value" style="text-decoration: none;" href="javascript:clear(\'field_' . $this->id . '\');"><img src="' . $bp->profile->image_base . '/cross.gif" alt="Clear" /> Clear</a>'; 467 467 } 468 468 … … 596 596 } 597 597 598 $sql = $wpdb->prepare( "SELECT * FROM " . $bp['profile']['table_name_fields'] . "WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );598 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id ); 599 599 600 600 if ( !$children = $wpdb->get_results($sql) ) … … 607 607 global $wpdb, $bp; 608 608 609 $sql = $wpdb->prepare("DELETE FROM " . $bp['profile']['table_name_fields'] . "WHERE parent_id = %d", $this->id);609 $sql = $wpdb->prepare("DELETE FROM {$bp->profile->table_name_fields} WHERE parent_id = %d", $this->id); 610 610 611 611 $wpdb->query($sql); … … 738 738 <p class="submit"> 739 739 <input type="submit" value="<?php _e("Save", 'buddypress') ?> »" name="saveField" id="saveField" style="font-weight: bold" /> 740 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=xprofile_settings" style="color: red"><?php _e( 'Cancel', 'buddypress') ?></a>740 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=xprofile_settings" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a> 741 741 </p> 742 742 … … 751 751 <div class="clear"> </div><br /> 752 752 753 <h2> Add Prebuilt Field</h2>753 <h2><?php _e( 'Add Prebuilt Field', 'buddypress' ) ?></h2> 754 754 <?php $this->render_prebuilt_fields(); ?> 755 755 … … 894 894 global $wpdb, $bp; 895 895 896 $sql = $wpdb->prepare( "SELECT f.id FROM " . $bp['profile']['table_name_fields'] . " AS f, " . $bp['profile']['table_name_groups'] . "AS g WHERE g.name = %s AND f.parent_id = 0 AND g.id = f.group_id ORDER BY f.id", get_site_option('bp-xprofile-base-group-name') );896 $sql = $wpdb->prepare( "SELECT f.id FROM {$bp->profile->table_name_fields} AS f, {$bp->profile->table_name_groups} AS g WHERE g.name = %s AND f.parent_id = 0 AND g.id = f.group_id ORDER BY f.id", get_site_option('bp-xprofile-base-group-name') ); 897 897 898 898 if ( !$temp_fields = $wpdb->get_results($sql) ) … … 910 910 911 911 // Validate Form 912 if ( $_POST['title'] == '' || $_POST['required'] == '' || $_POST['fieldtype'] == '') {912 if ( empty( $_POST['title'] ) || empty( $_POST['required'] ) || empty( $_POST['fieldtype'] ) ) { 913 913 $message = __('Please make sure you fill out all required fields.', 'buddypress'); 914 914 return false; … … 934 934 935 935 if ( $field_id ) { 936 $sql = $wpdb->prepare( "SELECT type FROM " . $bp['profile']['table_name_fields'] . " WHERE id = %d", $field_id);936 $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ); 937 937 938 938 if ( !$field_type = $wpdb->get_var($sql) ) … … 949 949 950 950 if ( $group_id ) { 951 $sql = $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_fields'] . " WHERE group_id = %d", $group_id);951 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ); 952 952 953 953 if ( $wpdb->get_var($sql) === false ) { … … 982 982 $user_id = $userdata->ID; 983 983 984 $sql = $wpdb->prepare( "SELECT * FROM " . $bp['profile']['table_name_data'] . " WHERE field_id = %d AND user_id = %d", $field_id, $user_id);984 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ); 985 985 986 986 if ( $profiledata = $wpdb->get_row($sql) ) { … … 997 997 998 998 // check to see if there is data already for the user. 999 $sql = $wpdb->prepare( "SELECT id FROM " . $bp['profile']['table_name_data'] . " WHERE user_id = %d AND field_id = %d", $userdata->ID, $this->field_id);999 $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $userdata->ID, $this->field_id ); 1000 1000 1001 1001 if ( !$wpdb->get_row($sql) ) … … 1009 1009 1010 1010 // check to see if this data is actually for a valid field. 1011 $sql = $wpdb->prepare("SELECT id FROM " . $bp['profile']['table_name_fields'] . " WHERE id = %d", $this->field_id);1011 $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ); 1012 1012 1013 1013 if ( !$wpdb->get_row($sql) ) … … 1024 1024 if ( $this->is_valid_field() ) { 1025 1025 if ( $this->exists() && $this->value != '' ) { 1026 $sql = $wpdb->prepare( "UPDATE " . $bp['profile']['table_name_data'] . " SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id);1027 } else if ( $this->exists() and $this->value == '') {1026 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_data} SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id ); 1027 } else if ( $this->exists() && empty( $this->value ) ) { 1028 1028 // Data removed, delete the entry. 1029 1029 $this->delete(); 1030 1030 } else { 1031 $sql = $wpdb->prepare("INSERT INTO " . $bp['profile']['table_name_data'] . " (user_id, field_id, value, last_updated) VALUES (%d, %d, %s, %s)", $this->user_id, $this->field_id, $this->value, $this->last_updated);1031 $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_data} (user_id, field_id, value, last_updated) VALUES (%d, %d, %s, %s)", $this->user_id, $this->field_id, $this->value, $this->last_updated ); 1032 1032 } 1033 1033 … … 1047 1047 global $wpdb, $bp; 1048 1048 1049 $sql = $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_data'] . " WHERE field_id = %d AND user_id = %d", $this->field_id, $this->user_id);1049 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $this->field_id, $this->user_id ); 1050 1050 1051 1051 if ( $wpdb->query($sql) === false ) … … 1061 1061 1062 1062 if ( !$user_id ) 1063 $user_id = $bp ['current_userid'];1064 1065 $sql = $wpdb->prepare("SELECT * FROM " . $bp['profile']['table_name_data'] . "WHERE field_id = %d AND user_id = %d", $field_id, $user_id );1063 $user_id = $bp->displayed_user->id; 1064 1065 $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ); 1066 1066 1067 1067 if ( $profile_data = $wpdb->get_row($sql) ) { … … 1079 1079 1080 1080 if ( !$user_id ) 1081 $user_id = $bp ['current_userid'];1082 1083 if ( !$bp ['profile'])1081 $user_id = $bp->displayed_user->id; 1082 1083 if ( !$bp->profile ) 1084 1084 xprofile_setup_globals(); 1085 1085 … … 1099 1099 } 1100 1100 1101 $sql = $wpdb->prepare( "SELECT d.value, f.name FROM " . $bp['profile']['table_name_data'] . " d, " . $bp['profile']['table_name_fields'] . "f WHERE d.field_id = f.id AND d.user_id = %d AND f.parent_id = 0 $field_sql", $user_id );1101 $sql = $wpdb->prepare( "SELECT d.value, f.name FROM {$bp->profile->table_name_data} d, {$bp->profile->table_name_fields} f WHERE d.field_id = f.id AND d.user_id = %d AND f.parent_id = 0 $field_sql", $user_id ); 1102 1102 1103 1103 if ( !$values = $wpdb->get_results($sql) ) … … 1126 1126 global $wpdb, $userdata, $bp; 1127 1127 1128 $sql = $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_data'] . " WHERE field_id = %d", $field_id);1128 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ); 1129 1129 1130 1130 if ( $wpdb->query($sql) === false ) … … 1137 1137 global $wpdb, $bp; 1138 1138 1139 $last_updated = $wpdb->get_var( $wpdb->prepare( "SELECT last_updated FROM " . $bp['profile']['table_name_data'] . "WHERE user_id = %d ORDER BY last_updated LIMIT 1", $user_id ) );1139 $last_updated = $wpdb->get_var( $wpdb->prepare( "SELECT last_updated FROM {$bp->profile->table_name_data} WHERE user_id = %d ORDER BY last_updated LIMIT 1", $user_id ) ); 1140 1140 1141 1141 return $last_updated; … … 1145 1145 global $wpdb, $bp; 1146 1146 1147 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['profile']['table_name_data'] . "WHERE user_id = %d", $user_id ) );1147 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); 1148 1148 } 1149 1149 … … 1154 1154 $exclude_sql = $wpdb->prepare( " AND pf.id != 1" ); 1155 1155 1156 return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM " . $bp['profile']['table_name_data'] . " pd INNER JOIN " . $bp['profile']['table_name_fields'] . "pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) );1156 return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM {$bp->profile->table_name_data} pd INNER JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) ); 1157 1157 } 1158 1158 … … 1161 1161 1162 1162 if ( !$user_id ) 1163 $user_id = $bp ['current_userid'];1163 $user_id = $bp->displayed_user->id; 1164 1164 1165 1165 $data = bp_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
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)