Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/11/2012 02:14:07 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in XProfile component. See #3989.

File:
1 edited

Legend:

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

    r5697 r5699  
    11<?php
    2 /***************************************************************************
    3  * XProfile Data Display Template Tags
    4  **/
     2
     3/**
     4 * BuddyPress XProfile Template Tags
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileTemplate
     8 */
    59
    610// Exit if accessed directly
     
    2024    var $in_the_loop;
    2125    var $user_id;
    22 
    23     function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
    24         $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
    25     }
    2626
    2727    function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
     
    152152
    153153function bp_has_profile( $args = '' ) {
    154     global $bp, $profile_template;
     154    global $profile_template;
    155155
    156156    // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page,
     
    411411        global $field;
    412412
     413        // Generally a required dropdown field will not get a blank value at
     414        // the top. Set 'null_on_required' to true if you want this blank value
     415        // even on required fields.
    413416        $defaults = array(
    414             'type'         => false,
    415             'null_on_required' => false // Generally, a required dropdown field will not
    416                             // get a blank value at the top. Set to true if
    417                             // you want this blank value even on
    418                             // required fields
     417            'type'             => false,
     418            'null_on_required' => false
    419419        );
    420420
     
    433433        switch ( $field->type ) {
    434434            case 'selectbox':
    435                 if ( !$field->is_required || $null_on_required )
     435
     436                if ( !$field->is_required || $null_on_required ) {
    436437                    $html .= '<option value="">' . /* translators: no option picked in select box */ __( '----', 'buddypress' ) . '</option>';
     438                }
    437439
    438440                $original_option_values = '';
    439441                $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
    440442
    441                 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) )
     443                if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) {
    442444                    $original_option_values = $_POST['field_' . $field->id];
     445                }
    443446
    444447                $option_values = (array) $original_option_values;
    445448
    446449                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     450
    447451                    // Check for updated posted values, but errors preventing them from being saved first time
    448452                    foreach( $option_values as $i => $option_value ) {
    449453                        if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
    450                             if ( !empty( $_POST['field_' . $field->id] ) )
     454                            if ( !empty( $_POST['field_' . $field->id] ) ) {
    451455                                $option_values[$i] = $_POST['field_' . $field->id];
     456                            }
    452457                        }
    453458                    }
     459
    454460                    $selected = '';
    455461
     
    458464
    459465                    // First, check to see whether the user-entered value matches
    460                     if ( in_array( $allowed_options, (array) $option_values ) )
     466                    if ( in_array( $allowed_options, (array) $option_values ) ) {
    461467                        $selected = ' selected="selected"';
     468                    }
    462469
    463470                    // Then, if the user has not provided a value, check for defaults
    464                     if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
     471                    if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) {
    465472                        $selected = ' selected="selected"';
     473                    }
    466474
    467475                    $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], $field->id, $selected, $k );
     
    473481                $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
    474482
    475                 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) )
     483                if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) {
    476484                    $original_option_values = $_POST['field_' . $field->id];
     485                }
    477486
    478487                $option_values = (array) $original_option_values;
    479488
    480489                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     490
    481491                    // Check for updated posted values, but errors preventing them from being saved first time
    482492                    foreach( $option_values as $i => $option_value ) {
    483493                        if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id][$i] != $option_value ) {
    484                             if ( !empty( $_POST['field_' . $field->id][$i] ) )
     494                            if ( !empty( $_POST['field_' . $field->id][$i] ) ) {
    485495                                $option_values[] = $_POST['field_' . $field->id][$i];
     496                            }
    486497                        }
    487498                    }
     
    492503
    493504                    // First, check to see whether the user-entered value matches
    494                     if ( in_array( $allowed_options, (array) $option_values ) )
     505                    if ( in_array( $allowed_options, (array) $option_values ) ) {
    495506                        $selected = ' selected="selected"';
     507                    }
    496508
    497509                    // Then, if the user has not provided a value, check for defaults
    498                     if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
     510                    if ( !is_array( $original_option_values ) && empty( $option_values ) && !empty( $options[$k]->is_default_option ) ) {
    499511                        $selected = ' selected="selected"';
     512                    }
    500513
    501514                    $html .= apply_filters( 'bp_get_the_profile_field_options_multiselect', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $field->id, $selected, $k );
     
    508521
    509522                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     523
    510524                    // Check for updated posted values, but errors preventing them from being saved first time
    511525                    if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
    512                         if ( !empty( $_POST['field_' . $field->id] ) )
     526                        if ( !empty( $_POST['field_' . $field->id] ) ) {
    513527                            $option_value = $_POST['field_' . $field->id];
     528                        }
    514529                    }
    515530
     
    517532                    // filter, so we'll be sure to get a match
    518533                    $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    519 
    520                     $selected = '';
    521                     if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && $options[$k]->is_default_option ) )
     534                    $selected        = '';
     535
     536                    // @todo $value is never created
     537                    if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && !empty( $options[$k]->is_default_option ) ) )
    522538                        $selected = ' checked="checked"';
    523539
     
    549565                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    550566
     567                        // @todo $value is never created
    551568                        if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) {
    552569                            $selected = ' checked="checked"';
     
    557574                    // If the user has not yet supplied a value for this field,
    558575                    // check to see whether there is a default value available
    559                     if ( !is_array( $option_values ) && empty( $option_values ) && !$selected && $options[$k]->is_default_option) {
     576                    if ( !is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && !empty( $options[$k]->is_default_option ) ) {
    560577                        $selected = ' checked="checked"';
    561578                    }
     
    574591
    575592                if ( !empty( $date ) ) {
     593
    576594                    // If Unix timestamp
    577595                    if ( is_numeric( $date ) ) {
     
    588606                }
    589607
    590                 // Check for updated posted values, but errors preventing them from being saved first time
     608                // Check for updated posted values, and errors preventing
     609                // them from being saved first time.
    591610                if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) {
    592                     if ( $day != $_POST['field_' . $field->id . '_day'] )
     611                    if ( $day != $_POST['field_' . $field->id . '_day'] ) {
    593612                        $day = $_POST['field_' . $field->id . '_day'];
     613                    }
    594614                }
    595615
    596616                if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) {
    597                     if ( $month != $_POST['field_' . $field->id . '_month'] )
     617                    if ( $month != $_POST['field_' . $field->id . '_month'] ) {
    598618                        $month = $_POST['field_' . $field->id . '_month'];
     619                    }
    599620                }
    600621
    601622                if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) {
    602                     if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) )
     623                    if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) ) {
    603624                        $year = $_POST['field_' . $field->id . '_year'];
    604                 }
    605 
     625                    }
     626                }
     627
     628                // $type will be passed by calling function when needed
    606629                switch ( $type ) {
    607630                    case 'day':
     
    689712}
    690713    function bp_get_profile_field_data( $args = '' ) {
    691         global $bp;
    692714
    693715        $defaults = array(
     
    765787
    766788function bp_profile_last_updated() {
    767     global $bp;
    768789
    769790    $last_updated = bp_get_profile_last_updated();
     
    776797}
    777798    function bp_get_profile_last_updated() {
    778         global $bp;
    779799
    780800        $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true );
     
    806826
    807827function bp_get_user_has_avatar() {
    808     global $bp;
    809828
    810829    if ( !bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'no_grav' => true ) ) )
     
    828847    ) );
    829848}
     849
    830850?>
Note: See TracChangeset for help on using the changeset viewer.