Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/06/2009 03:07:48 AM (17 years ago)
Author:
apeatling
Message:

Converted $bp as an array to $bp as an object. See this post for more info: http://buddypress.org/forums/topic.php?id=1125

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r850 r1021  
    2929                global $wpdb, $bp;
    3030               
    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);
    3232
    3333                if ( $group = $wpdb->get_row($sql) ) {
     
    4747
    4848                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);             
    5252                }
    5353               
     
    6464                        return false;
    6565               
    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 );
    6767
    6868                if ( $wpdb->query($sql) === false) {
     
    8585
    8686                // 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);
    8888
    8989                if(!$fields = $wpdb->get_results($sql))                 
     
    143143
    144144                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" );
    148148                }
    149149
     
    163163               
    164164                // Validate Form
    165                 if ( $_POST['group_name'] == '' ) {
     165                if ( empty( $_POST['group_name'] ) ) {
    166166                        $message = __('Please make sure you give the group a name.', 'buddypress');
    167167                        return false;
     
    204204                }
    205205               
    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 );
    207207       
    208208                if ( $field = $wpdb->get_row($sql) ) {
     
    233233                        return false;
    234234                       
    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 );
    236236
    237237                if ( $wpdb->query($sql) === false )
     
    248248               
    249249                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);
    253253                }
    254254                if ( $wpdb->query($sql) !== false ) {
     
    298298                                                               
    299299                                                        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);
    301301                                                                $wpdb->query($sql);
    302302                                                        }
     
    334334                                                        if ( $option_value != "" ) {
    335335                                                                // 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);
    337337
    338338                                                                if ( $wpdb->query($sql) === false ) {
     
    464464                               
    465465                                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>';
    467467                                }
    468468                               
     
    596596                }
    597597               
    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 );
    599599
    600600                if ( !$children = $wpdb->get_results($sql) )
     
    607607                global $wpdb, $bp;
    608608
    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);
    610610
    611611                $wpdb->query($sql);
     
    738738                                <p class="submit">
    739739                                                &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &raquo;" 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>
    741741                                </p>
    742742                       
     
    751751                <div class="clear">&nbsp;</div><br />
    752752               
    753                 <h2>Add Prebuilt Field</h2>
     753                <h2><?php _e( 'Add Prebuilt Field', 'buddypress' ) ?></h2>
    754754                <?php $this->render_prebuilt_fields(); ?>
    755755               
     
    894894                global $wpdb, $bp;
    895895               
    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') );
    897897
    898898                if ( !$temp_fields = $wpdb->get_results($sql) )
     
    910910               
    911911                // Validate Form
    912                 if ( $_POST['title'] == '' || $_POST['required'] == '' || $_POST['fieldtype'] == '' ) {
     912                if ( empty( $_POST['title'] ) || empty( $_POST['required'] ) || empty( $_POST['fieldtype'] ) ) {
    913913                        $message = __('Please make sure you fill out all required fields.', 'buddypress');
    914914                        return false;
     
    934934
    935935                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 );
    937937
    938938                        if ( !$field_type = $wpdb->get_var($sql) )
     
    949949
    950950                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 );
    952952
    953953                        if ( $wpdb->get_var($sql) === false ) {
     
    982982                        $user_id = $userdata->ID;
    983983               
    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 );
    985985
    986986                if ( $profiledata = $wpdb->get_row($sql) ) {
     
    997997               
    998998                // 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 );
    10001000
    10011001                if ( !$wpdb->get_row($sql) )
     
    10091009               
    10101010                // 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 );
    10121012
    10131013                if ( !$wpdb->get_row($sql) )
     
    10241024                if ( $this->is_valid_field() ) {
    10251025                        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 ) ) {
    10281028                                // Data removed, delete the entry.
    10291029                                $this->delete();
    10301030                        } 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 );
    10321032                        }
    10331033                                               
     
    10471047                global $wpdb, $bp;
    10481048               
    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 );
    10501050
    10511051                if ( $wpdb->query($sql) === false )
     
    10611061
    10621062                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 );
    10661066
    10671067                if ( $profile_data = $wpdb->get_row($sql) ) {
     
    10791079
    10801080                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 )
    10841084                        xprofile_setup_globals();
    10851085               
     
    10991099                }
    11001100
    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 );
    11021102
    11031103                if ( !$values = $wpdb->get_results($sql) )
     
    11261126                global $wpdb, $userdata, $bp;
    11271127
    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 );
    11291129
    11301130                if ( $wpdb->query($sql) === false )
     
    11371137                global $wpdb, $bp;
    11381138               
    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 ) );
    11401140               
    11411141                return $last_updated;
     
    11451145                global $wpdb, $bp;
    11461146               
    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 ) );   
    11481148        }
    11491149       
     
    11541154                        $exclude_sql = $wpdb->prepare( " AND pf.id != 1" );
    11551155                               
    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 ) );                 
    11571157        }
    11581158       
     
    11611161
    11621162                if ( !$user_id )
    1163                         $user_id = $bp['current_userid'];
     1163                        $user_id = $bp->displayed_user->id;
    11641164
    11651165                $data = bp_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
Note: See TracChangeset for help on using the changeset viewer.