Changeset 3300 for trunk/bp-xprofile/bp-xprofile-templatetags.php
- Timestamp:
- 10/24/2010 09:22:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-templatetags.php
r3232 r3300 21 21 function bp_xprofile_data_template( $user_id, $profile_group_id ) { 22 22 $this->groups = BP_XProfile_Group::get( array( 23 'profile_group_id' 24 'user_id' 25 'hide_empty_groups' 26 'fetch_fields' 27 'fetch_field_data' 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 28 28 ) ); 29 29 30 $this->group_count = count( $this->groups);30 $this->group_count = count($this->groups); 31 31 $this->user_id = $user_id; 32 32 } … … 51 51 function rewind_groups() { 52 52 $this->current_group = -1; 53 54 if ( $this->group_count > 0 ) 53 if ( $this->group_count > 0 ) { 55 54 $this->group = $this->groups[0]; 55 } 56 56 } 57 57 … … 60 60 return true; 61 61 } elseif ( $this->current_group + 1 == $this->group_count ) { 62 do_action( 'xprofile_template_loop_end');63 / * Do some cleaning up after the loop */62 do_action('xprofile_template_loop_end'); 63 // Do some cleaning up after the loop 64 64 $this->rewind_groups(); 65 65 } … … 75 75 $group = $this->next_group(); 76 76 77 if ( 0 == $this->current_group ) / * loop has just started */78 do_action( 'xprofile_template_loop_start');77 if ( 0 == $this->current_group ) // loop has just started 78 do_action('xprofile_template_loop_start'); 79 79 } 80 80 … … 90 90 function rewind_fields() { 91 91 $this->current_field = -1; 92 93 if ( $this->field_count > 0 ) 92 if ( $this->field_count > 0 ) { 94 93 $this->field = $this->group->fields[0]; 94 } 95 95 } 96 96 … … 101 101 $field = &$this->group->fields[$i]; 102 102 103 if ( $field->data->value != null ) 103 if ( $field->data->value != null ) { 104 104 $has_data = true; 105 } 105 106 } 106 107 … … 112 113 113 114 function profile_fields() { 114 if ( $this->current_field + 1 < $this->field_count ) 115 if ( $this->current_field + 1 < $this->field_count ) { 115 116 return true; 116 117 /* Do some cleaning up after the loop */ 118 elseif ( $this->current_field + 1 == $this->field_count ) 117 } elseif ( $this->current_field + 1 == $this->field_count ) { 118 // Do some cleaning up after the loop 119 119 $this->rewind_fields(); 120 } 120 121 121 122 return false; … … 127 128 $field = $this->next_field(); 128 129 129 if ( !empty( $field->data->value ) ) 130 if ( !empty( $field->data->value ) ) { 130 131 $this->field_has_data = true; 131 else 132 } 133 else { 132 134 $this->field_has_data = false; 135 } 133 136 } 134 137 } … … 177 180 178 181 if ( $class ) 179 $css_classes[] = sanitize_title( attribute_escape( $class ) );182 $css_classes[] = sanitize_title( esc_attr( $class ) ); 180 183 181 184 /* Set a class with the field ID */ … … 185 188 $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 186 189 187 if ( $profile_template->current_field % 2 )190 if ( $profile_template->current_field % 2 == 1 ) 188 191 $css_classes[] = 'alt'; 189 192 … … 254 257 global $group; 255 258 256 foreach ( (array) $group->fields as $field ) {259 foreach ( (array) $group->fields as $field ) 257 260 $field_ids .= $field->id . ','; 258 }259 261 260 262 return substr( $field_ids, 0, -1 ); … … 343 345 global $field; 344 346 345 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id ); 347 $array_box = false; 348 if ( 'multiselectbox' == $field->type ) 349 $array_box = '[]'; 350 351 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id . $array_box ); 346 352 } 347 353 … … 369 375 if ( 'multiselectbox' != $field->type ) 370 376 $html .= '<option value="">--------</option>'; 377 378 for ( $k = 0; $k < count($options); $k++ ) { 379 $option_values = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ); 380 $option_values = (array)$option_values; 381 382 /* Check for updated posted values, but errors preventing them from being saved first time */ 383 foreach( (array)$option_values as $i => $option_value ) { 384 if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) { 385 if ( !empty( $_POST['field_' . $field->id] ) ) 386 $option_values[$i] = $_POST['field_' . $field->id]; 387 } 388 } 389 390 if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option ) { 391 $selected = ' selected="selected"'; 392 } else { 393 $selected = ''; 394 } 395 396 $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( $options[$k]->name ) . '">' . esc_attr( $options[$k]->name ) . '</option>', $options[$k] ); 397 } 398 break; 399 400 case 'radio': 401 $html = '<div id="field_' . $field->id . '">'; 371 402 372 403 for ( $k = 0; $k < count($options); $k++ ) { … … 379 410 } 380 411 381 if ( in_array( $options[$k]->name, (array)$option_values ) || $options[$k]->is_default_option )382 $selected = ' selected="selected"';383 else412 if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) { 413 $selected = ' checked="checked"'; 414 } else { 384 415 $selected = ''; 385 386 $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . attribute_escape( stripslashes( $options[$k]->name ) ) . '">' . attribute_escape( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );387 }388 break;389 390 case 'radio':391 $html = '<div id="field_' . $field->id . '">';392 393 for ( $k = 0; $k < count( $options ); $k++ ) {394 $option_value = BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id );395 396 /* Check for updated posted values, but errors preventing them from being saved first time */397 if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {398 if ( !empty( $_POST['field_' . $field->id] ) )399 $option_value = $_POST['field_' . $field->id];400 416 } 401 417 402 if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) 403 $selected = ' checked="checked"'; 404 else 405 $selected = ''; 406 407 $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] ); 418 $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( $options[$k]->name ) . '"> ' . esc_attr( $options[$k]->name ) . '</label>', $options[$k] ); 408 419 } 409 420 … … 412 423 413 424 case 'checkbox': 414 $option_values = BP_XProfile_ProfileData::get_value_byid( $options[0]->parent_id);425 $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id); 415 426 416 427 /* Check for updated posted values, but errors preventing them from being saved first time */ … … 420 431 } 421 432 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++ ) {433 $option_values = maybe_unserialize($option_values); 434 435 for ( $k = 0; $k < count($options); $k++ ) { 436 for ( $j = 0; $j < count($option_values); $j++ ) { 426 437 if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) { 427 438 $selected = ' checked="checked"'; … … 430 441 } 431 442 432 $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] );443 $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( $options[$k]->name ) . '"> ' . esc_attr( $options[$k]->name ) . '</label>', $options[$k] ); 433 444 $selected = ''; 434 445 } … … 438 449 439 450 if ( !empty( $field->data->value ) ) { 440 $day 441 $month 442 $year 443 $default_select 451 $day = date("j", $field->data->value); 452 $month = date("F", $field->data->value); 453 $year = date("Y", $field->data->value); 454 $default_select = ' selected="selected"'; 444 455 } 445 456 … … 462 473 switch ( $type ) { 463 474 case 'day': 464 $html .= '<option value=""' . attribute_escape( $default_select ) . '>--</option>';475 $html .= '<option value=""' . esc_attr( $default_select ) . '>--</option>'; 465 476 466 477 for ( $i = 1; $i < 32; $i++ ) { 467 if ( $day == $i ) 478 if ( $day == $i ) { 468 479 $selected = ' selected = "selected"'; 469 else480 } else { 470 481 $selected = ''; 471 482 } 472 483 $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>'; 473 484 } … … 483 494 ); 484 495 485 $html .= '<option value=""' . attribute_escape( $default_select ) . '>------</option>';496 $html .= '<option value=""' . esc_attr( $default_select ) . '>------</option>'; 486 497 487 498 for ( $i = 0; $i < 12; $i++ ) { 488 if ( $month == $eng_months[$i] ) 499 if ( $month == $eng_months[$i] ) { 489 500 $selected = ' selected = "selected"'; 490 else501 } else { 491 502 $selected = ''; 503 } 492 504 493 505 $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>'; … … 496 508 497 509 case 'year': 498 $html .= '<option value=""' . attribute_escape( $default_select ) . '>----</option>';510 $html .= '<option value=""' . esc_attr( $default_select ) . '>----</option>'; 499 511 500 512 for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) { 501 if ( $year == $i ) 513 if ( $year == $i ) { 502 514 $selected = ' selected = "selected"'; 503 else515 } else { 504 516 $selected = ''; 517 } 505 518 506 519 $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>'; … … 523 536 global $field; 524 537 525 return apply_filters( 'bp_get_the_profile_field_is_required', (int) 538 return apply_filters( 'bp_get_the_profile_field_is_required', (int)$field->is_required ); 526 539 } 527 540 528 541 function bp_unserialize_profile_field( $value ) { 529 if ( is_serialized( $value) ) {530 $field_value = maybe_unserialize( $value);542 if ( is_serialized($value) ) { 543 $field_value = maybe_unserialize($value); 531 544 $field_value = implode( ', ', $field_value ); 532 545 return $field_value; … … 541 554 function bp_get_profile_field_data( $args = '' ) { 542 555 $defaults = array( 543 'field' => false, /* Field name or ID. */544 'user_id' 545 );556 'field' => false, // Field name or ID. 557 'user_id' => $bp->displayed_user->id 558 ); 546 559 547 560 $r = wp_parse_args( $args, $defaults ); … … 562 575 $group_name = bp_profile_group_name(false); 563 576 564 for ( $i = 0; $i < count( $groups); $i++ ) {565 if ( $group_name == $groups[$i]->name ) 577 for ( $i = 0; $i < count($groups); $i++ ) { 578 if ( $group_name == $groups[$i]->name ) { 566 579 $selected = ' class="current"'; 567 else580 } else { 568 581 $selected = ''; 582 } 569 583 570 584 if ( $groups[$i]->fields ) 571 echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . attribute_escape( $groups[$i]->name ) . '</a></li>';585 echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . esc_attr( $groups[$i]->name ) . '</a></li>'; 572 586 } 573 587 … … 584 598 585 599 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 586 $group = new BP_XProfile_Group( $group_id);600 $group = new BP_XProfile_Group($group_id); 587 601 wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); 588 602 } 589 603 590 if ( !$deprecated ) 604 if ( !$deprecated ) { 591 605 return bp_get_profile_group_name(); 592 else606 } else { 593 607 echo bp_get_profile_group_name(); 608 } 594 609 } 595 610 function bp_get_profile_group_name() { … … 602 617 603 618 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 604 $group = new BP_XProfile_Group( $group_id);619 $group = new BP_XProfile_Group($group_id); 605 620 wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); 606 621 } … … 623 638 $last_updated = bp_get_profile_last_updated(); 624 639 625 if ( !$last_updated ) 640 if ( !$last_updated ) { 626 641 _e( 'Profile not recently updated', 'buddypress' ) . '.'; 627 else642 } else { 628 643 echo $last_updated; 644 } 629 645 } 630 646 function bp_get_profile_last_updated() { 631 647 global $bp; 632 648 633 $last_updated = get_user meta( $bp->displayed_user->id, 'profile_last_updated');649 $last_updated = get_user_meta( $bp->displayed_user->id, 'profile_last_updated', true ); 634 650 635 651 if ( $last_updated ) … … 648 664 $profile_group_id = 1; 649 665 650 /* admin/profile/edit/[group-id] */ 651 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); 666 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id] 652 667 } 653 668 … … 671 686 global $bp; 672 687 688 bp_button( array ( 689 'id' => 'edit_profile', 690 'component' => 'xprofile', 691 'must_be_logged_in' => true, 692 'block_self' => true, 693 'link_href' => trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit' ), 694 'link_class' => 'edit', 695 'link_text' => __( 'Edit Profile', 'buddypress' ), 696 'link_title' => __( 'Edit Profile', 'buddypress' ), 697 ) ); 698 } 699 673 700 ?> 674 675 <div class="generic-button">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>677 </div>678 <?php679 }680 681 ?>
Note: See TracChangeset
for help on using the changeset viewer.