Changeset 5699 for trunk/bp-xprofile/bp-xprofile-template.php
- Timestamp:
- 02/11/2012 02:14:07 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/bp-xprofile/bp-xprofile-template.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-template.php
r5697 r5699 1 1 <?php 2 /*************************************************************************** 3 * XProfile Data Display Template Tags 4 **/ 2 3 /** 4 * BuddyPress XProfile Template Tags 5 * 6 * @package BuddyPress 7 * @subpackage XProfileTemplate 8 */ 5 9 6 10 // Exit if accessed directly … … 20 24 var $in_the_loop; 21 25 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 }26 26 27 27 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 ) { … … 152 152 153 153 function bp_has_profile( $args = '' ) { 154 global $ bp, $profile_template;154 global $profile_template; 155 155 156 156 // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page, … … 411 411 global $field; 412 412 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. 413 416 $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 419 419 ); 420 420 … … 433 433 switch ( $field->type ) { 434 434 case 'selectbox': 435 if ( !$field->is_required || $null_on_required ) 435 436 if ( !$field->is_required || $null_on_required ) { 436 437 $html .= '<option value="">' . /* translators: no option picked in select box */ __( '----', 'buddypress' ) . '</option>'; 438 } 437 439 438 440 $original_option_values = ''; 439 441 $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); 440 442 441 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) 443 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) { 442 444 $original_option_values = $_POST['field_' . $field->id]; 445 } 443 446 444 447 $option_values = (array) $original_option_values; 445 448 446 449 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 450 447 451 // Check for updated posted values, but errors preventing them from being saved first time 448 452 foreach( $option_values as $i => $option_value ) { 449 453 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] ) ) { 451 455 $option_values[$i] = $_POST['field_' . $field->id]; 456 } 452 457 } 453 458 } 459 454 460 $selected = ''; 455 461 … … 458 464 459 465 // 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 ) ) { 461 467 $selected = ' selected="selected"'; 468 } 462 469 463 470 // 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 ) { 465 472 $selected = ' selected="selected"'; 473 } 466 474 467 475 $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 ); … … 473 481 $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); 474 482 475 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) 483 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) { 476 484 $original_option_values = $_POST['field_' . $field->id]; 485 } 477 486 478 487 $option_values = (array) $original_option_values; 479 488 480 489 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 490 481 491 // Check for updated posted values, but errors preventing them from being saved first time 482 492 foreach( $option_values as $i => $option_value ) { 483 493 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] ) ) { 485 495 $option_values[] = $_POST['field_' . $field->id][$i]; 496 } 486 497 } 487 498 } … … 492 503 493 504 // 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 ) ) { 495 506 $selected = ' selected="selected"'; 507 } 496 508 497 509 // 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 ) ) { 499 511 $selected = ' selected="selected"'; 512 } 500 513 501 514 $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 ); … … 508 521 509 522 for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { 523 510 524 // Check for updated posted values, but errors preventing them from being saved first time 511 525 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] ) ) { 513 527 $option_value = $_POST['field_' . $field->id]; 528 } 514 529 } 515 530 … … 517 532 // filter, so we'll be sure to get a match 518 533 $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 ) ) ) 522 538 $selected = ' checked="checked"'; 523 539 … … 549 565 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 550 566 567 // @todo $value is never created 551 568 if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) { 552 569 $selected = ' checked="checked"'; … … 557 574 // If the user has not yet supplied a value for this field, 558 575 // 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 ) ) { 560 577 $selected = ' checked="checked"'; 561 578 } … … 574 591 575 592 if ( !empty( $date ) ) { 593 576 594 // If Unix timestamp 577 595 if ( is_numeric( $date ) ) { … … 588 606 } 589 607 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. 591 610 if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) { 592 if ( $day != $_POST['field_' . $field->id . '_day'] ) 611 if ( $day != $_POST['field_' . $field->id . '_day'] ) { 593 612 $day = $_POST['field_' . $field->id . '_day']; 613 } 594 614 } 595 615 596 616 if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) { 597 if ( $month != $_POST['field_' . $field->id . '_month'] ) 617 if ( $month != $_POST['field_' . $field->id . '_month'] ) { 598 618 $month = $_POST['field_' . $field->id . '_month']; 619 } 599 620 } 600 621 601 622 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'] ) ) { 603 624 $year = $_POST['field_' . $field->id . '_year']; 604 } 605 625 } 626 } 627 628 // $type will be passed by calling function when needed 606 629 switch ( $type ) { 607 630 case 'day': … … 689 712 } 690 713 function bp_get_profile_field_data( $args = '' ) { 691 global $bp;692 714 693 715 $defaults = array( … … 765 787 766 788 function bp_profile_last_updated() { 767 global $bp;768 789 769 790 $last_updated = bp_get_profile_last_updated(); … … 776 797 } 777 798 function bp_get_profile_last_updated() { 778 global $bp;779 799 780 800 $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true ); … … 806 826 807 827 function bp_get_user_has_avatar() { 808 global $bp;809 828 810 829 if ( !bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'no_grav' => true ) ) ) … … 828 847 ) ); 829 848 } 849 830 850 ?>
Note: See TracChangeset
for help on using the changeset viewer.