Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 06:56:42 PM (17 years ago)
Author:
apeatling
Message:

Merging last few trunk changes and stripping all whitespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1/bp-xprofile/bp-xprofile-classes.php

    r2075 r2076  
    77        var $can_delete;
    88        var $fields;
    9        
     9
    1010        function bp_xprofile_group( $id = null ) {
    1111                global $bp, $wpdb;
    … …  
    1515                }
    1616        }
    17        
     17
    1818        function populate( $id ) {
    1919                global $wpdb, $bp;
    20                
     20
    2121                $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id);
    2222
    … …  
    2626                        $this->description = $group->description;
    2727                        $this->can_delete = $group->can_delete;
    28                        
     28
    2929                        // get the fields for this group.
    3030                        $this->fields = $this->get_fields();
    … …  
    3535        function save() {
    3636                global $wpdb, $bp;
    37                
     37
    3838                $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id );
    3939                $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id );
    … …  
    4444                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
    4545                } else {
    46                         $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description );           
    47                 }
    48                
     46                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description );
     47                }
     48
    4949                if ( !$wpdb->query($sql) )
    5050                        return false;
    5151
    5252                do_action( 'xprofile_group_after_save', $this );
    53                
     53
    5454                return true;
    5555        }
    56        
     56
    5757        function delete() {
    5858                global $wpdb, $bp;
    59                
     59
    6060                if ( !$this->can_delete )
    6161                        return false;
    62                
     62
    6363                $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id );
    6464
    … …  
    6969                        if ( BP_XProfile_Field::delete_for_group($this->id) ) {
    7070                                // Now delete all the profile data for the groups fields
    71                                 for ( $i = 0; $i < count($this->fields); $i++ ) {       
     71                                for ( $i = 0; $i < count($this->fields); $i++ ) {
    7272                                        BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
    7373                                }
    7474                        }
    75                        
     75
    7676                        return true;
    7777                }
    7878        }
    79        
     79
    8080        function get_fields() {
    8181                global $wpdb, $bp;
    82                
     82
    8383                /* Find the max value for field_order, if it is zero, order by field_id instead -- provides backwards compat ordering */
    8484                if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT MAX(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $this->id ) ) )
    … …  
    9090                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 ) ) )
    9191                        return false;
    92                
     92
    9393                return $fields;
    9494        }
    95        
     95
    9696        /** Static Functions **/
    97        
     97
    9898        function get_all( $hide_empty = false ) {
    9999                global $wpdb, $bp;
    … …  
    107107                if ( !$groups_temp = $wpdb->get_results($sql) )
    108108                        return false;
    109                        
     109
    110110                for ( $i = 0; $i < count($groups_temp); $i++ ) {
    111111                        $group = new BP_XProfile_Group($groups_temp[$i]->id);
    … …  
    115115                return $groups;
    116116        }
    117        
     117
    118118        function admin_validate() {
    119119                global $message;
    120                
     120
    121121                // Validate Form
    122122                if ( empty( $_POST['group_name'] ) ) {
    … …  
    127127                }
    128128        }
    129        
     129
    130130        // ADMIN AREA HTML. TODO: Get this out of here.
    131131
    … …  
    138138                } else {
    139139                        $title = __('Edit Field Group', 'buddypress');
    140                         $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;                     
     140                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
    141141                }
    142142        ?>
    143143                <div class="wrap">
    144                
     144
    145145                        <h2><?php echo $title; ?></h2>
    146146                        <br />
    147                        
     147
    148148                        <?php
    149149                                if ( $message != '' ) {
    … …  
    154154                                </div>
    155155                        <?php } ?>
    156                        
     156
    157157                        <form action="<?php echo attribute_escape( $action ); ?>" method="post">
    158                                
     158
    159159                                <div id="titlediv">
    160160                                        <label for="group_name"><?php _e( "Field Group Name", 'buddypress') ?></label>
    … …  
    163163                                        </div>
    164164                                </div>
    165                                
     165
    166166                                <p class="submit" style="text-align: left">
    167167                                        <input type="submit" name="saveGroup" value="<?php echo attribute_escape( $title ); ?> &raquo;" />
    168168                                </p>
    169                        
     169
    170170                        </form>
    171171                </div>
    172                
     172
    173173                <?php
    174174        }
    … …  
    189189        var $order_by;
    190190        var $is_default_option;
    191        
     191
    192192        var $data;
    193193        var $message = null;
    … …  
    199199                }
    200200        }
    201        
     201
    202202        function populate( $id, $user_id, $get_data ) {
    203203                global $wpdb, $userdata, $bp;
    204                
     204
    205205                if ( is_null($user_id) ) {
    206206                        $user_id = $userdata->ID;
    207207                }
    208                
     208
    209209                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id );
    210        
     210
    211211                if ( $field = $wpdb->get_row($sql) ) {
    212212                        $this->id = $field->id;
    … …  
    231231        function delete() {
    232232                global $wpdb, $bp;
    233                
     233
    234234                if ( !$this->id ||
    235235                        // Prevent deletion by url when can_delete is false.
    … …  
    241241                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
    242242                        return false;
    243                
     243
    244244                // delete the data in the DB for this field
    245245                BP_XProfile_ProfileData::delete_for_field($this->id);
    246                
     246
    247247                return true;
    248248        }
    249        
     249
    250250        function save() {
    251251                global $wpdb, $bp;
    252                
     252
    253253                $error = false;
    254                
     254
    255255                $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id );
    256256                $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id );
    … …  
    263263
    264264                do_action( 'xprofile_field_before_save', $this );
    265                
     265
    266266                if ( $this->id != null )
    267267                        $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, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id);
    … …  
    272272                // The described situation will return 0 here.
    273273                if ( $wpdb->query($sql) !== null ) {
    274                        
     274
    275275                        // Only do this if we are editing an existing field
    276276                        if ( $this->id != null ) {
    … …  
    278278                                // field. They will be re-added if needed.
    279279                                // This stops orphan options if the user changes a
    280                                 // field from a radio button field to a text box. 
     280                                // field from a radio button field to a text box.
    281281                                $this->delete_children();
    282282                        }
    283                        
     283
    284284                        // Check to see if this is a field with child options.
    285285                        // We need to add the options to the db, if it is.
    … …  
    288288                                        $parent_id = $this->id;
    289289                                } else {
    290                                         $parent_id = $wpdb->insert_id; 
     290                                        $parent_id = $wpdb->insert_id;
    291291                                }
    292                                
     292
    293293                                if ( 'radio' == $this->type ) {
    294                                        
     294
    295295                                        $options = $_POST['radio_option'];
    296296                                        $defaults = $_POST['isDefault_radio_option'];
    297                                        
     297
    298298                                } else if ( 'selectbox' == $this->type ) {
    299                                        
     299
    300300                                        $options = $_POST['selectbox_option'];
    301301                                        $defaults = $_POST['isDefault_selectbox_option'];
    302                                        
     302
    303303                                } else if ( 'multiselectbox' == $this->type ) {
    304                                        
     304
    305305                                        $options = $_POST['multiselectbox_option'];
    306306                                        $defaults = $_POST['isDefault_multiselectbox_option'];
    307                                        
     307
    308308                                } else if ( 'checkbox' == $this->type ) {
    309                                        
     309
    310310                                        $options = $_POST['checkbox_option'];
    311311                                        $defaults = $_POST['isDefault_checkbox_option'];
    312                                        
     312
    313313                                }
    314                                
     314
    315315                                $counter = 1;
    316316                                if ( $options ) {
    … …  
    326326                                                }
    327327
    328                                                 if ( '' != $option_value ) { 
     328                                                if ( '' != $option_value ) {
    329329                                                        if ( !$wpdb->query( $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 ) ) )
    330330                                                                return false;
    331331                                                }
    332                                        
     332
    333333                                                $counter++;
    334                                         }                                       
     334                                        }
    335335                                }
    336336                        }
    … …  
    338338                        $error = true;
    339339                }
    340                
     340
    341341                if ( !$error ) {
    342342                        do_action( 'xprofile_field_after_save', $this );
    … …  
    346346                }
    347347        }
    348                
     348
    349349        function get_field_data($user_id) {
    350350                return new BP_XProfile_ProfileData($this->id, $user_id);
    351351        }
    352        
     352
    353353         function get_children($for_editing = false) {
    354354                global $wpdb, $bp;
    355                
     355
    356356                // This is done here so we don't have problems with sql injection
    357357                if ( 'asc' == $this->order_by && !$for_editing ) {
    … …  
    362362                        $sort_sql = 'ORDER BY option_order ASC';
    363363                }
    364                
     364
    365365                //This eliminates a problem with getting all fields when there is no id for the object
    366366                if ( !$this->id ) {
    … …  
    369369                        $parent_id = $this->id;
    370370                }
    371                
     371
    372372                $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 );
    373373
    374374                if ( !$children = $wpdb->get_results($sql) )
    375375                        return false;
    376                        
     376
    377377                return $children;
    378         } 
    379        
     378        }
     379
    380380        function delete_children() {
    381381                global $wpdb, $bp;
    … …  
    385385                $wpdb->query($sql);
    386386        }
    387        
     387
    388388        // Static Functions
    389                
     389
    390390        function get_type( $field_id ) {
    391391                global $wpdb, $bp;
    … …  
    396396                        if ( !$field_type = $wpdb->get_var($sql) )
    397397                                return false;
    398                
     398
    399399                        return $field_type;
    400400                }
    401                
     401
    402402                return false;
    403403        }
    404        
     404
    405405        function delete_for_group( $group_id ) {
    406406                global $wpdb, $bp;
    … …  
    412412                                return false;
    413413                        }
    414                        
     414
    415415                        return true;
    416416                }
    417                
     417
    418418                return false;
    419419        }
    420        
     420
    421421        function get_id_from_name( $field_name ) {
    422422                global $wpdb, $bp;
    423                
     423
    424424                if ( !$bp->profile->table_name_fields || !$field_name )
    425425                        return false;
    426                
     426
    427427                return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
    428428        }
    429        
     429
    430430        function update_position( $field_id, $position ) {
    431431                global $wpdb, $bp;
    432                
     432
    433433                if ( !is_numeric( $position ) )
    434434                        return false;
    435                
     435
    436436                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d WHERE id = %d", $position, $field_id ) );
    437437        }
    438        
     438
    439439        // ADMIN AREA HTML. TODO: Get this out of here.
    440        
     440
    441441        function render_admin_form_children() {
    442442                //This function populates the items for radio buttons checkboxes and drop down boxes
    443                 $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );     
    444                
    445                 foreach ($input_types as $type) { 
     443                $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );
     444
     445                foreach ($input_types as $type) {
    446446                        $default_name = '';
    447                        
     447
    448448                        if ( 'multiselectbox' == $type || 'checkbox' == $type ) {
    449449                                $default_input = 'checkbox';
    … …  
    455455                                <h4><?php _e('Please enter options for this Field:', 'buddypress') ?></h4>
    456456                                <p><?php _e( 'Order By:', 'buddypress' ) ?>
    457                                        
     457
    458458                                        <select name="sort_order_<?php echo $type ?>" id="sort_order_<?php echo $type ?>" >
    459459                                                <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ) ?></option>
    … …  
    461461                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ) ?></option>
    462462                                        </select>
    463        
     463
    464464                                <?php
    465465                                if ( !$options = $this->get_children(true) ) {
    … …  
    481481
    482482                                if ( !empty($options) ) {
    483                                         for ( $i = 0; $i < count($options); $i++ ) { 
     483                                        for ( $i = 0; $i < count($options); $i++ ) {
    484484                                                $j = $i + 1;
    485                                                
     485
    486486                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    487487                                                        $default_name = '[' . $j . ']';
    488488                                        ?>
    489                                                 <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>: 
     489                                                <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
    490490                                                   <input type="text" name="<?php echo $type ?>_option[<?php echo $j ?>]" id="<?php echo $type ?>_option<?php echo $j ?>" value="<?php echo attribute_escape( $options[$i]->name ) ?>" />
    491                                                    <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j ?>" /> <?php _e( 'Default Value', 'buddypress' ) ?> 
     491                                                   <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j ?>" /> <?php _e( 'Default Value', 'buddypress' ) ?>
    492492                                                        <?php if ( $j != 1 &&
    493493                                                                $options[$i]->id != -1 ) : ?><a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id ?>">[x]</a><?php endif ?></p>
    … …  
    495495                                        <?php } // end for ?>
    496496                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" />
    497                                
    498                                 <?php 
    499                                 } else { 
     497
     498                                <?php
     499                                } else {
    500500                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    501501                                                $default_name = '[1]';
    502502                                ?>
    503                                        
     503
    504504                                        <p><?php _e('Option', 'buddypress') ?> 1: <input type="text" name="<?php echo $type ?>_option[1]" id="<?php echo $type ?>_option1" />
    505505                                        <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?>
    506506                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
    507                                
     507
    508508                                <?php } // end if ?>
    509                                 <div id="<?php echo $type ?>_more"></div>                                       
     509                                <div id="<?php echo $type ?>_more"></div>
    510510                                <p><a href="javascript:add_option('<?php echo $type ?>')"><?php _e('Add Another Option', 'buddypress') ?></a></p>
    511511                        </div>
    512512
    513                 <?php } 
    514         }
    515                
     513                <?php }
     514        }
     515
    516516        function render_admin_form( $message = '' ) {
    517517                if ( !$this->id ) {
    … …  
    526526                } else {
    527527                        $title = __('Edit Field', 'buddypress');
    528                         $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;                 
     528                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
    529529                }
    530530        ?>
    531        
     531
    532532        <div class="wrap">
    533                
     533
    534534                <h2><?php echo $title; ?></h2>
    535535                <br />
    536                
     536
    537537                <?php
    538538                        if ( $message != '' ) {
    … …  
    542542                        </div>
    543543                <?php } ?>
    544                
     544
    545545                <form action="<?php echo $action ?>" method="post">
    546                         <div id="poststuff">           
     546                        <div id="poststuff">
    547547                                <div id="titlediv">
    548548                                        <h3><label for="title"><?php _e("Field Title", 'buddypress') ?> *</label></h3>
    … …  
    551551                                        </div>
    552552                                </div>
    553                        
     553
    554554                                <div id="titlediv" class="inside">
    555555                                        <h3><label for="description"><?php _e("Field Description", 'buddypress') ?></label></h3>
    … …  
    558558                                        </div>
    559559                                </div>
    560        
     560
    561561                                <div id="titlediv">
    562562                                        <h3><label for="required"><?php _e("Is This Field Required?", 'buddypress') ?> *</label></h3>
    … …  
    580580                                </div>
    581581
    582                                 <?php $this->render_admin_form_children() ?>                           
    583        
     582                                <?php $this->render_admin_form_children() ?>
     583
    584584                                <p class="submit">
    585585                                                &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &raquo;" name="saveField" id="saveField" style="font-weight: bold" />
    586586                                                 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a>
    587587                                </p>
    588                        
     588
    589589                        <div class="clear"></div>
    590                        
     590
    591591                        <?php if ( function_exists('wp_nonce_field') )
    592592                                wp_nonce_field('xprofile_delete_option');
    593593                        ?>
    594                        
    595                 </form> 
     594
     595                </form>
    596596        </div>
    597        
     597
    598598        <?php
    599599        }
    600        
     600
    601601        function admin_validate() {
    602602                global $message;
    603                
     603
    604604                // Validate Form
    605605                if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) {
    … …  
    607607                        return false;
    608608                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'radio' && empty($_POST['radio_option'][1]) ) {
    609                         $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress'); 
     609                        $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress');
    610610                        return false;
    611611                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'selectbox' && empty($_POST['selectbox_option'][1]) ) {
    612                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');   
    613                         return false;   
     612                        $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     613                        return false;
    614614                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'multiselectbox' && empty($_POST['multiselectbox_option'][1]) ) {
    615                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');   
    616                         return false;   
     615                        $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     616                        return false;
    617617                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'checkbox' && empty($_POST['checkbox_option'][1]) ) {
    618                         $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress');     
    619                         return false;           
     618                        $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress');
     619                        return false;
    620620                } else {
    621621                        return true;
    … …  
    640640        function populate( $field_id, $user_id )  {
    641641                global $wpdb, $bp;
    642                
     642
    643643                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
    644                
     644
    645645                if ( $profiledata = $wpdb->get_row($sql) ) {
    646                        
     646
    647647                        $this->id = $profiledata->id;
    648648                        $this->user_id = $profiledata->user_id;
    … …  
    652652                }
    653653        }
    654        
     654
    655655        function exists() {
    656656                global $wpdb, $bp;
    657                
     657
    658658                // check to see if there is data already for the user.
    659659                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id );
    660660
    661                 if ( !$wpdb->get_row($sql) ) 
    662                         return false;
    663 
    664                 return true;           
    665         }
    666                
     661                if ( !$wpdb->get_row($sql) )
     662                        return false;
     663
     664                return true;
     665        }
     666
    667667        function is_valid_field() {
    668668                global $wpdb, $bp;
    669                
     669
    670670                // check to see if this data is actually for a valid field.
    671671                $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
    672672
    673                 if ( !$wpdb->get_row($sql) ) 
    674                         return false;
    675                
     673                if ( !$wpdb->get_row($sql) )
     674                        return false;
     675
    676676                return true;
    677677        }
    … …  
    684684                $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id );
    685685                $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id );
    686                
     686
    687687                do_action( 'xprofile_data_before_save', $this );
    688688
    … …  
    698698
    699699                        if ( !$result )
    700                                 return false; 
     700                                return false;
    701701
    702702                        do_action( 'xprofile_data_after_save', $this );
    703                        
     703
    704704                        return true;
    705705                }
    706                
     706
    707707                return false;
    708708        }
    … …  
    710710        function delete() {
    711711                global $wpdb, $bp;
    712                
     712
    713713                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $this->field_id, $this->user_id ) ) )
    714714                        return false;
    715                
     715
    716716                return true;
    717717        }
    718        
     718
    719719        /** Static Functions **/
    720        
     720
    721721        function get_value_byid( $field_id, $user_id = null ) {
    722722                global $wpdb, $bp;
    … …  
    724724                if ( !$user_id )
    725725                        $user_id = $bp->displayed_user->id;
    726                        
     726
    727727                if ( !$bp->profile )
    728728                        xprofile_setup_globals();
    … …  
    736736                }
    737737        }
    738        
     738
    739739        function get_value_byfieldname( $fields, $user_id = null ) {
    740740                global $bp, $wpdb;
    … …  
    745745                if ( !$user_id )
    746746                        $user_id = $bp->displayed_user->id;
    747                
     747
    748748                if ( !$bp->profile )
    749749                        xprofile_setup_globals();
    750                
     750
    751751                $field_sql = '';
    752752
    … …  
    755755                                if ( $i == 0 )
    756756                                        $field_sql .= $wpdb->prepare( "AND ( f.name = %s ", $fields[$i] );
    757                                 else 
     757                                else
    758758                                        $field_sql .= $wpdb->prepare( "OR f.name = %s ", $fields[$i] );
    759759                        }
    760                        
     760
    761761                        $field_sql .= ')';
    762762                } else {
    … …  
    768768                if ( !$values = $wpdb->get_results($sql) )
    769769                        return false;
    770                
     770
    771771                $new_values = array();
    772                
     772
    773773                if ( is_array($fields) ) {
    774774                        for ( $i = 0; $i < count($values); $i++ ) {
    … …  
    784784                        $new_values = $values[0]->value;
    785785                }
    786                
     786
    787787                return $new_values;
    788788        }
    789        
     789
    790790        function delete_for_field( $field_id ) {
    791791                global $wpdb, $userdata, $bp;
    … …  
    793793                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) )
    794794                        return false;
    795                
     795
    796796                return true;
    797797        }
    798        
     798
    799799        function get_last_updated( $user_id ) {
    800800                global $wpdb, $bp;
    801                
     801
    802802                $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 ) );
    803                
     803
    804804                return $last_updated;
    805805        }
    806        
     806
    807807        function delete_data_for_user( $user_id ) {
    808808                global $wpdb, $bp;
    809                
    810                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );   
    811         }
    812        
     809
     810                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );
     811        }
     812
    813813        function get_random( $user_id, $exclude_fullname ) {
    814814                global $wpdb, $bp;
    815                
     815
    816816                if ( $exclude_fullname )
    817817                        $exclude_sql = $wpdb->prepare( " AND pf.id != 1" );
    818                                
    819                 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 ) );                 
    820         }
    821        
     818
     819                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 ) );
     820        }
     821
    822822        function get_fullname( $user_id = false ) {
    823823                global $bp;
    … …  
    828828                $data = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
    829829
    830                 return $data[BP_XPROFILE_FULLNAME_FIELD_NAME];         
     830                return $data[BP_XPROFILE_FULLNAME_FIELD_NAME];
    831831        }
    832832}
Note: See TracChangeset for help on using the changeset viewer.