Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/05/2010 04:01:27 AM (16 years ago)
Author:
johnjamesjacoby
Message:

Sweep through xprofile and format code to WP standards

File:
1 edited

Legend:

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

    r2798 r2810  
    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                 if ( $this->group_count > 0 ) {
     53
     54                if ( $this->group_count > 0 )
    5455                        $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');
     62                        do_action( 'xprofile_template_loop_end' );
    6363                        /* Do some cleaning up after the loop */
    6464                        $this->rewind_groups();
     
    7676
    7777                if ( 0 == $this->current_group ) /* loop has just started */
    78                         do_action('xprofile_template_loop_start');
     78                        do_action( 'xprofile_template_loop_start' );
    7979        }
    8080
     
    9090        function rewind_fields() {
    9191                $this->current_field = -1;
    92                 if ( $this->field_count > 0 ) {
     92
     93                if ( $this->field_count > 0 )
    9394                        $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                         }
    106105                }
    107106
     
    113112
    114113        function profile_fields() {
    115                 if ( $this->current_field + 1 < $this->field_count ) {
     114                if ( $this->current_field + 1 < $this->field_count )
    116115                        return true;
    117                 } elseif ( $this->current_field + 1 == $this->field_count ) {
    118                         /* Do some cleaning up after the loop */
     116
     117                /* Do some cleaning up after the loop */
     118                elseif ( $this->current_field + 1 == $this->field_count )
    119119                        $this->rewind_fields();
    120                 }
    121120
    122121                return false;
     
    128127                $field = $this->next_field();
    129128
    130                 if ( !empty( $field->data->value ) ) {
     129                if ( !empty( $field->data->value ) )
    131130                        $this->field_has_data = true;
    132                 }
    133                 else {
     131                else
    134132                        $this->field_has_data = false;
    135                 }
    136133        }
    137134}
     
    257254                global $group;
    258255
    259                 foreach ( (array) $group->fields as $field )
     256                foreach ( (array) $group->fields as $field ) {
    260257                        $field_ids .= $field->id . ',';
     258                }
    261259
    262260                return substr( $field_ids, 0, -1 );
     
    372370                                        $html .= '<option value="">--------</option>';
    373371
    374                                 for ( $k = 0; $k < count($options); $k++ ) {
    375                                         $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
     372                                for ( $k = 0; $k < count( $options ); $k++ ) {
     373                                        $option_value = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );
    376374
    377375                                        /* Check for updated posted values, but errors preventing them from being saved first time */
     
    381379                                        }
    382380
    383                                         if ( $option_value == $options[$k]->name || $options[$k]->is_default_option ) {
     381                                        if ( $option_value == $options[$k]->name || $options[$k]->is_default_option )
    384382                                                $selected = ' selected="selected"';
    385                                         } else {
     383                                        else
    386384                                                $selected = '';
    387                                         }
    388385
    389386                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . attribute_escape( $options[$k]->name ) . '">' . attribute_escape( $options[$k]->name ) . '</option>', $options[$k] );
     
    394391                                $html = '<div id="field_' . $field->id . '">';
    395392
    396                                 for ( $k = 0; $k < count($options); $k++ ) {
    397                                         $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
     393                                for ( $k = 0; $k < count( $options ); $k++ ) {
     394                                        $option_value = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );
    398395
    399396                                        /* Check for updated posted values, but errors preventing them from being saved first time */
     
    403400                                        }
    404401
    405                                         if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) {
     402                                        if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option )
    406403                                                $selected = ' checked="checked"';
    407                                         } else {
     404                                        else
    408405                                                $selected = '';
    409                                         }
    410406
    411407                                        $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] );
     
    416412
    417413                        case 'checkbox':
    418                                 $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id);
     414                                $option_values = BP_XProfile_ProfileData::get_value_byid( $options[0]->parent_id );
    419415
    420416                                /* Check for updated posted values, but errors preventing them from being saved first time */
     
    424420                                }
    425421
    426                                 $option_values = maybe_unserialize($option_values);
    427 
    428                                 for ( $k = 0; $k < count($options); $k++ ) {
    429                                         for ( $j = 0; $j < count($option_values); $j++ ) {
     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++ ) {
    430426                                                if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) {
    431427                                                        $selected = ' checked="checked"';
     
    442438
    443439                                if ( !empty( $field->data->value ) ) {
    444                                         $day = date("j", $field->data->value);
    445                                         $month = date("F", $field->data->value);
    446                                         $year = date("Y", $field->data->value);
    447                                         $default_select = ' selected="selected"';
     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"';
    448444                                }
    449445
     
    469465
    470466                                                for ( $i = 1; $i < 32; $i++ ) {
    471                                                         if ( $day == $i ) {
     467                                                        if ( $day == $i )
    472468                                                                $selected = ' selected = "selected"';
    473                                                         } else {
     469                                                        else
    474470                                                                $selected = '';
    475                                                         }
     471
    476472                                                        $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
    477473                                                }
     
    490486
    491487                                                for ( $i = 0; $i < 12; $i++ ) {
    492                                                         if ( $month == $eng_months[$i] ) {
     488                                                        if ( $month == $eng_months[$i] )
    493489                                                                $selected = ' selected = "selected"';
    494                                                         } else {
     490                                                        else
    495491                                                                $selected = '';
    496                                                         }
    497492
    498493                                                        $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>';
     
    504499
    505500                                                for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) {
    506                                                         if ( $year == $i ) {
     501                                                        if ( $year == $i )
    507502                                                                $selected = ' selected = "selected"';
    508                                                         } else {
     503                                                        else
    509504                                                                $selected = '';
    510                                                         }
    511505
    512506                                                        $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
     
    529523                global $field;
    530524
    531                 return apply_filters( 'bp_get_the_profile_field_is_required', (int)$field->is_required );
     525                return apply_filters( 'bp_get_the_profile_field_is_required', (int) $field->is_required );
    532526        }
    533527
    534528function bp_unserialize_profile_field( $value ) {
    535         if ( is_serialized($value) ) {
    536                 $field_value = maybe_unserialize($value);
     529        if ( is_serialized( $value ) ) {
     530                $field_value = maybe_unserialize( $value );
    537531                $field_value = implode( ', ', $field_value );
    538532                return $field_value;
     
    547541        function bp_get_profile_field_data( $args = '' ) {
    548542                $defaults = array(
    549                         'field' => false, /* Field name or ID. */
    550                         'user_id' => $bp->displayed_user->id
     543                        'field'         => false, /* Field name or ID. */
     544                        'user_id'       => $bp->displayed_user->id
    551545                );
    552546
     
    568562                $group_name = bp_profile_group_name(false);
    569563
    570         for ( $i = 0; $i < count($groups); $i++ ) {
    571                 if ( $group_name == $groups[$i]->name ) {
     564        for ( $i = 0; $i < count( $groups ); $i++ ) {
     565                if ( $group_name == $groups[$i]->name )
    572566                        $selected = ' class="current"';
    573                 } else {
     567                else
    574568                        $selected = '';
    575                 }
    576569
    577570                if ( $groups[$i]->fields )
     
    591584
    592585        if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    593                 $group = new BP_XProfile_Group($group_id);
     586                $group = new BP_XProfile_Group( $group_id );
    594587                wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    595588        }
    596589
    597         if ( !$deprecated ) {
     590        if ( !$deprecated )
    598591                return bp_get_profile_group_name();
    599         } else {
     592        else
    600593                echo bp_get_profile_group_name();
    601         }
    602594}
    603595        function bp_get_profile_group_name() {
     
    610602
    611603                if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    612                         $group = new BP_XProfile_Group($group_id);
     604                        $group = new BP_XProfile_Group( $group_id );
    613605                        wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    614606                }
     
    631623        $last_updated = bp_get_profile_last_updated();
    632624
    633         if ( !$last_updated ) {
     625        if ( !$last_updated )
    634626                _e( 'Profile not recently updated', 'buddypress' ) . '.';
    635         } else {
     627        else
    636628                echo $last_updated;
    637         }
    638629}
    639630        function bp_get_profile_last_updated() {
     
    680671        global $bp;
    681672
    682         ?>
     673?>
     674
    683675        <div class="generic-button">
    684                 <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>
     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>
    685677        </div>
    686         <?php
    687 }
    688 
     678<?php
     679}
    689680
    690681?>
Note: See TracChangeset for help on using the changeset viewer.