Skip to:
Content

BuddyPress.org

Ticket #2947: 2947.002.diff

File 2947.002.diff, 10.1 KB (added by cnorris23, 14 years ago)
  • bp-xprofile/bp-xprofile-templatetags.php

     
    187187                if ( $class )
    188188                        $css_classes[] = sanitize_title( esc_attr( $class ) );
    189189
    190                 /* Set a class with the field ID */
     190                // Set a class with the field ID
    191191                $css_classes[] = 'field_' . $profile_template->field->id;
    192192
    193                 /* Set a class with the field name (sanitized) */
     193                // Set a class with the field name (sanitized)
    194194                $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name );
    195195
    196196                if ( $profile_template->current_field % 2 == 1 )
     
    359359                return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id . $array_box );
    360360        }
    361361
     362/**
     363 * bp_the_profile_field_options()
     364 *
     365 * Displays field options HTML for field types of 'selectbox', 'multiselectbox',
     366 * 'radio', 'checkbox', and 'datebox'.
     367 *
     368 * @package BuddyPress Xprofile
     369 * @since 1.1
     370 *
     371 * @uses bp_get_the_profile_field_options()
     372 *
     373 * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'.
     374 */
    362375function bp_the_profile_field_options( $args = '' ) {
    363376        echo bp_get_the_profile_field_options( $args );
    364377}
     378        /**
     379         * bp_get_the_profile_field_options()
     380         *
     381         * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox',
     382         * 'radio', 'checkbox', and 'datebox'.
     383         *
     384         * @package BuddyPress Xprofile
     385         * @since 1.1
     386         *
     387         * @uses BP_XProfile_Field::get_children()
     388         * @uses BP_XProfile_ProfileData::get_value_byid()
     389         *
     390         * @param array $args Specify type for datebox. Allowed 'day', 'month', 'year'.
     391         */
    365392        function bp_get_the_profile_field_options( $args = '' ) {
    366393                global $field;
    367394
     
    377404
    378405                $options = $field->get_children();
    379406
     407                // Setup some defaults
     408                $html     = '';
     409                $selected = '';
     410
    380411                switch ( $field->type ) {
    381412
    382413                        case 'selectbox': case 'multiselectbox':
     
    385416
    386417                                for ( $k = 0; $k < count($options); $k++ ) {
    387418                                        $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ) );
    388                                         $option_values = (array)$option_values;
     419                                        $option_values = (array) $option_values;
    389420
    390                                         /* Check for updated posted values, but errors preventing them from being saved first time */
    391                                         foreach( (array)$option_values as $i => $option_value ) {
     421                                        // Check for updated posted values, but errors preventing them from being saved first time
     422                                        foreach( $option_values as $i => $option_value ) {
    392423                                                if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
    393424                                                        if ( !empty( $_POST['field_' . $field->id] ) )
    394425                                                                $option_values[$i] = $_POST['field_' . $field->id];
    395426                                                }
    396427                                        }
    397428
    398                                         if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option ) {
     429                                        if ( in_array( $options[$k]->name, (array) $option_values ) || $options[$k]->is_default_option )
    399430                                                $selected = ' selected="selected"';
    400                                         } else {
    401                                                 $selected = '';
    402                                         }
    403431
    404                                         $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . stripslashes( esc_attr( $options[$k]->name ) ) . '">' . stripslashes( esc_attr( $options[$k]->name ) ) . '</option>', $options[$k] );
     432                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );
    405433                                }
    406434                                break;
    407435
    408436                        case 'radio':
    409                                 $html = '<div id="field_' . $field->id . '">';
     437                                $html .= '<div id="field_' . $field->id . '">';
    410438
    411439                                for ( $k = 0; $k < count($options); $k++ ) {
    412440                                        $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
    413441
    414                                         /* Check for updated posted values, but errors preventing them from being saved first time */
     442                                        // Check for updated posted values, but errors preventing them from being saved first time
    415443                                        if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
    416444                                                if ( !empty( $_POST['field_' . $field->id] ) )
    417445                                                        $option_value = $_POST['field_' . $field->id];
    418446                                        }
    419447
    420                                         if ( $option_value == $options[$k]->name || $value == $options[$k]->name || ( empty( $option_value ) && $options[$k]->is_default_option ) ) {
     448                                        if ( $option_value == $options[$k]->name || $value == $options[$k]->name || ( empty( $option_value ) && $options[$k]->is_default_option ) )
    421449                                                $selected = ' checked="checked"';
    422                                         } else {
    423                                                 $selected = '';
    424                                         }
    425450
    426                                         $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="' . stripslashes( esc_attr( $options[$k]->name ) ) . '"> ' . stripslashes( esc_attr( $options[$k]->name ) ) . '</label>', $options[$k] );
     451                                        $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( stripslashes( $options[$k]->name ) ) . '"> ' . esc_attr( stripslashes( $options[$k]->name ) ) . '</label>', $options[$k] );
    427452                                }
    428453
    429454                                $html .= '</div>';
     
    432457                        case 'checkbox':
    433458                                $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id);
    434459
    435                                 /* Check for updated posted values, but errors preventing them from being saved first time */
     460                                // Check for updated posted values, but errors preventing them from being saved first time
    436461                                if ( isset( $_POST['field_' . $field->id] ) && $option_values != maybe_serialize( $_POST['field_' . $field->id] ) ) {
    437462                                        if ( !empty( $_POST['field_' . $field->id] ) )
    438463                                                $option_values = $_POST['field_' . $field->id];
     
    440465
    441466                                $option_values = maybe_unserialize($option_values);
    442467
    443                                 $html = '';
    444468                                for ( $k = 0; $k < count($options); $k++ ) {
    445                                         $selected = '';
    446469                                        for ( $j = 0; $j < count($option_values); $j++ ) {
    447470                                                if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) {
    448471                                                        $selected = ' checked="checked"';
     
    450473                                                }
    451474                                        }
    452475
    453                                         $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="' . stripslashes( esc_attr( $options[$k]->name ) ) . '"> ' . stripslashes( esc_attr( $options[$k]->name ) ) . '</label>', $options[$k] );
    454                                         $selected = '';
     476                                        $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( stripslashes( $options[$k]->name ) ) . '"> ' . esc_attr( stripslashes( $options[$k]->name ) ) . '</label>', $options[$k] );
    455477                                }
    456478                                break;
    457479
    458480                        case 'datebox':
     481                                $date = BP_XProfile_ProfileData::get_value_byid( $field->id );
    459482
    460                                 if ( !empty( $field->data->value ) ) {
    461                                         $day = date("j", $field->data->value);
    462                                         $month = date("F", $field->data->value);
    463                                         $year = date("Y", $field->data->value);
    464                                         $default_select = ' selected="selected"';
     483                                // Set day, month, year defaults
     484                                $day   = '';
     485                                $month = '';
     486                                $year  = '';
     487
     488                                if ( !empty( $date ) ) {
     489                                        $day   = date( 'j', $date );
     490                                        $month = date( 'F', $date );
     491                                        $year  = date( 'Y', $date );
    465492                                }
    466493
    467                                 /* Check for updated posted values, but errors preventing them from being saved first time */
     494                                // Check for updated posted values, but errors preventing them from being saved first time
    468495                                if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) {
    469496                                        if ( $day != $_POST['field_' . $field->id . '_day'] )
    470497                                                $day = $_POST['field_' . $field->id . '_day'];
     
    482509
    483510                                switch ( $type ) {
    484511                                        case 'day':
    485                                                 $html .= '<option value=""' . esc_attr( $default_select ) . '>--</option>';
     512                                                $html .= '<option value=""' . selected( $day, '', false ) . '>--</option>';
    486513
    487514                                                for ( $i = 1; $i < 32; $i++ ) {
    488                                                         if ( $day == $i ) {
    489                                                                 $selected = ' selected = "selected"';
    490                                                         } else {
    491                                                                 $selected = '';
    492                                                         }
    493                                                         $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
     515                                                        $html .= '<option value="' . $i .'"' . selected( $day, $i, false ) . '>' . $i . '</option>';
    494516                                                }
    495517                                                break;
    496518
     
    503525                                                                 __( 'October', 'buddypress' ), __( 'November', 'buddypress' ), __( 'December', 'buddypress' )
    504526                                                                );
    505527
    506                                                 $html .= '<option value=""' . esc_attr( $default_select ) . '>------</option>';
     528                                                $html .= '<option value=""' . selected( $month, '', false ) . '>------</option>';
    507529
    508530                                                for ( $i = 0; $i < 12; $i++ ) {
    509                                                         if ( $month == $eng_months[$i] ) {
    510                                                                 $selected = ' selected = "selected"';
    511                                                         } else {
    512                                                                 $selected = '';
    513                                                         }
    514 
    515                                                         $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>';
     531                                                        $html .= '<option value="' . $eng_months[$i] . '"' . selected( $month, $eng_months[$i], false ) . '>' . $months[$i] . '</option>';
    516532                                                }
    517533                                                break;
    518534
    519535                                        case 'year':
    520                                                 $html .= '<option value=""' . esc_attr( $default_select ) . '>----</option>';
     536                                                $html .= '<option value=""' . selected( $year, '', false ) . '>----</option>';
    521537
    522                                                 for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) {
    523                                                         if ( $year == $i ) {
    524                                                                 $selected = ' selected = "selected"';
    525                                                         } else {
    526                                                                 $selected = '';
    527                                                         }
    528 
    529                                                         $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
     538                                                for ( $i = date( 'Y' ); $i > 1899; $i-- ) {
     539                                                        $html .= '<option value="' . $i .'"' . selected( $year, $i, false ) . '>' . $i . '</option>';
    530540                                                }
    531541                                                break;
    532542                                }
    533543
    534                                 apply_filters( 'bp_get_the_profile_field_datebox', $html, $day, $month, $year, $default_select );
     544                                $html = apply_filters( 'bp_get_the_profile_field_datebox', $html, $type, $day, $month, $year );
    535545
    536546                                break;
    537547                }