Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (14 years ago)
Author:
djpaul
Message:

Fixed #2676

File:
1 edited

Legend:

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

    r3232 r3300  
    2121    function bp_xprofile_data_template( $user_id, $profile_group_id ) {
    2222        $this->groups = BP_XProfile_Group::get( array(
    23             'profile_group_id'  => $profile_group_id,
    24             'user_id'           => $user_id,
    25             'hide_empty_groups' => true,
    26             'fetch_fields'      => true,
    27             'fetch_field_data'  => true
     23            'profile_group_id' => $profile_group_id,
     24            'user_id' => $user_id,
     25            'hide_empty_groups' => true,
     26            'fetch_fields' => true,
     27            'fetch_field_data' => true
    2828        ) );
    2929
    30         $this->group_count = count( $this->groups );
     30        $this->group_count = count($this->groups);
    3131        $this->user_id = $user_id;
    3232    }
     
    5151    function rewind_groups() {
    5252        $this->current_group = -1;
    53 
    54         if ( $this->group_count > 0 )
     53        if ( $this->group_count > 0 ) {
    5554            $this->group = $this->groups[0];
     55        }
    5656    }
    5757
     
    6060            return true;
    6161        } elseif ( $this->current_group + 1 == $this->group_count ) {
    62             do_action( 'xprofile_template_loop_end' );
    63             /* Do some cleaning up after the loop */
     62            do_action('xprofile_template_loop_end');
     63            // Do some cleaning up after the loop
    6464            $this->rewind_groups();
    6565        }
     
    7575        $group = $this->next_group();
    7676
    77         if ( 0 == $this->current_group ) /* loop has just started */
    78             do_action( 'xprofile_template_loop_start' );
     77        if ( 0 == $this->current_group ) // loop has just started
     78            do_action('xprofile_template_loop_start');
    7979    }
    8080
     
    9090    function rewind_fields() {
    9191        $this->current_field = -1;
    92 
    93         if ( $this->field_count > 0 )
     92        if ( $this->field_count > 0 ) {
    9493            $this->field = $this->group->fields[0];
     94        }
    9595    }
    9696
     
    101101            $field = &$this->group->fields[$i];
    102102
    103             if ( $field->data->value != null )
     103            if ( $field->data->value != null ) {
    104104                $has_data = true;
     105            }
    105106        }
    106107
     
    112113
    113114    function profile_fields() {
    114         if ( $this->current_field + 1 < $this->field_count )
     115        if ( $this->current_field + 1 < $this->field_count ) {
    115116            return true;
    116 
    117         /* Do some cleaning up after the loop */
    118         elseif ( $this->current_field + 1 == $this->field_count )
     117        } elseif ( $this->current_field + 1 == $this->field_count ) {
     118            // Do some cleaning up after the loop
    119119            $this->rewind_fields();
     120        }
    120121
    121122        return false;
     
    127128        $field = $this->next_field();
    128129
    129         if ( !empty( $field->data->value ) )
     130        if ( !empty( $field->data->value ) ) {
    130131            $this->field_has_data = true;
    131         else
     132        }
     133        else {
    132134            $this->field_has_data = false;
     135        }
    133136    }
    134137}
     
    177180
    178181        if ( $class )
    179             $css_classes[] = sanitize_title( attribute_escape( $class ) );
     182            $css_classes[] = sanitize_title( esc_attr( $class ) );
    180183
    181184        /* Set a class with the field ID */
     
    185188        $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name );
    186189
    187         if ( $profile_template->current_field % 2 )
     190        if ( $profile_template->current_field % 2 == 1 )
    188191            $css_classes[] = 'alt';
    189192
     
    254257        global $group;
    255258
    256         foreach ( (array) $group->fields as $field ) {
     259        foreach ( (array) $group->fields as $field )
    257260            $field_ids .= $field->id . ',';
    258         }
    259261
    260262        return substr( $field_ids, 0, -1 );
     
    343345        global $field;
    344346
    345         return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id );
     347        $array_box = false;
     348        if ( 'multiselectbox' == $field->type )
     349            $array_box = '[]';
     350
     351        return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id . $array_box );
    346352    }
    347353
     
    369375                if ( 'multiselectbox' != $field->type )
    370376                    $html .= '<option value="">--------</option>';
     377
     378                for ( $k = 0; $k < count($options); $k++ ) {
     379                    $option_values = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );
     380                    $option_values = (array)$option_values;
     381
     382                    /* Check for updated posted values, but errors preventing them from being saved first time */
     383                    foreach( (array)$option_values as $i => $option_value ) {
     384                        if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
     385                            if ( !empty( $_POST['field_' . $field->id] ) )
     386                                $option_values[$i] = $_POST['field_' . $field->id];
     387                        }
     388                    }
     389
     390                    if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option ) {
     391                        $selected = ' selected="selected"';
     392                    } else {
     393                        $selected = '';
     394                    }
     395
     396                    $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( $options[$k]->name ) . '">' . esc_attr( $options[$k]->name ) . '</option>', $options[$k] );
     397                }
     398                break;
     399
     400            case 'radio':
     401                $html = '<div id="field_' . $field->id . '">';
    371402
    372403                for ( $k = 0; $k < count($options); $k++ ) {
     
    379410                    }
    380411
    381                     if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option )
    382                         $selected = ' selected="selected"';
    383                     else
     412                    if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) {
     413                        $selected = ' checked="checked"';
     414                    } else {
    384415                        $selected = '';
    385 
    386                     $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . attribute_escape( stripslashes( $options[$k]->name ) ) . '">' . attribute_escape( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );
    387                 }
    388                 break;
    389 
    390             case 'radio':
    391                 $html = '<div id="field_' . $field->id . '">';
    392 
    393                 for ( $k = 0; $k < count( $options ); $k++ ) {
    394                     $option_value = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );
    395 
    396                     /* Check for updated posted values, but errors preventing them from being saved first time */
    397                     if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
    398                         if ( !empty( $_POST['field_' . $field->id] ) )
    399                             $option_value = $_POST['field_' . $field->id];
    400416                    }
    401417
    402                     if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option )
    403                         $selected = ' checked="checked"';
    404                     else
    405                         $selected = '';
    406 
    407                     $html .= apply_filters( 'bp_get_the_profile_field_options_radio', '<label><input' . $selected . ' type="radio" name="field_' . $field->id . '" id="option_' . $options[$k]->id . '" value="' . attribute_escape( $options[$k]->name ) . '"> ' . attribute_escape( $options[$k]->name ) . '</label>', $options[$k] );
     418                    $html .= apply_filters( 'bp_get_the_profile_field_options_radio', '<label><input' . $selected . ' type="radio" name="field_' . $field->id . '" id="option_' . $options[$k]->id . '" value="' . esc_attr( $options[$k]->name ) . '"> ' . esc_attr( $options[$k]->name ) . '</label>', $options[$k] );
    408419                }
    409420
     
    412423
    413424            case 'checkbox':
    414                 $option_values = BP_XProfile_ProfileData::get_value_byid( $options[0]->parent_id );
     425                $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id);
    415426
    416427                /* Check for updated posted values, but errors preventing them from being saved first time */
     
    420431                }
    421432
    422                 $option_values = maybe_unserialize( $option_values );
    423 
    424                 for ( $k = 0; $k < count( $options ); $k++ ) {
    425                     for ( $j = 0; $j < count( $option_values ); $j++ ) {
     433                $option_values = maybe_unserialize($option_values);
     434
     435                for ( $k = 0; $k < count($options); $k++ ) {
     436                    for ( $j = 0; $j < count($option_values); $j++ ) {
    426437                        if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) {
    427438                            $selected = ' checked="checked"';
     
    430441                    }
    431442
    432                     $html .= apply_filters( 'bp_get_the_profile_field_options_checkbox', '<label><input' . $selected . ' type="checkbox" name="field_' . $field->id . '[]" id="field_' . $options[$k]->id . '_' . $k . '" value="' . attribute_escape( $options[$k]->name ) . '"> ' . attribute_escape( $options[$k]->name ) . '</label>', $options[$k] );
     443                    $html .= apply_filters( 'bp_get_the_profile_field_options_checkbox', '<label><input' . $selected . ' type="checkbox" name="field_' . $field->id . '[]" id="field_' . $options[$k]->id . '_' . $k . '" value="' . esc_attr( $options[$k]->name ) . '"> ' . esc_attr( $options[$k]->name ) . '</label>', $options[$k] );
    433444                    $selected = '';
    434445                }
     
    438449
    439450                if ( !empty( $field->data->value ) ) {
    440                     $day            = date("j", $field->data->value);
    441                     $month          = date("F", $field->data->value);
    442                     $year           = date("Y", $field->data->value);
    443                     $default_select = ' selected="selected"';
     451                    $day = date("j", $field->data->value);
     452                    $month = date("F", $field->data->value);
     453                    $year = date("Y", $field->data->value);
     454                    $default_select = ' selected="selected"';
    444455                }
    445456
     
    462473                switch ( $type ) {
    463474                    case 'day':
    464                         $html .= '<option value=""' . attribute_escape( $default_select ) . '>--</option>';
     475                        $html .= '<option value=""' . esc_attr( $default_select ) . '>--</option>';
    465476
    466477                        for ( $i = 1; $i < 32; $i++ ) {
    467                             if ( $day == $i )
     478                            if ( $day == $i ) {
    468479                                $selected = ' selected = "selected"';
    469                             else
     480                            } else {
    470481                                $selected = '';
    471 
     482                            }
    472483                            $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
    473484                        }
     
    483494                                );
    484495
    485                         $html .= '<option value=""' . attribute_escape( $default_select ) . '>------</option>';
     496                        $html .= '<option value=""' . esc_attr( $default_select ) . '>------</option>';
    486497
    487498                        for ( $i = 0; $i < 12; $i++ ) {
    488                             if ( $month == $eng_months[$i] )
     499                            if ( $month == $eng_months[$i] ) {
    489500                                $selected = ' selected = "selected"';
    490                             else
     501                            } else {
    491502                                $selected = '';
     503                            }
    492504
    493505                            $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>';
     
    496508
    497509                    case 'year':
    498                         $html .= '<option value=""' . attribute_escape( $default_select ) . '>----</option>';
     510                        $html .= '<option value=""' . esc_attr( $default_select ) . '>----</option>';
    499511
    500512                        for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) {
    501                             if ( $year == $i )
     513                            if ( $year == $i ) {
    502514                                $selected = ' selected = "selected"';
    503                             else
     515                            } else {
    504516                                $selected = '';
     517                            }
    505518
    506519                            $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
     
    523536        global $field;
    524537
    525         return apply_filters( 'bp_get_the_profile_field_is_required', (int) $field->is_required );
     538        return apply_filters( 'bp_get_the_profile_field_is_required', (int)$field->is_required );
    526539    }
    527540
    528541function bp_unserialize_profile_field( $value ) {
    529     if ( is_serialized( $value ) ) {
    530         $field_value = maybe_unserialize( $value );
     542    if ( is_serialized($value) ) {
     543        $field_value = maybe_unserialize($value);
    531544        $field_value = implode( ', ', $field_value );
    532545        return $field_value;
     
    541554    function bp_get_profile_field_data( $args = '' ) {
    542555        $defaults = array(
    543             'field'     => false, /* Field name or ID. */
    544             'user_id'   => $bp->displayed_user->id
    545         );
     556            'field' => false, // Field name or ID.
     557            'user_id' => $bp->displayed_user->id
     558            );
    546559
    547560        $r = wp_parse_args( $args, $defaults );
     
    562575        $group_name = bp_profile_group_name(false);
    563576
    564     for ( $i = 0; $i < count( $groups ); $i++ ) {
    565         if ( $group_name == $groups[$i]->name )
     577    for ( $i = 0; $i < count($groups); $i++ ) {
     578        if ( $group_name == $groups[$i]->name ) {
    566579            $selected = ' class="current"';
    567         else
     580        } else {
    568581            $selected = '';
     582        }
    569583
    570584        if ( $groups[$i]->fields )
    571             echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . attribute_escape( $groups[$i]->name ) . '</a></li>';
     585            echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . esc_attr( $groups[$i]->name ) . '</a></li>';
    572586    }
    573587
     
    584598
    585599    if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    586         $group = new BP_XProfile_Group( $group_id );
     600        $group = new BP_XProfile_Group($group_id);
    587601        wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    588602    }
    589603
    590     if ( !$deprecated )
     604    if ( !$deprecated ) {
    591605        return bp_get_profile_group_name();
    592     else
     606    } else {
    593607        echo bp_get_profile_group_name();
     608    }
    594609}
    595610    function bp_get_profile_group_name() {
     
    602617
    603618        if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    604             $group = new BP_XProfile_Group( $group_id );
     619            $group = new BP_XProfile_Group($group_id);
    605620            wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    606621        }
     
    623638    $last_updated = bp_get_profile_last_updated();
    624639
    625     if ( !$last_updated )
     640    if ( !$last_updated ) {
    626641        _e( 'Profile not recently updated', 'buddypress' ) . '.';
    627     else
     642    } else {
    628643        echo $last_updated;
     644    }
    629645}
    630646    function bp_get_profile_last_updated() {
    631647        global $bp;
    632648
    633         $last_updated = get_usermeta( $bp->displayed_user->id, 'profile_last_updated' );
     649        $last_updated = get_user_meta( $bp->displayed_user->id, 'profile_last_updated', true );
    634650
    635651        if ( $last_updated )
     
    648664            $profile_group_id = 1;
    649665
    650         /* admin/profile/edit/[group-id] */
    651         return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id );
     666        return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id]
    652667    }
    653668
     
    671686    global $bp;
    672687
     688    bp_button( array (
     689        'id'                => 'edit_profile',
     690        'component'         => 'xprofile',
     691        'must_be_logged_in' => true,
     692        'block_self'        => true,
     693        'link_href'         => trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit' ),
     694        'link_class'        => 'edit',
     695        'link_text'         => __( 'Edit Profile', 'buddypress' ),
     696        'link_title'        => __( 'Edit Profile', 'buddypress' ),
     697    ) );
     698}
     699
    673700?>
    674 
    675     <div class="generic-button">
    676         <a class="edit" title="<?php _e( 'Edit Profile', 'buddypress' ); ?>" href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit"><?php _e( 'Edit Profile', 'buddypress' ); ?></a>
    677     </div>
    678 <?php
    679 }
    680 
    681 ?>
Note: See TracChangeset for help on using the changeset viewer.