Skip to:
Content

BuddyPress.org

Changeset 1907


Ignore:
Timestamp:
09/21/2009 06:02:36 PM (15 years ago)
Author:
apeatling
Message:

Fixes #1040 props junsuljin

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r1905 r1907  
    203203   
    204204    /* Add 'Profile' to the main navigation */
    205     bp_core_new_nav_item( array( 'name' => __('Profile', 'buddypress'), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) );
     205    bp_core_new_nav_item( array( 'name' => __( 'Profile', 'buddypress' ), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) );
    206206
    207207    $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/';
     
    214214    if ( $bp->current_component == $bp->profile->slug ) {
    215215        if ( bp_is_home() ) {
    216             $bp->bp_options_title = __('My Profile', 'buddypress');
     216            $bp->bp_options_title = __( 'My Profile', 'buddypress' );
    217217        } else {
    218218            $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r1905 r1907  
    220220            $field->is_required = wp_filter_kses( $_POST['required'] );
    221221            $field->type = wp_filter_kses( $_POST['fieldtype'] );
    222             $field->order_by = wp_filter_kses( $_POST["sort_order_$field->type"] );
    223             $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
    224             $field->field_order++;
     222            $field->order_by = wp_filter_kses( $_POST["sort_order_{$field->type}"] );
     223
     224            $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
     225
     226            if ( !$field->field_order ) {
     227                $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
     228                $field->field_order++;
     229            }
    225230           
    226231            if ( !$field->save() ) {
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r1905 r1907  
    232232        global $wpdb, $bp;
    233233       
    234         if ( !$this->id )
    235             return false;
    236            
     234        if ( !$this->id ||
     235            // Prevent deletion by url when can_delete is false.
     236            !$this->can_delete ||
     237            // Prevent deletion of option 1 since this invalidates fields with options.
     238            ( $this->parent_id && $this->option_order == 1 ) )
     239            return false;
     240
    237241        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
    238242            return false;
     
    265269            $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, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->order_by, $this->field_order );
    266270
    267         if ( $wpdb->query($sql) ) {
     271        // Check for null so field options can be changed without changing any other part of the field.
     272        // The described situation will return 0 here.
     273        if ( $wpdb->query($sql) !== null ) {
    268274           
    269275            // Only do this if we are editing an existing field
     
    457463   
    458464                <?php
    459                 $options = $this->get_children(true);
    460                
     465                if ( !$options = $this->get_children(true) ) {
     466                    $i = 1;
     467                    while ( isset( $_POST[$type . '_option'][$i] ) ) {
     468                        (array) $options[] = (object) array(
     469                            'id' => -1,
     470                            'name' => $_POST[$type . '_option'][$i],
     471                            'is_default_option' => ( 'multiselectbox' != $type &&
     472                                'checkbox' != $type &&
     473                                $_POST["isDefault_{$type}_option"] == $i ) ?
     474                                    1 :
     475                                    $_POST["isDefault_{$type}_option"][$i]
     476                        );
     477
     478                        $i++;
     479                    }
     480                }
     481
    461482                if ( !empty($options) ) {
    462483                    for ( $i = 0; $i < count($options); $i++ ) {
    463                         //var_dump($options[$i]);
    464484                        $j = $i + 1;
    465485                       
     
    469489                        <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
    470490                           <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 ) ?>" />
    471                            <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' ) ?>
    472                         <a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&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></p>
     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' ) ?>
     492                            <?php if ( $j != 1 &&
     493                                $options[$i]->id != -1 ) : ?><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&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>
    473494                        </p>
    474495                    <?php } // end for ?>
     
    477498                <?php
    478499                } else {
    479                     if ( 'multiselectbox' == $type || 'checkxbox' == $type )
     500                    if ( 'multiselectbox' == $type || 'checkbox' == $type )
    480501                        $default_name = '[1]';
    481502                ?>
    482503                   
    483504                    <p><?php _e('Option', 'buddypress') ?> 1: <input type="text" name="<?php echo $type ?>_option[1]" id="<?php echo $type ?>_option1" />
    484                     <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?>" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?>
     505                    <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" <?php if ( $default_input == 'radio' ) {?> checked="checked"<?php } ?>" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?>
    485506                    <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
    486507               
     
    497518            $title = __('Add Field', 'buddypress');
    498519            $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     520
     521            $this->name         = $_POST['title'];
     522            $this->desc         = $_POST['description'];
     523            $this->is_required  = $_POST['required'];
     524            $this->type         = $_POST['fieldtype'];
     525            $this->order_by     = $_POST["sort_order_{$this->type}"];
    499526        } else {
    500527            $title = __('Edit Field', 'buddypress');
    501528            $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;           
    502             $options = $this->get_children();
    503529        }
    504530    ?>
     
    529555                    <h3><label for="description"><?php _e("Field Description", 'buddypress') ?></label></h3>
    530556                    <div id="titlewrap">
    531                         <textarea name="description" id="description" rows="8" cols="60"> <?php echo htmlspecialchars( $this->desc ); ?></textarea>
     557                        <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->desc ); ?></textarea>
    532558                    </div>
    533559                </div>
Note: See TracChangeset for help on using the changeset viewer.