Changeset 5699 for trunk/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 02/11/2012 02:14:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-classes.php
r5697 r5699 1 1 <?php 2 3 /** 4 * BuddyPress XProfile Classes 5 * 6 * @package BuddyPress 7 * @subpackage XProfileClasses 8 */ 9 2 10 // Exit if accessed directly 3 11 if ( !defined( 'ABSPATH' ) ) exit; … … 11 19 var $fields; 12 20 13 function bp_xprofile_group( $id = null ) {14 $this->__construct( $id );15 }16 17 21 function __construct( $id = null ) { 18 global $bp, $wpdb; 19 20 if ( $id ) 22 if ( !empty( $id ) ) 21 23 $this->populate( $id ); 22 23 24 } 24 25 … … 46 47 do_action_ref_array( 'xprofile_group_before_save', array( $this ) ); 47 48 48 if ( $this->id)49 if ( !empty( $this->id ) ) 49 50 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id ); 50 51 else … … 56 57 do_action_ref_array( 'xprofile_group_after_save', array( $this ) ); 57 58 58 if ( $this->id)59 if ( !empty( $this->id ) ) 59 60 return $this->id; 60 61 else … … 65 66 global $wpdb, $bp; 66 67 67 if ( !$this->can_delete)68 return false; 69 70 / * Delete field group */68 if ( empty( $this->can_delete ) ) 69 return false; 70 71 // Delete field group 71 72 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) { 72 73 return false; 73 74 } else { 74 /* Remove the group's fields. */ 75 76 // Remove the group's fields. 75 77 if ( BP_XProfile_Field::delete_for_group( $this->id ) ) { 76 /* Remove profile data for the groups fields */ 78 79 // Remove profile data for the groups fields 77 80 for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) { 78 81 BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id ); … … 84 87 } 85 88 86 /** Static Functions**/89 /** Static Methods ********************************************************/ 87 90 88 91 /** … … 126 129 $where_sql = ''; 127 130 128 if ( $profile_group_id)131 if ( !empty( $profile_group_id ) ) 129 132 $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id ); 130 133 elseif ( $exclude_groups ) 131 134 $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})"); 132 135 133 if ( $hide_empty_groups)136 if ( !empty( $hide_empty_groups ) ) 134 137 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" ) ); 135 138 else 136 139 $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) ); 137 140 138 if ( !$fetch_fields)141 if ( empty( $fetch_fields ) ) 139 142 return $groups; 140 143 … … 151 154 152 155 $exclude_fields_sql = ''; 153 if ( $exclude_fields)156 if ( !empty( $exclude_fields ) ) 154 157 $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" ); 155 158 … … 160 163 return $groups; 161 164 162 if ( $fetch_field_data ) { 165 if ( !empty( $fetch_field_data ) ) { 166 163 167 // Fetch the field data for the user. 164 foreach( (array) $fields as $field )168 foreach( (array) $fields as $field ) { 165 169 $field_ids[] = $field->id; 170 } 166 171 167 172 $field_ids_sql = implode( ',', (array) $field_ids ); … … 171 176 172 177 // Remove data-less fields, if necessary 173 if ( $hide_empty_fields) {178 if ( !empty( $hide_empty_fields ) ) { 174 179 175 180 // Loop through the results and find the fields that have data. 176 181 foreach( (array)$field_data as $data ) { 182 177 183 // Empty fields may contain a serialized empty array 178 184 $maybe_value = maybe_unserialize( $data->value ); … … 220 226 221 227 foreach( (array) $fields as $field ) { 222 if ( $group->id == $field->group_id ) 228 if ( $group->id == $field->group_id ) { 223 229 $groups[$index]->fields[] = $field; 230 } 224 231 } 225 232 … … 265 272 global $message; 266 273 267 if ( !$this->id) {274 if ( empty( $this->id ) ) { 268 275 $title = __( 'Add New Field Group', 'buddypress' ); 269 276 $action = "admin.php?page=bp-profile-setup&mode=add_group"; … … 273 280 $action = "admin.php?page=bp-profile-setup&mode=edit_group&group_id=" . $this->id; 274 281 $button = __( 'Save Changes', 'buddypress' ); 275 } 276 ?> 282 } ?> 283 277 284 <div class="wrap"> 278 285 … … 282 289 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 283 290 284 <?php if ( $message != '' ) : 285 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?> 291 <?php if ( !empty( $message ) ) : 292 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?> 293 286 294 <div id="message" class="<?php echo $type; ?> fade"> 287 295 <p><?php echo $message; ?></p> 288 296 </div> 289 <?php endif; ?> 297 298 <?php endif; ?> 299 290 300 <div id="poststuff"> 291 301 <form action="<?php echo esc_attr( $action ); ?>" method="post"> … … 297 307 </div> 298 308 299 <?php if ( '0' != $this->can_delete ) : ?> 300 <div id="titlediv"> 301 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3> 302 <div id="titlewrap"> 303 <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 309 <?php if ( '0' != $this->can_delete ) : ?> 310 311 <div id="titlediv"> 312 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3> 313 <div id="titlewrap"> 314 <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 315 </div> 304 316 </div> 305 </div> 306 <?php endif; ?>317 318 <?php endif; ?> 307 319 308 320 <p class="submit"> … … 314 326 </div> 315 327 </div> 328 316 329 <?php 317 330 } 318 331 } 319 320 332 321 333 class BP_XProfile_Field { … … 337 349 var $message_type = 'err'; 338 350 339 function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {340 $this->__construct( $id, $user_id, $get_data );341 }342 343 351 function __construct( $id = null, $user_id = null, $get_data = true ) { 344 if ( $id)352 if ( !empty( $id ) ) 345 353 $this->populate( $id, $user_id, $get_data ); 346 354 } … … 349 357 global $wpdb, $userdata, $bp; 350 358 359 // @todo Why are we nooping the user_id ? 351 360 $user_id = 0; 352 361 if ( is_null( $user_id ) ) … … 369 378 $this->is_default_option = $field->is_default_option; 370 379 371 if ( $get_data && $user_id ) 372 $this->data = $this->get_field_data( $user_id ); 380 if ( $get_data && $user_id ) { 381 $this->data = $this->get_field_data( $user_id ); 382 } 373 383 } 374 384 } … … 380 390 // Prevent deletion by url when can_delete is false. 381 391 // Prevent deletion of option 1 since this invalidates fields with options. 382 if ( !$this->id || !$this->can_delete|| ( $this->parent_id && $this->option_order == 1 ) )392 if ( empty( $this->id ) || empty( $this->can_delete ) || ( $this->parent_id && $this->option_order == 1 ) ) 383 393 return false; 384 394 … … 396 406 global $wpdb, $bp; 397 407 398 $error = false;399 400 408 $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id ); 401 409 $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id ); 402 $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id );403 $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id );410 $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id ); 411 $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id ); 404 412 $this->description = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id ); 405 413 $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id ); … … 409 417 do_action_ref_array( 'xprofile_field_before_save', array( $this ) ); 410 418 411 if ( $this->id != null ) 419 if ( $this->id != null ) { 412 420 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id ); 413 else421 } else { 414 422 $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order ); 415 416 /* 423 } 424 425 /** 417 426 * Check for null so field options can be changed without changing any other part of the field. 418 427 * The described situation will return 0 here. 419 428 */ 420 429 if ( $wpdb->query( $sql ) !== null ) { 421 if ( $this->id ) 430 431 if ( !empty( $this->id ) ) { 422 432 $field_id = $this->id; 423 else433 } else { 424 434 $field_id = $wpdb->insert_id; 425 426 /* Only do this if we are editing an existing field */ 435 } 436 437 // Only do this if we are editing an existing field 427 438 if ( $this->id != null ) { 428 /* 439 440 /** 429 441 * Remove any radio or dropdown options for this 430 442 * field. They will be re-added if needed. … … 435 447 } 436 448 437 /* 449 /** 438 450 * Check to see if this is a field with child options. 439 451 * We need to add the options to the db, if it is. 440 452 */ 441 453 if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) { 442 if ( $this->id ) 454 455 if ( !empty( $this->id ) ) { 443 456 $parent_id = $this->id; 444 else457 } else { 445 458 $parent_id = $wpdb->insert_id; 459 } 446 460 447 461 if ( 'radio' == $this->type ) { … … 452 466 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'radio' ); 453 467 454 } else 468 } elseif ( 'selectbox' == $this->type ) { 455 469 $post_option = !empty( $_POST['selectbox_option'] ) ? $_POST['selectbox_option'] : ''; 456 470 $post_default = !empty( $_POST['isDefault_selectbox_option'] ) ? $_POST['isDefault_selectbox_option'] : ''; … … 459 473 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'selectbox' ); 460 474 461 } else 475 } elseif ( 'multiselectbox' == $this->type ) { 462 476 $post_option = !empty( $_POST['multiselectbox_option'] ) ? $_POST['multiselectbox_option'] : ''; 463 477 $post_default = !empty( $_POST['isDefault_multiselectbox_option'] ) ? $_POST['isDefault_multiselectbox_option'] : ''; … … 466 480 $defaults = apply_filters( 'xprofile_field_default_before_save', $post_default, 'multiselectbox' ); 467 481 468 } else 482 } elseif ( 'checkbox' == $this->type ) { 469 483 $post_option = !empty( $_POST['checkbox_option'] ) ? $_POST['checkbox_option'] : ''; 470 484 $post_default = !empty( $_POST['isDefault_checkbox_option'] ) ? $_POST['isDefault_checkbox_option'] : ''; … … 475 489 476 490 $counter = 1; 477 if ( $options) {491 if ( !empty( $options ) ) { 478 492 foreach ( (array)$options as $option_key => $option_value ) { 479 493 $is_default = 0; … … 488 502 489 503 if ( '' != $option_value ) { 490 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) ) 504 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) ) { 491 505 return false; 506 } 492 507 } 493 508 … … 513 528 514 529 // This is done here so we don't have problems with sql injection 515 if ( 'asc' == $this->order_by && !$for_editing )530 if ( 'asc' == $this->order_by && empty( $for_editing ) ) { 516 531 $sort_sql = 'ORDER BY name ASC'; 517 else if ( 'desc' == $this->order_by && !$for_editing )532 } elseif ( 'desc' == $this->order_by && empty( $for_editing ) ) { 518 533 $sort_sql = 'ORDER BY name DESC'; 519 else534 } else { 520 535 $sort_sql = 'ORDER BY option_order ASC'; 536 } 521 537 522 538 // This eliminates a problem with getting all fields when there is no id for the object 523 if ( !$this->id )539 if ( empty( $this->id ) ) { 524 540 $parent_id = -1; 525 else541 } else { 526 542 $parent_id = $this->id; 543 } 527 544 528 545 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id ); … … 547 564 global $wpdb, $bp; 548 565 549 if ( $field_id) {566 if ( !empty( $field_id ) ) { 550 567 $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ); 551 568 552 if ( !$field_type = $wpdb->get_var( $sql ) ) 569 if ( !$field_type = $wpdb->get_var( $sql ) ) { 553 570 return false; 571 } 554 572 555 573 return $field_type; … … 562 580 global $wpdb, $bp; 563 581 564 if ( $group_id) {582 if ( !empty( $group_id ) ) { 565 583 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ); 566 584 567 if ( $wpdb->get_var( $sql ) === false ) 585 if ( $wpdb->get_var( $sql ) === false ) { 568 586 return false; 587 } 569 588 570 589 return true; … … 589 608 return false; 590 609 591 / * Update $field_id with new $position and $field_group_id */610 // Update $field_id with new $position and $field_group_id 592 611 if ( $parent = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id ) ) ) {; 593 /* Update any children of this $field_id */ 612 613 // Update any children of this $field_id 594 614 $children = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id ) ); 595 615 … … 608 628 $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' ); 609 629 610 foreach ( $input_types as $type) {630 foreach ( $input_types as $type ) { 611 631 $default_name = ''; 612 632 613 if ( 'multiselectbox' == $type || 'checkbox' == $type )633 if ( ( 'multiselectbox' == $type ) || ( 'checkbox' == $type ) ) { 614 634 $default_input = 'checkbox'; 615 else635 } else { 616 636 $default_input = 'radio'; 617 ?> 618 <div id="<?php echo $type; ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;"> 637 } 638 639 if ( $this->type != $type ) { 640 $class = 'display: none;'; 641 } 642 643 ?> 644 645 <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;"> 619 646 <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4> 620 647 <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label> … … 624 651 <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option> 625 652 </select> 626 <?php 627 if ( !$options = $this->get_children( true ) ) { 653 654 <?php if ( !$options = $this->get_children( true ) ) { 655 628 656 $i = 1; 629 657 while ( isset( $_POST[$type . '_option'][$i] ) ) { 630 658 (array) $options[] = (object) array( 631 'id' => -1, 632 'name' => $_POST[$type . '_option'][$i], 633 'is_default_option' => ( 'multiselectbox' != $type && 634 'checkbox' != $type && 635 $_POST["isDefault_{$type}_option"] == $i ) ? 636 1 : 637 $_POST["isDefault_{$type}_option"][$i] 659 'id' => -1, 660 'name' => $_POST[$type . '_option'][$i], 661 'is_default_option' => ( ( 'multiselectbox' != $type ) && ( 'checkbox' != $type ) && ( $_POST["isDefault_{$type}_option"] == $i ) ) ? 1 : $_POST["isDefault_{$type}_option"][$i] 638 662 ); 639 663 … … 647 671 648 672 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 649 $default_name = '[' . $j . ']'; 650 ?> 651 <p><?php _e( 'Option', 'buddypress'); ?> <?php echo $j; ?>:673 $default_name = '[' . $j . ']'; ?> 674 675 <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>: 652 676 <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" /> 653 677 <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?> 654 <?php 655 if ( $j != 1 && $options[$i]->id != -1 ) : ?> 656 <a href="admin.php?page=bp-profile-setup&mode=delete_option&option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a> 657 <?php endif; ?> 678 679 <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?> 680 681 <a href="admin.php?page=bp-profile-setup&mode=delete_option&option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a> 682 683 <?php endif; ?> 684 658 685 </p> 659 <?php } /* end for */ ?> 686 687 <?php } /* end for */ ?> 660 688 661 689 <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="<?php echo $j + 1; ?>" /> 662 <?php 663 } else { 690 691 <?php } else { 692 664 693 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 665 $default_name = '[1]'; 666 ?> 694 $default_name = '[1]'; ?> 667 695 668 696 <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" /> … … 670 698 <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" /> 671 699 672 <?php} /* end if */ ?>700 <?php } /* end if */ ?> 673 701 674 702 <div id="<?php echo $type; ?>_more"></div> … … 680 708 681 709 function render_admin_form( $message = '' ) { 682 if ( !$this->id) {710 if ( empty( $this->id ) ) { 683 711 $title = __( 'Add Field', 'buddypress' ); 684 712 $action = "admin.php?page=bp-profile-setup&group_id=" . $this->group_id . "&mode=add_field#tabs-" . $this->group_id; 685 713 686 714 if ( !empty( $_POST['saveField'] ) ) { 687 $this->name = $_POST['title']; 688 $this->description = $_POST['description']; 689 $this->is_required = $_POST['required']; 690 $this->type = $_POST['fieldtype']; 691 $this->order_by = $_POST["sort_order_{$this->type}"]; 692 $this->field_order = $_POST['field_order']; 693 } 694 } else { 695 $title = __( 'Edit Field', 'buddypress' ); 696 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id . "#tabs-" . $this->group_id; 697 } 698 ?> 699 <div class="wrap"> 700 <div id="icon-users" class="icon32"><br /></div> 701 <h2><?php echo $title; ?></h2> 702 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 703 704 <?php 705 if ( $message != '' ) { 706 ?> 707 <div id="message" class="error fade"> 708 <p><?php echo $message; ?></p> 709 </div> 710 <?php } ?> 711 712 <form action="<?php echo $action; ?>" method="post"> 713 <div id="poststuff"> 714 <div id="titlediv"> 715 <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3> 716 <div id="titlewrap"> 717 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" /> 715 $this->name = $_POST['title']; 716 $this->description = $_POST['description']; 717 $this->is_required = $_POST['required']; 718 $this->type = $_POST['fieldtype']; 719 $this->order_by = $_POST["sort_order_{$this->type}"]; 720 $this->field_order = $_POST['field_order']; 721 } 722 } else { 723 $title = __( 'Edit Field', 'buddypress' ); 724 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id . "#tabs-" . $this->group_id; 725 } ?> 726 727 <div class="wrap"> 728 <div id="icon-users" class="icon32"><br /></div> 729 <h2><?php echo $title; ?></h2> 730 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p> 731 732 <?php if ( !empty( $message ) ) : ?> 733 734 <div id="message" class="error fade"> 735 <p><?php echo $message; ?></p> 736 </div> 737 738 <?php endif; ?> 739 740 <form action="<?php echo $action; ?>" method="post"> 741 <div id="poststuff"> 742 <div id="titlediv"> 743 <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3> 744 <div id="titlewrap"> 745 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" /> 746 </div> 718 747 </div> 748 749 <div id="titlediv"> 750 <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3> 751 <div id="titlewrap"> 752 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 753 </div> 754 </div> 755 756 <?php if ( '0' != $this->can_delete ) { ?> 757 758 <div id="titlediv"> 759 <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3> 760 <select name="required" id="required" style="width: 30%"> 761 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option> 762 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option> 763 </select> 764 </div> 765 766 <div id="titlediv"> 767 <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3> 768 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%"> 769 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option> 770 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option> 771 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option> 772 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option> 773 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option> 774 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option> 775 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option> 776 </select> 777 </div> 778 779 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?> 780 781 <?php $this->render_admin_form_children(); ?> 782 783 <?php } else { ?> 784 785 <input type="hidden" name="required" id="required" value="1" /> 786 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" /> 787 788 <?php } ?> 789 790 <p class="submit"> 791 <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" /> 792 <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" /> 793 <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a> 794 </p> 795 719 796 </div> 720 797 721 <div id="titlediv"> 722 <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3> 723 <div id="titlewrap"> 724 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea> 725 </div> 726 </div> 727 728 <?php 729 if ( '0' != $this->can_delete ) { 730 ?> 731 <div id="titlediv"> 732 <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3> 733 <select name="required" id="required" style="width: 30%"> 734 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option> 735 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option> 736 </select> 737 </div> 738 739 <div id="titlediv"> 740 <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3> 741 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%"> 742 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option> 743 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option> 744 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option> 745 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option> 746 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option> 747 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option> 748 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option> 749 </select> 750 </div> 751 752 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?> 753 754 <?php $this->render_admin_form_children(); ?> 755 <?php } else { ?> 756 <input type="hidden" name="required" id="required" value="1" /> 757 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" /> 758 <?php } ?> 759 <p class="submit"> 760 <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" /> 761 <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" /> 762 <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a> 763 </p> 764 765 </div> 766 767 <?php wp_nonce_field( 'xprofile_delete_option' ); ?> 768 769 </form> 770 </div> 798 <?php wp_nonce_field( 'xprofile_delete_option' ); ?> 799 800 </form> 801 </div> 771 802 772 803 <?php … … 776 807 global $message; 777 808 778 / * Validate Form */809 // Validate Form 779 810 if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) { 780 811 $message = __( 'Please make sure you fill out all required fields.', 'buddypress' ); … … 806 837 var $last_updated; 807 838 808 function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {809 $this->__construct( $field_id, $user_id );810 }811 812 839 function __construct( $field_id = null, $user_id = null ) { 813 if ( $field_id)840 if ( !empty( $field_id ) ) 814 841 $this->populate( $field_id, $user_id ); 815 842 } … … 923 950 $profile_data = array(); 924 951 925 if ( $results) {952 if ( !empty( $results ) ) { 926 953 $profile_data['user_login'] = $results[0]->user_login; 927 954 $profile_data['user_nicename'] = $results[0]->user_nicename; … … 945 972 global $wpdb, $bp; 946 973 947 if ( !$user_ids)974 if ( empty( $user_ids ) ) 948 975 $user_ids = bp_displayed_user_id(); 949 976 … … 961 988 global $bp, $wpdb; 962 989 963 if ( !$fields)964 return false; 965 966 if ( !$user_id)990 if ( empty( $fields ) ) 991 return false; 992 993 if ( empty( $user_id ) ) 967 994 $user_id = bp_displayed_user_id(); 968 995 … … 1006 1033 1007 1034 function delete_for_field( $field_id ) { 1008 global $wpdb, $ userdata, $bp;1035 global $wpdb, $bp; 1009 1036 1010 1037 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) ) … … 1031 1058 global $wpdb, $bp; 1032 1059 1033 if ( $exclude_fullname)1060 if ( !empty( $exclude_fullname ) ) 1034 1061 $exclude_sql = $wpdb->prepare( " AND pf.id != 1" ); 1035 1062 … … 1038 1065 1039 1066 function get_fullname( $user_id = 0 ) { 1040 global $bp; 1041 1042 if ( !$user_id ) 1067 1068 if ( empty( $user_id ) ) 1043 1069 $user_id = bp_displayed_user_id(); 1044 1070
Note: See TracChangeset
for help on using the changeset viewer.