Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/11/2012 02:14:07 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in XProfile component. See #3989.

File:
1 edited

Legend:

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

    r5697 r5699  
    11<?php
     2
     3/**
     4 * BuddyPress XProfile Classes
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileClasses
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    … …  
    1119        var $fields;
    1220
    13         function bp_xprofile_group( $id = null ) {
    14                 $this->__construct( $id );
    15         }
    16 
    1721        function __construct( $id = null ) {
    18                 global $bp, $wpdb;
    19 
    20                 if ( $id )
     22                if ( !empty( $id ) )
    2123                        $this->populate( $id );
    22 
    2324        }
    2425
    … …  
    4647                do_action_ref_array( 'xprofile_group_before_save', array( $this ) );
    4748
    48                 if ( $this->id )
     49                if ( !empty( $this->id ) )
    4950                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
    5051                else
    … …  
    5657                do_action_ref_array( 'xprofile_group_after_save', array( $this ) );
    5758
    58                 if ( $this->id )
     59                if ( !empty( $this->id ) )
    5960                        return $this->id;
    6061                else
    … …  
    6566                global $wpdb, $bp;
    6667
    67                 if ( !$this->can_delete )
    68                         return false;
    69 
    70                 /* Delete field group */
     68                if ( empty( $this->can_delete ) )
     69                        return false;
     70
     71                // Delete field group
    7172                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) {
    7273                        return false;
    7374                } else {
    74                         /* Remove the group's fields. */
     75
     76                        // Remove the group's fields.
    7577                        if ( BP_XProfile_Field::delete_for_group( $this->id ) ) {
    76                                 /* Remove profile data for the groups fields */
     78
     79                                // Remove profile data for the groups fields
    7780                                for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) {
    7881                                        BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id );
    … …  
    8487        }
    8588
    86         /** Static Functions **/
     89        /** Static Methods ********************************************************/
    8790
    8891        /**
    … …  
    126129                $where_sql = '';
    127130
    128                 if ( $profile_group_id )
     131                if ( !empty( $profile_group_id ) )
    129132                        $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
    130133                elseif ( $exclude_groups )
    131134                        $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
    132135
    133                 if ( $hide_empty_groups )
     136                if ( !empty( $hide_empty_groups ) )
    134137                        $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 {$where_sql} ORDER BY g.group_order ASC" ) );
    135138                else
    136139                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) );
    137140
    138                 if ( !$fetch_fields )
     141                if ( empty( $fetch_fields ) )
    139142                        return $groups;
    140143
    … …  
    151154
    152155                $exclude_fields_sql = '';
    153                 if ( $exclude_fields )
     156                if ( !empty( $exclude_fields ) )
    154157                        $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" );
    155158
    … …  
    160163                        return $groups;
    161164
    162                 if ( $fetch_field_data ) {
     165                if ( !empty( $fetch_field_data ) ) {
     166
    163167                        // Fetch the field data for the user.
    164                         foreach( (array)$fields as $field )
     168                        foreach( (array) $fields as $field ) {
    165169                                $field_ids[] = $field->id;
     170                        }
    166171
    167172                        $field_ids_sql = implode( ',', (array) $field_ids );
    … …  
    171176
    172177                        // Remove data-less fields, if necessary
    173                         if ( $hide_empty_fields ) {
     178                        if ( !empty( $hide_empty_fields ) ) {
    174179
    175180                                // Loop through the results and find the fields that have data.
    176181                                foreach( (array)$field_data as $data ) {
     182
    177183                                        // Empty fields may contain a serialized empty array
    178184                                        $maybe_value = maybe_unserialize( $data->value );
    … …  
    220226
    221227                        foreach( (array) $fields as $field ) {
    222                                 if ( $group->id == $field->group_id )
     228                                if ( $group->id == $field->group_id ) {
    223229                                        $groups[$index]->fields[] = $field;
     230                                }
    224231                        }
    225232
    … …  
    265272                global $message;
    266273
    267                 if ( !$this->id ) {
     274                if ( empty( $this->id ) ) {
    268275                        $title  = __( 'Add New Field Group', 'buddypress' );
    269276                        $action = "admin.php?page=bp-profile-setup&amp;mode=add_group";
    … …  
    273280                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
    274281                        $button = __( 'Save Changes', 'buddypress' );
    275                 }
    276 ?>
     282                } ?>
     283
    277284                <div class="wrap">
    278285
    … …  
    282289                        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
    283290
    284 <?php if ( $message != '' ) :
    285                 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?>
     291                        <?php if ( !empty( $message ) ) :
     292                                        $type = ( 'error' == $type ) ? 'error' : 'updated'; ?>
     293
    286294                                <div id="message" class="<?php echo $type; ?> fade">
    287295                                        <p><?php echo $message; ?></p>
    288296                                </div>
    289 <?php endif; ?>
     297
     298                        <?php endif; ?>
     299
    290300                        <div id="poststuff">
    291301                                <form action="<?php echo esc_attr( $action ); ?>" method="post">
    … …  
    297307                                        </div>
    298308
    299 <?php if ( '0' != $this->can_delete ) : ?>
    300                                         <div id="titlediv">
    301                                                 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3>
    302                                                 <div id="titlewrap">
    303                                                         <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     309                                        <?php if ( '0' != $this->can_delete ) : ?>
     310
     311                                                <div id="titlediv">
     312                                                        <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3>
     313                                                        <div id="titlewrap">
     314                                                                <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     315                                                        </div>
    304316                                                </div>
    305                                         </div>
    306 <?php endif; ?>
     317
     318                                        <?php endif; ?>
    307319
    308320                                        <p class="submit">
    … …  
    314326                        </div>
    315327                </div>
     328
    316329<?php
    317330        }
    318331}
    319 
    320332
    321333class BP_XProfile_Field {
    … …  
    337349        var $message_type = 'err';
    338350
    339         function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {
    340                 $this->__construct( $id, $user_id, $get_data );
    341         }
    342 
    343351        function __construct( $id = null, $user_id = null, $get_data = true ) {
    344                 if ( $id )
     352                if ( !empty( $id ) )
    345353                        $this->populate( $id, $user_id, $get_data );
    346354        }
    … …  
    349357                global $wpdb, $userdata, $bp;
    350358
     359                // @todo Why are we nooping the user_id ?
    351360                $user_id = 0;
    352361                if ( is_null( $user_id ) )
    … …  
    369378                        $this->is_default_option = $field->is_default_option;
    370379
    371                         if ( $get_data && $user_id )
    372                                 $this->data            = $this->get_field_data( $user_id );
     380                        if ( $get_data && $user_id ) {
     381                                $this->data          = $this->get_field_data( $user_id );
     382                        }
    373383                }
    374384        }
    … …  
    380390                // Prevent deletion by url when can_delete is false.
    381391                // Prevent deletion of option 1 since this invalidates fields with options.
    382                 if ( !$this->id || !$this->can_delete || ( $this->parent_id && $this->option_order == 1 ) )
     392                if ( empty( $this->id ) || empty( $this->can_delete ) || ( $this->parent_id && $this->option_order == 1 ) )
    383393                        return false;
    384394
    … …  
    396406                global $wpdb, $bp;
    397407
    398                 $error = false;
    399 
    400408                $this->group_id    = apply_filters( 'xprofile_field_group_id_before_save',    $this->group_id,    $this->id );
    401409                $this->parent_id   = apply_filters( 'xprofile_field_parent_id_before_save',   $this->parent_id,   $this->id );
    402                 $this->type        = apply_filters( 'xprofile_field_type_before_save',        $this->type,        $this->id );
    403                 $this->name        = apply_filters( 'xprofile_field_name_before_save',        $this->name,        $this->id );
     410                $this->type            = apply_filters( 'xprofile_field_type_before_save',        $this->type,        $this->id );
     411                $this->name            = apply_filters( 'xprofile_field_name_before_save',        $this->name,        $this->id );
    404412                $this->description = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id );
    405413                $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id );
    … …  
    409417                do_action_ref_array( 'xprofile_field_before_save', array( $this ) );
    410418
    411                 if ( $this->id != null )
     419                if ( $this->id != null ) {
    412420                        $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 );
    413                 else
     421                } else {
    414422                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
    415 
    416                 /*
     423                }
     424
     425                /**
    417426                 * Check for null so field options can be changed without changing any other part of the field.
    418427                 * The described situation will return 0 here.
    419428                 */
    420429                if ( $wpdb->query( $sql ) !== null ) {
    421                         if ( $this->id )
     430
     431                        if ( !empty( $this->id ) ) {
    422432                                $field_id = $this->id;
    423                         else
     433                        } else {
    424434                                $field_id = $wpdb->insert_id;
    425 
    426                         /* Only do this if we are editing an existing field */
     435                        }
     436
     437                        // Only do this if we are editing an existing field
    427438                        if ( $this->id != null ) {
    428                                 /*
     439
     440                                /**
    429441                                 * Remove any radio or dropdown options for this
    430442                                 * field. They will be re-added if needed.
    … …  
    435447                        }
    436448
    437                         /*
     449                        /**
    438450                         * Check to see if this is a field with child options.
    439451                         * We need to add the options to the db, if it is.
    440452                         */
    441453                        if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) {
    442                                 if ( $this->id )
     454
     455                                if ( !empty( $this->id ) ) {
    443456                                        $parent_id = $this->id;
    444                                 else
     457                                } else {
    445458                                        $parent_id = $wpdb->insert_id;
     459                                }
    446460
    447461                                if ( 'radio' == $this->type ) {
    … …  
    452466                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'radio' );
    453467
    454                                 } else if ( 'selectbox' == $this->type ) {
     468                                } elseif ( 'selectbox' == $this->type ) {
    455469                                        $post_option  = !empty( $_POST['selectbox_option']           ) ? $_POST['selectbox_option']           : '';
    456470                                        $post_default = !empty( $_POST['isDefault_selectbox_option'] ) ? $_POST['isDefault_selectbox_option'] : '';
    … …  
    459473                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'selectbox' );
    460474
    461                                 } else if ( 'multiselectbox' == $this->type ) {
     475                                } elseif ( 'multiselectbox' == $this->type ) {
    462476                                        $post_option  = !empty( $_POST['multiselectbox_option']           ) ? $_POST['multiselectbox_option']           : '';
    463477                                        $post_default = !empty( $_POST['isDefault_multiselectbox_option'] ) ? $_POST['isDefault_multiselectbox_option'] : '';
    … …  
    466480                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'multiselectbox' );
    467481
    468                                 } else if ( 'checkbox' == $this->type ) {
     482                                } elseif ( 'checkbox' == $this->type ) {
    469483                                        $post_option  = !empty( $_POST['checkbox_option']           ) ? $_POST['checkbox_option']           : '';
    470484                                        $post_default = !empty( $_POST['isDefault_checkbox_option'] ) ? $_POST['isDefault_checkbox_option'] : '';
    … …  
    475489
    476490                                $counter = 1;
    477                                 if ( $options ) {
     491                                if ( !empty( $options ) ) {
    478492                                        foreach ( (array)$options as $option_key => $option_value ) {
    479493                                                $is_default = 0;
    … …  
    488502
    489503                                                if ( '' != $option_value ) {
    490                                                         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 ) ) )
     504                                                        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 ) ) ) {
    491505                                                                return false;
     506                                                        }
    492507                                                }
    493508
    … …  
    513528
    514529                // This is done here so we don't have problems with sql injection
    515                 if ( 'asc' == $this->order_by && !$for_editing )
     530                if ( 'asc' == $this->order_by && empty( $for_editing ) ) {
    516531                        $sort_sql = 'ORDER BY name ASC';
    517                 else if ( 'desc' == $this->order_by && !$for_editing )
     532                } elseif ( 'desc' == $this->order_by && empty( $for_editing ) ) {
    518533                        $sort_sql = 'ORDER BY name DESC';
    519                 else
     534                } else {
    520535                        $sort_sql = 'ORDER BY option_order ASC';
     536                }
    521537
    522538                // This eliminates a problem with getting all fields when there is no id for the object
    523                 if ( !$this->id )
     539                if ( empty( $this->id ) ) {
    524540                        $parent_id = -1;
    525                 else
     541                } else {
    526542                        $parent_id = $this->id;
     543                }
    527544
    528545                $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 );
    … …  
    547564                global $wpdb, $bp;
    548565
    549                 if ( $field_id ) {
     566                if ( !empty( $field_id ) ) {
    550567                        $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
    551568
    552                         if ( !$field_type = $wpdb->get_var( $sql ) )
     569                        if ( !$field_type = $wpdb->get_var( $sql ) ) {
    553570                                return false;
     571                        }
    554572
    555573                        return $field_type;
    … …  
    562580                global $wpdb, $bp;
    563581
    564                 if ( $group_id ) {
     582                if ( !empty( $group_id ) ) {
    565583                        $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
    566584
    567                         if ( $wpdb->get_var( $sql ) === false )
     585                        if ( $wpdb->get_var( $sql ) === false ) {
    568586                                return false;
     587                        }
    569588
    570589                        return true;
    … …  
    589608                        return false;
    590609
    591                 /* Update $field_id with new $position and $field_group_id */
     610                // Update $field_id with new $position and $field_group_id
    592611                if ( $parent = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id ) ) ) {;
    593                         /* Update any children of this $field_id */
     612
     613                        // Update any children of this $field_id
    594614                        $children = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id ) );
    595615
    … …  
    608628                $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );
    609629
    610                 foreach ($input_types as $type) {
     630                foreach ( $input_types as $type ) {
    611631                        $default_name = '';
    612632
    613                         if ( 'multiselectbox' == $type || 'checkbox' == $type )
     633                        if ( ( 'multiselectbox' == $type ) || ( 'checkbox' == $type ) ) {
    614634                                $default_input = 'checkbox';
    615                         else
     635                        } else {
    616636                                $default_input = 'radio';
    617 ?>
    618                         <div id="<?php echo $type; ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;">
     637                        }
     638
     639                        if ( $this->type != $type ) {
     640                                $class = 'display: none;';
     641                        }
     642
     643                        ?>
     644
     645                        <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;">
    619646                                <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4>
    620647                                <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    … …  
    624651                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option>
    625652                                        </select>
    626 <?php
    627                                 if ( !$options = $this->get_children( true ) ) {
     653
     654                                <?php if ( !$options = $this->get_children( true ) ) {
     655
    628656                                        $i = 1;
    629657                                        while ( isset( $_POST[$type . '_option'][$i] ) ) {
    630658                                                (array) $options[] = (object) array(
    631                                                         'id' => -1,
    632                                                         'name' => $_POST[$type . '_option'][$i],
    633                                                         'is_default_option' => ( 'multiselectbox' != $type &&
    634                                                                 'checkbox' != $type &&
    635                                                                 $_POST["isDefault_{$type}_option"] == $i ) ?
    636                                                                         1 :
    637                                                                         $_POST["isDefault_{$type}_option"][$i]
     659                                                        'id'                => -1,
     660                                                        'name'              => $_POST[$type . '_option'][$i],
     661                                                        'is_default_option' => ( ( 'multiselectbox' != $type ) && ( 'checkbox' != $type ) && ( $_POST["isDefault_{$type}_option"] == $i ) ) ? 1 : $_POST["isDefault_{$type}_option"][$i]
    638662                                                );
    639663
    … …  
    647671
    648672                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    649                                                         $default_name = '[' . $j . ']';
    650 ?>
    651                                                 <p><?php _e('Option', 'buddypress'); ?> <?php echo $j; ?>:
     673                                                        $default_name = '[' . $j . ']'; ?>
     674
     675                                                <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>:
    652676                                                   <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" />
    653677                                                   <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' ); ?>
    654 <?php
    655                                         if ( $j != 1 && $options[$i]->id != -1 ) : ?>
    656                                                         <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>
    657 <?php                           endif; ?>
     678
     679                                                        <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?>
     680
     681                                                                <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>
     682
     683                                                        <?php endif; ?>
     684
    658685                                                </p>
    659 <?php                           } /* end for */ ?>
     686
     687                                        <?php } /* end for */ ?>
    660688
    661689                                        <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="<?php echo $j + 1; ?>" />
    662 <?php
    663                                 } else {
     690
     691                                <?php } else {
     692
    664693                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    665                                                 $default_name = '[1]';
    666 ?>
     694                                                $default_name = '[1]'; ?>
    667695
    668696                                        <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" />
    … …  
    670698                                        <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" />
    671699
    672 <?php                   } /* end if */ ?>
     700                                <?php } /* end if */ ?>
    673701
    674702                                <div id="<?php echo $type; ?>_more"></div>
    … …  
    680708
    681709        function render_admin_form( $message = '' ) {
    682                 if ( !$this->id ) {
     710                if ( empty( $this->id ) ) {
    683711                        $title                          = __( 'Add Field', 'buddypress' );
    684712                        $action                         = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
    685713
    686714                        if ( !empty( $_POST['saveField'] ) ) {
    687                                 $this->name             = $_POST['title'];
    688                                 $this->description      = $_POST['description'];
    689                                 $this->is_required      = $_POST['required'];
    690                                 $this->type             = $_POST['fieldtype'];
    691                                 $this->order_by         = $_POST["sort_order_{$this->type}"];
    692                                 $this->field_order      = $_POST['field_order'];
    693                         }
    694                 } else {
    695                         $title                          = __( 'Edit Field', 'buddypress' );
    696                         $action                         = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
    697                 }
    698 ?>
    699         <div class="wrap">
    700                 <div id="icon-users" class="icon32"><br /></div>
    701                 <h2><?php echo $title; ?></h2>
    702                 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
    703 
    704 <?php
    705                 if ( $message != '' ) {
    706 ?>
    707                         <div id="message" class="error fade">
    708                                 <p><?php echo $message; ?></p>
    709                         </div>
    710 <?php   } ?>
    711 
    712                 <form action="<?php echo $action; ?>" method="post">
    713                         <div id="poststuff">
    714                                 <div id="titlediv">
    715                                         <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3>
    716                                         <div id="titlewrap">
    717                                                 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" />
     715                                $this->name        = $_POST['title'];
     716                                $this->description = $_POST['description'];
     717                                $this->is_required = $_POST['required'];
     718                                $this->type        = $_POST['fieldtype'];
     719                                $this->order_by    = $_POST["sort_order_{$this->type}"];
     720                                $this->field_order = $_POST['field_order'];
     721                        }
     722                } else {
     723                        $title  = __( 'Edit Field', 'buddypress' );
     724                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
     725                } ?>
     726
     727                <div class="wrap">
     728                        <div id="icon-users" class="icon32"><br /></div>
     729                        <h2><?php echo $title; ?></h2>
     730                        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
     731
     732                        <?php if ( !empty( $message ) ) : ?>
     733
     734                                <div id="message" class="error fade">
     735                                        <p><?php echo $message; ?></p>
     736                                </div>
     737
     738                        <?php endif; ?>
     739
     740                        <form action="<?php echo $action; ?>" method="post">
     741                                <div id="poststuff">
     742                                        <div id="titlediv">
     743                                                <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3>
     744                                                <div id="titlewrap">
     745                                                        <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" />
     746                                                </div>
    718747                                        </div>
     748
     749                                        <div id="titlediv">
     750                                                <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
     751                                                <div id="titlewrap">
     752                                                        <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     753                                                </div>
     754                                        </div>
     755
     756                                        <?php if ( '0' != $this->can_delete ) { ?>
     757
     758                                                <div id="titlediv">
     759                                                        <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3>
     760                                                        <select name="required" id="required" style="width: 30%">
     761                                                                <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
     762                                                                <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option>
     763                                                        </select>
     764                                                </div>
     765
     766                                                <div id="titlediv">
     767                                                        <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3>
     768                                                        <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%">
     769                                                                <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option>
     770                                                                <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
     771                                                                <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option>
     772                                                                <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option>
     773                                                                <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
     774                                                                <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option>
     775                                                                <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option>
     776                                                        </select>
     777                                                </div>
     778
     779                                                <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?>
     780
     781                                                <?php $this->render_admin_form_children(); ?>
     782
     783                                        <?php } else { ?>
     784
     785                                                <input type="hidden" name="required" id="required" value="1" />
     786                                                <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
     787
     788                                        <?php } ?>
     789
     790                                        <p class="submit">
     791                                                <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" />
     792                                                <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" />
     793                                                <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     794                                        </p>
     795
    719796                                </div>
    720797
    721                                 <div id="titlediv">
    722                                         <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
    723                                         <div id="titlewrap">
    724                                                 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
    725                                         </div>
    726                                 </div>
    727 
    728 <?php
    729                 if ( '0' != $this->can_delete ) {
    730 ?>
    731                                 <div id="titlediv">
    732                                         <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3>
    733                                         <select name="required" id="required" style="width: 30%">
    734                                                 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
    735                                                 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option>
    736                                         </select>
    737                                 </div>
    738 
    739                                 <div id="titlediv">
    740                                         <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3>
    741                                         <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%">
    742                                                 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option>
    743                                                 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
    744                                                 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option>
    745                                                 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option>
    746                                                 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
    747                                                 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option>
    748                                                 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option>
    749                                         </select>
    750                                 </div>
    751 
    752                                 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?>
    753 
    754                                 <?php $this->render_admin_form_children(); ?>
    755 <?php   } else { ?>
    756                                 <input type="hidden" name="required" id="required" value="1" />
    757                                 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
    758 <?php   } ?>
    759                                 <p class="submit">
    760                                         <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" />
    761                                         <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" />
    762                                         <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    763                                 </p>
    764 
    765                         </div>
    766 
    767                         <?php wp_nonce_field( 'xprofile_delete_option' ); ?>
    768 
    769                 </form>
    770         </div>
     798                                <?php wp_nonce_field( 'xprofile_delete_option' ); ?>
     799
     800                        </form>
     801                </div>
    771802
    772803<?php
    … …  
    776807                global $message;
    777808
    778                 /* Validate Form */
     809                // Validate Form
    779810                if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) {
    780811                        $message = __( 'Please make sure you fill out all required fields.', 'buddypress' );
    … …  
    806837        var $last_updated;
    807838
    808         function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {
    809                 $this->__construct( $field_id, $user_id );
    810         }
    811 
    812839        function __construct( $field_id = null, $user_id = null ) {
    813                 if ( $field_id )
     840                if ( !empty( $field_id ) )
    814841                        $this->populate( $field_id, $user_id );
    815842        }
    … …  
    923950                $profile_data = array();
    924951
    925                 if ( $results ) {
     952                if ( !empty( $results ) ) {
    926953                        $profile_data['user_login']             = $results[0]->user_login;
    927954                        $profile_data['user_nicename']  = $results[0]->user_nicename;
    … …  
    945972                global $wpdb, $bp;
    946973
    947                 if ( !$user_ids )
     974                if ( empty( $user_ids ) )
    948975                        $user_ids = bp_displayed_user_id();
    949976
    … …  
    961988                global $bp, $wpdb;
    962989
    963                 if ( !$fields )
    964                         return false;
    965 
    966                 if ( !$user_id )
     990                if ( empty( $fields ) )
     991                        return false;
     992
     993                if ( empty( $user_id ) )
    967994                        $user_id = bp_displayed_user_id();
    968995
    … …  
    10061033
    10071034        function delete_for_field( $field_id ) {
    1008                 global $wpdb, $userdata, $bp;
     1035                global $wpdb, $bp;
    10091036
    10101037                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) )
    … …  
    10311058                global $wpdb, $bp;
    10321059
    1033                 if ( $exclude_fullname )
     1060                if ( !empty( $exclude_fullname ) )
    10341061                        $exclude_sql = $wpdb->prepare( " AND pf.id != 1" );
    10351062
    … …  
    10381065
    10391066        function get_fullname( $user_id = 0 ) {
    1040                 global $bp;
    1041 
    1042                 if ( !$user_id )
     1067
     1068                if ( empty( $user_id ) )
    10431069                        $user_id = bp_displayed_user_id();
    10441070
Note: See TracChangeset for help on using the changeset viewer.