Changeset 2077 for trunk/bp-xprofile/bp-xprofile-templatetags.php
- Timestamp:
- 11/02/2009 07:54:21 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-xprofile/bp-xprofile-templatetags.php (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-templatetags.php
r2066 r2077 10 10 var $groups; 11 11 var $group; 12 12 13 13 var $current_field = -1; 14 14 var $field_count; 15 15 var $field_has_data; 16 16 var $field; 17 17 18 18 var $in_the_loop; 19 19 var $user_id; 20 20 21 21 function bp_xprofile_data_template( $user_id, $profile_group_id ) { 22 22 23 23 if ( !$profile_group_id ) { 24 24 if ( !$this->groups = wp_cache_get( 'xprofile_groups', 'bp' ) ) { … … 31 31 wp_cache_set( 'xprofile_group_' . $profile_group_id, 'bp' ); 32 32 } 33 33 34 34 /* We need to put this single group into the same format as multiple group (an array) */ 35 35 $this->groups = array( $this->groups ); 36 36 } 37 37 38 38 $this->group_count = count($this->groups); 39 39 $this->user_id = $user_id; 40 40 } 41 41 42 42 function has_groups() { 43 43 if ( $this->group_count ) 44 44 return true; 45 45 46 46 return false; 47 47 } 48 48 49 49 function next_group() { 50 50 $this->current_group++; 51 51 52 52 $this->group = $this->groups[$this->current_group]; 53 53 54 54 if ( !$fields = wp_cache_get( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, 'bp' ) ) { 55 55 for ( $i = 0; $i < count($this->group->fields); $i++ ) { … … 60 60 $fields[$i] = $field; 61 61 } 62 62 63 63 wp_cache_set( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, $fields, 'bp' ); 64 64 } 65 65 66 66 $this->group->fields = apply_filters( 'xprofile_group_fields', $fields, $this->group->id ); 67 67 $this->field_count = count( $this->group->fields ); 68 68 69 69 return $this->group; 70 70 } 71 71 72 72 function rewind_groups() { 73 73 $this->current_group = -1; … … 76 76 } 77 77 } 78 79 function profile_groups() { 78 79 function profile_groups() { 80 80 if ( $this->current_group + 1 < $this->group_count ) { 81 81 return true; … … 89 89 return false; 90 90 } 91 91 92 92 function the_profile_group() { 93 93 global $group; … … 99 99 do_action('xprofile_template_loop_start'); 100 100 } 101 101 102 102 /**** FIELDS ****/ 103 103 104 104 function next_field() { 105 105 $this->current_field++; … … 108 108 return $this->field; 109 109 } 110 110 111 111 function rewind_fields() { 112 112 $this->current_field = -1; … … 114 114 $this->field = $this->group->fields[0]; 115 115 } 116 } 117 118 function has_fields() { 116 } 117 118 function has_fields() { 119 119 $has_data = false; 120 120 $just_name = true; 121 121 122 for ( $i = 0; $i < count( $this->group->fields ); $i++ ) { 122 for ( $i = 0; $i < count( $this->group->fields ); $i++ ) { 123 123 $field = &$this->group->fields[$i]; 124 124 125 125 if ( $field->data->value != null ) { 126 126 $has_data = true; 127 127 128 128 if ( 1 != $field->id ) 129 129 $just_name = false; 130 130 } 131 131 } 132 132 133 133 if ( 1 == $this->group->id && $just_name ) 134 134 return false; … … 136 136 if ( $has_data ) 137 137 return true; 138 138 139 139 return false; 140 140 } 141 141 142 142 function profile_fields() { 143 143 if ( $this->current_field + 1 < $this->field_count ) { … … 148 148 } 149 149 150 return false; 151 } 152 150 return false; 151 } 152 153 153 function the_profile_field() { 154 154 global $field; … … 169 169 } 170 170 171 function bp_has_profile( $args = '' ) { 171 function bp_has_profile( $args = '' ) { 172 172 global $bp, $profile_template; 173 173 174 174 $defaults = array( 175 175 'user_id' => $bp->displayed_user->id, … … 179 179 $r = wp_parse_args( $args, $defaults ); 180 180 extract( $r, EXTR_SKIP ); 181 181 182 182 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id ); 183 183 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), &$profile_template ); 184 184 } 185 185 186 function bp_profile_groups() { 186 function bp_profile_groups() { 187 187 global $profile_template; 188 188 return $profile_template->profile_groups(); … … 209 209 function bp_get_field_css_class( $class = false ) { 210 210 global $profile_template; 211 211 212 212 $css_classes = array(); 213 213 214 214 if ( $class ) 215 215 $css_classes[] = sanitize_title( attribute_escape( $class ) ); 216 216 217 217 /* Set a class with the field ID */ 218 218 $css_classes[] = 'field_' . $profile_template->field->id; 219 219 220 220 /* Set a class with the field name (sanitized) */ 221 221 $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 222 222 223 223 if ( $profile_template->current_field % 2 ) 224 224 $css_classes[] = 'alt'; 225 225 226 226 $css_classes = apply_filters( 'bp_field_css_classes', &$css_classes ); 227 227 … … 236 236 function bp_field_has_public_data() { 237 237 global $profile_template; 238 238 239 239 if ( $profile_template->field_has_data ) 240 240 return true; 241 241 242 242 return false; 243 243 } … … 274 274 echo apply_filters( 'bp_get_the_profile_group_description', $group->description ); 275 275 } 276 276 277 277 function bp_the_profile_group_edit_form_action() { 278 278 echo bp_get_the_profile_group_edit_form_action(); … … 280 280 function bp_get_the_profile_group_edit_form_action() { 281 281 global $bp, $group; 282 282 283 283 return apply_filters( 'bp_get_the_profile_group_edit_form_action', $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $group->id . '/' ); 284 } 284 } 285 285 286 286 function bp_the_profile_group_field_ids() { … … 292 292 foreach ( (array) $group->fields as $field ) 293 293 $field_ids .= $field->id . ','; 294 294 295 295 return substr( $field_ids, 0, -1 ); 296 296 } 297 297 298 298 function bp_profile_fields() { 299 299 global $profile_template; … … 359 359 function bp_get_the_profile_field_type() { 360 360 global $field; 361 361 362 362 return apply_filters( 'bp_the_profile_field_type', $field->type ); 363 363 } … … 368 368 function bp_get_the_profile_field_description() { 369 369 global $field; 370 370 371 371 return apply_filters( 'bp_get_the_profile_field_description', $field->description ); 372 372 } 373 373 374 374 function bp_the_profile_field_input_name() { 375 375 echo bp_get_the_profile_field_input_name(); … … 377 377 function bp_get_the_profile_field_input_name() { 378 378 global $field; 379 379 380 380 return apply_filters( 'bp_get_the_profile_field_input_name', 'field_' . $field->id ); 381 381 } … … 386 386 function bp_get_the_profile_field_options( $args = '' ) { 387 387 global $field; 388 388 389 389 $defaults = array( 390 390 'type' => false … … 393 393 $r = wp_parse_args( $args, $defaults ); 394 394 extract( $r, EXTR_SKIP ); 395 395 396 396 $options = $field->get_children(); 397 397 398 398 switch ( $field->type ) { 399 399 400 400 case 'selectbox': case 'multiselectbox': 401 401 if ( 'multiselectbox' != $field->type ) 402 402 $html .= '<option value="">--------</option>'; 403 403 404 404 for ( $k = 0; $k < count($options); $k++ ) { 405 405 $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id); 406 406 407 407 /* Check for updated posted values, but errors preventing them from being saved first time */ 408 408 if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) { … … 410 410 $option_value = $_POST['field_' . $field->id]; 411 411 } 412 412 413 413 if ( $option_value == $options[$k]->name || $options[$k]->is_default_option ) { 414 414 $selected = ' selected="selected"'; … … 420 420 } 421 421 break; 422 422 423 423 case 'radio': 424 424 $html = '<div id="field_' . $field->id . '">'; 425 426 for ( $k = 0; $k < count($options); $k++ ) { 425 426 for ( $k = 0; $k < count($options); $k++ ) { 427 427 $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id); 428 428 … … 432 432 $option_value = $_POST['field_' . $field->id]; 433 433 } 434 434 435 435 if ( $option_value == $options[$k]->name || $value == $options[$k]->name || $options[$k]->is_default_option ) { 436 436 $selected = ' checked="checked"'; … … 438 438 $selected = ''; 439 439 } 440 440 441 441 $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] ); 442 442 } 443 443 444 444 $html .= '</div>'; 445 445 break; 446 446 447 447 case 'checkbox': 448 448 $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id); 449 449 450 450 /* Check for updated posted values, but errors preventing them from being saved first time */ 451 451 if ( isset( $_POST['field_' . $field->id] ) && $option_values != maybe_serialize( $_POST['field_' . $field->id] ) ) { … … 453 453 $option_values = $_POST['field_' . $field->id]; 454 454 } 455 455 456 456 $option_values = maybe_unserialize($option_values); 457 457 458 for ( $k = 0; $k < count($options); $k++ ) { 458 for ( $k = 0; $k < count($options); $k++ ) { 459 459 for ( $j = 0; $j < count($option_values); $j++ ) { 460 460 if ( $option_values[$j] == $options[$k]->name || @in_array( $options[$k]->name, $value ) || $options[$k]->is_default_option ) { … … 463 463 } 464 464 } 465 465 466 466 $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] ); 467 467 $selected = ''; 468 468 } 469 469 break; 470 470 471 471 case 'datebox': 472 472 … … 477 477 $default_select = ' selected="selected"'; 478 478 } 479 479 480 480 /* Check for updated posted values, but errors preventing them from being saved first time */ 481 481 if ( isset( $_POST['field_' . $field->id . '_day'] ) && $day != $_POST['field_' . $field->id . '_day'] ) { … … 483 483 $day = $_POST['field_' . $field->id . '_day']; 484 484 } 485 485 486 486 if ( isset( $_POST['field_' . $field->id . '_month'] ) && $month != $_POST['field_' . $field->id . '_month'] ) { 487 487 if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) 488 488 $month = $_POST['field_' . $field->id . '_month']; 489 489 } 490 490 491 491 if ( isset( $_POST['field_' . $field->id . '_year'] ) && $year != date("j", $_POST['field_' . $field->id . '_year'] ) ) { 492 492 if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) 493 493 $year = $_POST['field_' . $field->id . '_year']; 494 494 } 495 495 496 496 switch ( $type ) { 497 497 case 'day': 498 498 $html .= '<option value=""' . attribute_escape( $default_select ) . '>--</option>'; 499 499 500 500 for ( $i = 1; $i < 32; $i++ ) { 501 if ( $day == $i ) { 502 $selected = ' selected = "selected"'; 501 if ( $day == $i ) { 502 $selected = ' selected = "selected"'; 503 503 } else { 504 504 $selected = ''; … … 507 507 } 508 508 break; 509 509 510 510 case 'month': 511 511 $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' ), 514 514 __( 'April', 'buddypress' ), __( 'May', 'buddypress' ), __( 'June', 'buddypress' ), 515 515 __( 'July', 'buddypress' ), __( 'August', 'buddypress' ), __( 'September', 'buddypress' ), … … 518 518 519 519 $html .= '<option value=""' . attribute_escape( $default_select ) . '>------</option>'; 520 520 521 521 for ( $i = 0; $i < 12; $i++ ) { 522 522 if ( $month == $eng_months[$i] ) { … … 525 525 $selected = ''; 526 526 } 527 527 528 528 $html .= '<option value="' . $eng_months[$i] . '"' . $selected . '>' . $months[$i] . '</option>'; 529 529 } 530 530 break; 531 531 532 532 case 'year': 533 533 $html .= '<option value=""' . attribute_escape( $default_select ) . '>----</option>'; 534 534 535 535 for ( $i = date( 'Y', time() ); $i > 1899; $i-- ) { 536 536 if ( $year == $i ) { 537 $selected = ' selected = "selected"'; 537 $selected = ' selected = "selected"'; 538 538 } else { 539 539 $selected = ''; 540 540 } 541 541 542 542 $html .= '<option value="' . $i .'"' . $selected . '>' . $i . '</option>'; 543 543 } 544 544 break; 545 545 } 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 ); 548 548 549 549 break; 550 550 } 551 551 552 552 return $html; 553 553 } … … 558 558 function bp_get_the_profile_field_is_required() { 559 559 global $field; 560 560 561 561 return apply_filters( 'bp_get_the_profile_field_is_required', (int)$field->is_required ); 562 562 } 563 563 564 564 function bp_unserialize_profile_field( $value ) { 565 565 if ( is_serialized($value) ) { … … 568 568 return $field_value; 569 569 } 570 570 571 571 return $value; 572 572 } … … 574 574 function bp_profile_group_tabs() { 575 575 global $bp, $group_name; 576 576 577 577 if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) { 578 578 $groups = BP_XProfile_Group::get_all(); … … 582 582 if ( empty( $group_name ) ) 583 583 $group_name = bp_profile_group_name(false); 584 584 585 585 for ( $i = 0; $i < count($groups); $i++ ) { 586 586 if ( $group_name == $groups[$i]->name ) { … … 589 589 $selected = ''; 590 590 } 591 591 592 592 if ( $groups[$i]->fields ) 593 593 echo '<li' . $selected . '><a href="' . $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $groups[$i]->id . '">' . attribute_escape( $groups[$i]->name ) . '</a></li>'; 594 594 } 595 595 596 596 do_action( 'xprofile_profile_group_tabs' ); 597 597 } … … 599 599 function bp_profile_group_name( $deprecated = true ) { 600 600 global $bp; 601 601 602 602 $group_id = $bp->action_variables[1]; 603 603 604 604 if ( !is_numeric( $group_id ) ) 605 605 $group_id = 1; 606 606 607 607 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) { 608 608 $group = new BP_XProfile_Group($group_id); 609 609 wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' ); 610 610 } 611 611 612 612 if ( !$deprecated ) { 613 613 return bp_get_profile_group_name(); … … 634 634 function bp_avatar_upload_form() { 635 635 global $bp; 636 637 if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) 636 637 if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) 638 638 bp_core_avatar_admin( null, $bp->loggedin_user->domain . $bp->profile->slug . '/change-avatar/', $bp->loggedin_user->domain . $bp->profile->slug . '/delete-avatar/' ); 639 639 else … … 643 643 function bp_profile_last_updated() { 644 644 global $bp; 645 645 646 646 $last_updated = bp_get_profile_last_updated(); 647 647 … … 658 658 659 659 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 662 662 return false; 663 663 } … … 668 668 function bp_get_current_profile_group_id() { 669 669 global $bp; 670 670 671 671 if ( !$profile_group_id = $bp->action_variables[1] ) 672 672 $profile_group_id = 1; 673 673 674 674 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id] 675 675 } … … 680 680 function bp_get_avatar_delete_link() { 681 681 global $bp; 682 682 683 683 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' ) ); 684 684 } … … 687 687 if ( !bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'no_grav' => true ) ) ) 688 688 return false; 689 689 690 690 return true; 691 691 } … … 693 693 function bp_edit_profile_button() { 694 694 global $bp; 695 695 696 696 ?> 697 697 <div class="generic-button">
Note: See TracChangeset
for help on using the changeset viewer.