Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (17 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

File:
1 edited

Legend:

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

    r2066 r2077  
    1010    var $groups;
    1111    var $group;
    12    
     12
    1313    var $current_field = -1;
    1414    var $field_count;
    1515    var $field_has_data;
    1616    var $field;
    17    
     17
    1818    var $in_the_loop;
    1919    var $user_id;
    2020
    2121    function bp_xprofile_data_template( $user_id, $profile_group_id ) {
    22        
     22
    2323        if ( !$profile_group_id ) {
    2424            if ( !$this->groups = wp_cache_get( 'xprofile_groups', 'bp' ) ) {
     
    3131                wp_cache_set( 'xprofile_group_' . $profile_group_id, 'bp' );
    3232            }
    33            
     33
    3434            /* We need to put this single group into the same format as multiple group (an array) */
    3535            $this->groups = array( $this->groups );
    3636        }
    37        
     37
    3838        $this->group_count = count($this->groups);
    3939        $this->user_id = $user_id;
    4040    }
    41    
     41
    4242    function has_groups() {
    4343        if ( $this->group_count )
    4444            return true;
    45        
     45
    4646        return false;
    4747    }
    48    
     48
    4949    function next_group() {
    5050        $this->current_group++;
    5151
    5252        $this->group = $this->groups[$this->current_group];
    53        
     53
    5454        if ( !$fields = wp_cache_get( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, 'bp' ) ) {
    5555            for ( $i = 0; $i < count($this->group->fields); $i++ ) {
     
    6060                $fields[$i] = $field;
    6161            }
    62            
     62
    6363            wp_cache_set( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, $fields, 'bp' );
    6464        }
    65        
     65
    6666        $this->group->fields = apply_filters( 'xprofile_group_fields', $fields, $this->group->id );
    6767        $this->field_count = count( $this->group->fields );
    68        
     68
    6969        return $this->group;
    7070    }
    71    
     71
    7272    function rewind_groups() {
    7373        $this->current_group = -1;
     
    7676        }
    7777    }
    78    
    79     function profile_groups() { 
     78
     79    function profile_groups() {
    8080        if ( $this->current_group + 1 < $this->group_count ) {
    8181            return true;
     
    8989        return false;
    9090    }
    91    
     91
    9292    function the_profile_group() {
    9393        global $group;
     
    9999            do_action('xprofile_template_loop_start');
    100100    }
    101    
     101
    102102    /**** FIELDS ****/
    103    
     103
    104104    function next_field() {
    105105        $this->current_field++;
     
    108108        return $this->field;
    109109    }
    110    
     110
    111111    function rewind_fields() {
    112112        $this->current_field = -1;
     
    114114            $this->field = $this->group->fields[0];
    115115        }
    116     }   
    117    
    118     function has_fields() { 
     116    }
     117
     118    function has_fields() {
    119119        $has_data = false;
    120120        $just_name = true;
    121121
    122         for ( $i = 0; $i < count( $this->group->fields ); $i++ ) { 
     122        for ( $i = 0; $i < count( $this->group->fields ); $i++ ) {
    123123            $field = &$this->group->fields[$i];
    124124
    125125            if ( $field->data->value != null ) {
    126126                $has_data = true;
    127                
     127
    128128                if ( 1 != $field->id )
    129129                    $just_name = false;
    130130            }
    131131        }
    132        
     132
    133133        if ( 1 == $this->group->id && $just_name )
    134134            return false;
     
    136136        if ( $has_data )
    137137            return true;
    138        
     138
    139139        return false;
    140140    }
    141    
     141
    142142    function profile_fields() {
    143143        if ( $this->current_field + 1 < $this->field_count ) {
     
    148148        }
    149149
    150         return false;   
    151     }
    152    
     150        return false;
     151    }
     152
    153153    function the_profile_field() {
    154154        global $field;
     
    169169}
    170170
    171 function bp_has_profile( $args = '' ) { 
     171function bp_has_profile( $args = '' ) {
    172172    global $bp, $profile_template;
    173    
     173
    174174    $defaults = array(
    175175        'user_id' => $bp->displayed_user->id,
     
    179179    $r = wp_parse_args( $args, $defaults );
    180180    extract( $r, EXTR_SKIP );
    181    
     181
    182182    $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id );
    183183    return apply_filters( 'bp_has_profile', $profile_template->has_groups(), &$profile_template );
    184184}
    185185
    186 function bp_profile_groups() { 
     186function bp_profile_groups() {
    187187    global $profile_template;
    188188    return $profile_template->profile_groups();
     
    209209    function bp_get_field_css_class( $class = false ) {
    210210        global $profile_template;
    211    
     211
    212212        $css_classes = array();
    213        
     213
    214214        if ( $class )
    215215            $css_classes[] = sanitize_title( attribute_escape( $class ) );
    216        
     216
    217217        /* Set a class with the field ID */
    218218        $css_classes[] = 'field_' . $profile_template->field->id;
    219        
     219
    220220        /* Set a class with the field name (sanitized) */
    221221        $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name );
    222        
     222
    223223        if ( $profile_template->current_field % 2 )
    224224            $css_classes[] = 'alt';
    225        
     225
    226226        $css_classes = apply_filters( 'bp_field_css_classes', &$css_classes );
    227227
     
    236236function bp_field_has_public_data() {
    237237    global $profile_template;
    238    
     238
    239239    if ( $profile_template->field_has_data )
    240240        return true;
    241    
     241
    242242    return false;
    243243}
     
    274274        echo apply_filters( 'bp_get_the_profile_group_description', $group->description );
    275275    }
    276    
     276
    277277function bp_the_profile_group_edit_form_action() {
    278278    echo bp_get_the_profile_group_edit_form_action();
     
    280280    function bp_get_the_profile_group_edit_form_action() {
    281281        global $bp, $group;
    282        
     282
    283283        return apply_filters( 'bp_get_the_profile_group_edit_form_action', $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $group->id . '/' );
    284     }   
     284    }
    285285
    286286function bp_the_profile_group_field_ids() {
     
    292292        foreach ( (array) $group->fields as $field )
    293293            $field_ids .= $field->id . ',';
    294            
     294
    295295        return substr( $field_ids, 0, -1 );
    296296    }
    297    
     297
    298298function bp_profile_fields() {
    299299    global $profile_template;
     
    359359    function bp_get_the_profile_field_type() {
    360360        global $field;
    361        
     361
    362362        return apply_filters( 'bp_the_profile_field_type', $field->type );
    363363    }
     
    368368    function bp_get_the_profile_field_description() {
    369369        global $field;
    370        
     370
    371371        return apply_filters( 'bp_get_the_profile_field_description', $field->description );
    372372    }
    373    
     373
    374374function bp_the_profile_field_input_name() {
    375375    echo bp_get_the_profile_field_input_name();
     
    377377    function bp_get_the_profile_field_input_name() {
    378378        global $field;
    379    
     379
    380380        return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id );
    381381    }
     
    386386    function bp_get_the_profile_field_options( $args = '' ) {
    387387        global $field;
    388        
     388
    389389        $defaults = array(
    390390            'type' => false
     
    393393        $r = wp_parse_args( $args, $defaults );
    394394        extract( $r, EXTR_SKIP );
    395        
     395
    396396        $options = $field->get_children();
    397397
    398398        switch ( $field->type ) {
    399            
     399
    400400            case 'selectbox': case 'multiselectbox':
    401401                if ( 'multiselectbox' != $field->type )
    402402                    $html .= '<option value="">--------</option>';
    403                        
     403
    404404                for ( $k = 0; $k < count($options); $k++ ) {
    405405                    $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
    406                    
     406
    407407                    /* Check for updated posted values, but errors preventing them from being saved first time */
    408408                    if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
     
    410410                            $option_value = $_POST['field_' . $field->id];
    411411                    }
    412                                        
     412
    413413                    if ( $option_value == $options[$k]->name || $options[$k]->is_default_option ) {
    414414                        $selected = ' selected="selected"';
     
    420420                }
    421421                break;
    422                
     422
    423423            case 'radio':
    424424                $html = '<div id="field_' . $field->id . '">';
    425                
    426                 for ( $k = 0; $k < count($options); $k++ ) {               
     425
     426                for ( $k = 0; $k < count($options); $k++ ) {
    427427                    $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
    428428
     
    432432                            $option_value = $_POST['field_' . $field->id];
    433433                    }
    434                                
     434
    435435                    if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) {
    436436                        $selected = ' checked="checked"';
     
    438438                        $selected = '';
    439439                    }
    440                    
     440
    441441                    $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] );
    442442                }
    443                
     443
    444444                $html .= '</div>';
    445445                break;
    446                
     446
    447447            case 'checkbox':
    448448                $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id);
    449                
     449
    450450                /* Check for updated posted values, but errors preventing them from being saved first time */
    451451                if ( isset( $_POST['field_' . $field->id] ) && $option_values != maybe_serialize( $_POST['field_' . $field->id] ) ) {
     
    453453                        $option_values = $_POST['field_' . $field->id];
    454454                }
    455        
     455
    456456                $option_values = maybe_unserialize($option_values);
    457457
    458                 for ( $k = 0; $k < count($options); $k++ ) {               
     458                for ( $k = 0; $k < count($options); $k++ ) {
    459459                    for ( $j = 0; $j < count($option_values); $j++ ) {
    460460                        if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) {
     
    463463                        }
    464464                    }
    465                    
     465
    466466                    $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] );
    467467                    $selected = '';
    468468                }
    469469                break;
    470            
     470
    471471            case 'datebox':
    472472
     
    477477                    $default_select = ' selected="selected"';
    478478                }
    479                
     479
    480480                /* Check for updated posted values, but errors preventing them from being saved first time */
    481481                if ( isset( $_POST['field_' . $field->id . '_day'] ) && $day != $_POST['field_' . $field->id . '_day'] ) {
     
    483483                        $day = $_POST['field_' . $field->id . '_day'];
    484484                }
    485                
     485
    486486                if ( isset( $_POST['field_' . $field->id . '_month'] ) && $month != $_POST['field_' . $field->id . '_month'] ) {
    487487                    if ( !empty( $_POST['field_' . $field->id . '_month'] ) )
    488488                        $month = $_POST['field_' . $field->id . '_month'];
    489489                }
    490                
     490
    491491                if ( isset( $_POST['field_' . $field->id . '_year'] ) && $year != date("j", $_POST['field_' . $field->id . '_year'] ) ) {
    492492                    if ( !empty( $_POST['field_' . $field->id . '_year'] ) )
    493493                        $year = $_POST['field_' . $field->id . '_year'];
    494494                }
    495                
     495
    496496                switch ( $type ) {
    497497                    case 'day':
    498498                        $html .= '<option value=""' . attribute_escape( $default_select ) . '>--</option>';
    499                
     499
    500500                        for ( $i = 1; $i < 32; $i++ ) {
    501                             if ( $day == $i ) { 
    502                                 $selected = ' selected = "selected"'; 
     501                            if ( $day == $i ) {
     502                                $selected = ' selected = "selected"';
    503503                            } else {
    504504                                $selected = '';
     
    507507                        }
    508508                        break;
    509                    
     509
    510510                    case 'month':
    511511                        $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
    512                        
    513                         $months = array( __( 'January', 'buddypress' ), __( 'February', 'buddypress' ), __( 'March', 'buddypress' ), 
     512
     513                        $months = array( __( 'January', 'buddypress' ), __( 'February', 'buddypress' ), __( 'March', 'buddypress' ),
    514514                                 __( 'April', 'buddypress' ), __( 'May', 'buddypress' ), __( 'June', 'buddypress' ),
    515515                                 __( 'July', 'buddypress' ), __( 'August', 'buddypress' ), __( 'September', 'buddypress' ),
     
    518518
    519519                        $html .= '<option value=""' . attribute_escape( $default_select ) . '>------</option>';
    520                
     520
    521521                        for ( $i = 0; $i < 12; $i++ ) {
    522522                            if ( $month == $eng_months[$i] ) {
     
    525525                                $selected = '';
    526526                            }
    527                    
     527
    528528                            $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>';
    529529                        }
    530530                        break;
    531                        
     531
    532532                    case 'year':
    533533                        $html .= '<option value=""' . attribute_escape( $default_select ) . '>----</option>';
    534                                
     534
    535535                        for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) {
    536536                            if ( $year == $i ) {
    537                                 $selected = ' selected = "selected"'; 
     537                                $selected = ' selected = "selected"';
    538538                            } else {
    539539                                $selected = '';
    540540                            }
    541                
     541
    542542                            $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>';
    543543                        }
    544544                        break;
    545545                }
    546                
    547                 apply_filters( 'bp_get_the_profile_field_datebox', $html, $day, $month, $year, $default_select ); 
     546
     547                apply_filters( 'bp_get_the_profile_field_datebox', $html, $day, $month, $year, $default_select );
    548548
    549549                break;
    550550        }
    551        
     551
    552552        return $html;
    553553    }
     
    558558    function bp_get_the_profile_field_is_required() {
    559559        global $field;
    560        
     560
    561561        return apply_filters( 'bp_get_the_profile_field_is_required', (int)$field->is_required );
    562562    }
    563    
     563
    564564function bp_unserialize_profile_field( $value ) {
    565565    if ( is_serialized($value) ) {
     
    568568        return $field_value;
    569569    }
    570    
     570
    571571    return $value;
    572572}
     
    574574function bp_profile_group_tabs() {
    575575    global $bp, $group_name;
    576    
     576
    577577    if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) {
    578578        $groups = BP_XProfile_Group::get_all();
     
    582582    if ( empty( $group_name ) )
    583583        $group_name = bp_profile_group_name(false);
    584    
     584
    585585    for ( $i = 0; $i < count($groups); $i++ ) {
    586586        if ( $group_name == $groups[$i]->name ) {
     
    589589            $selected = '';
    590590        }
    591        
     591
    592592        if ( $groups[$i]->fields )
    593593            echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . attribute_escape( $groups[$i]->name ) . '</a></li>';
    594594    }
    595    
     595
    596596    do_action( 'xprofile_profile_group_tabs' );
    597597}
     
    599599function bp_profile_group_name( $deprecated = true ) {
    600600    global $bp;
    601    
     601
    602602    $group_id = $bp->action_variables[1];
    603    
     603
    604604    if ( !is_numeric( $group_id ) )
    605605        $group_id = 1;
    606    
     606
    607607    if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    608608        $group = new BP_XProfile_Group($group_id);
    609609        wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    610610    }
    611    
     611
    612612    if ( !$deprecated ) {
    613613        return bp_get_profile_group_name();
     
    634634function bp_avatar_upload_form() {
    635635    global $bp;
    636    
    637     if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) 
     636
     637    if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) )
    638638        bp_core_avatar_admin( null, $bp->loggedin_user->domain . $bp->profile->slug . '/change-avatar/', $bp->loggedin_user->domain . $bp->profile->slug . '/delete-avatar/' );
    639639    else
     
    643643function bp_profile_last_updated() {
    644644    global $bp;
    645    
     645
    646646    $last_updated = bp_get_profile_last_updated();
    647647
     
    658658
    659659        if ( $last_updated )
    660             return apply_filters( 'bp_get_profile_last_updated', sprintf( __('Profile updated %s ago', 'buddypress'), bp_core_time_since( strtotime( $last_updated ) ) ) ); 
    661        
     660            return apply_filters( 'bp_get_profile_last_updated', sprintf( __('Profile updated %s ago', 'buddypress'), bp_core_time_since( strtotime( $last_updated ) ) ) );
     661
    662662        return false;
    663663    }
     
    668668    function bp_get_current_profile_group_id() {
    669669        global $bp;
    670        
     670
    671671        if ( !$profile_group_id = $bp->action_variables[1] )
    672672            $profile_group_id = 1;
    673    
     673
    674674        return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id]
    675675    }
     
    680680    function bp_get_avatar_delete_link() {
    681681        global $bp;
    682        
     682
    683683        return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( $bp->displayed_user->domain . $bp->profile->slug . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
    684684    }
     
    687687    if ( !bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'no_grav' => true ) ) )
    688688        return false;
    689    
     689
    690690    return true;
    691691}
     
    693693function bp_edit_profile_button() {
    694694    global $bp;
    695    
     695
    696696    ?>
    697697    <div class="generic-button">
Note: See TracChangeset for help on using the changeset viewer.