Changeset 1749 for trunk/bp-xprofile/deprecated/bp-xprofile-deprecated.php
- Timestamp:
- 09/01/2009 01:45:37 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/deprecated/bp-xprofile-deprecated.php
r1726 r1749 409 409 } 410 410 411 411 /*** DEPRECATED SIGNUP FUNCTIONS *******/ 412 413 function xprofile_clear_signup_cookie() { 414 /* If we are using a BuddyPress 1.1+ theme ignore this. */ 415 if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) 416 return false; 417 418 if ( !isset( $_REQUEST['action'] ) && $_POST['stage'] != 'validate-blog-signup' && $_POST['stage'] != 'validate-user-signup' ) 419 setcookie( 'bp_xprofile_meta', false, time()-1000, COOKIEPATH ); 420 } 421 add_action( 'init', 'xprofile_clear_signup_cookie' ); 422 423 function xprofile_add_signup_fields() { 424 global $bp_xprofile_callback, $avatar_error, $avatar_error_msg; 425 426 /* Fetch the fields needed for the signup form */ 427 $fields = BP_XProfile_Field::get_signup_fields(); 428 429 if ( $fields ) { 430 ?> 431 <h3><?php _e('Your Profile Details', 'buddypress'); ?></h3> 432 <p id="extra-fields-help"><?php _e('Please fill in the following fields to start up your member profile. Fields 433 marked with a star are required.', 'buddypress'); ?></p> 434 435 <div id="extra-form-fields"> 436 <?php 437 for ( $i = 0; $i < count($fields); $i++ ) { 438 if ( $bp_xprofile_callback[$i]['field_id'] == $fields[$i]->id && isset($bp_xprofile_callback[$i]['error_msg']) ) { 439 $css_class = ' class="error"'; 440 } else { 441 $css_class = ''; 442 } 443 ?> 444 <div class="extra-field"> 445 <?php if ( $css_class != '' ) { echo '<div class="error">' . $bp_xprofile_callback[$i]['error_msg'] . '</div>'; } ?> 446 <?php echo $fields[$i]->get_edit_html($bp_xprofile_callback[$i]['value']); ?> 447 </div> 448 <?php 449 $field_ids .= $fields[$i]->id . ","; 450 } 451 ?> 452 </div> 453 <input type="hidden" name="xprofile_ids" value="<?php echo attribute_escape( $field_ids ); ?>" /> 454 <?php 455 } 456 457 if ( !(int) get_site_option( 'bp-disable-avatar-uploads' ) ) { 458 ?> 459 <div id="avatar-form-fields"> 460 <h3><?php _e('Profile Picture (Avatar)', 'buddypress'); ?></h3> 461 <p id="avatar-help-text"><?php _e('You can upload an image from your computer to use as an avatar. This avatar will appear on your profile page.', 'buddypress'); ?></p> 462 <?php 463 if ( $avatar_error ) { 464 $css_class = ' error'; 465 } else { 466 $css_class = ''; 467 } 468 ?> 469 470 <div class="avatar-field<?php echo $css_class; ?>"> 471 <?php if ( $css_class != '' ) { echo '<div class="error">' . $avatar_error_msg . '</div>'; } ?> 472 473 <label for="file"><?php _e( 'Select a file:', 'buddypress' ) ?></label> 474 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_site_option('fileupload_maxk') * 1024; ?>" /> 475 <input type="hidden" name="slick_avatars_action" value="upload" /> 476 <input type="hidden" name="action" value="slick_avatars" /> 477 <input type="file" name="file" id="file" /> 478 </div> 479 <script type="text/javascript"> 480 jQuery(document).ready( function() { 481 jQuery('form#setupform').attr( 'enctype', 'multipart/form-data' ); 482 jQuery('form#setupform').attr( 'encoding', 'multipart/form-data' ); 483 }); 484 </script> 485 </div> 486 <?php 487 } 488 } 489 add_action( 'signup_extra_fields', 'xprofile_add_signup_fields' ); 490 491 function xprofile_validate_signup_fields( $result ) { 492 global $bp_xprofile_callback, $avatar_error_msg; 493 global $canvas, $original; 494 global $current_site, $active_signup; 495 global $wp_upload_error; 496 global $bp_signup_has_errors, $bp_signup_avatar_has_errors; 497 498 if ( $_POST['stage'] != 'validate-user-signup' ) return $result; 499 500 extract($result); 501 502 if ( $bp_signup_has_errors || $bp_signup_avatar_has_errors ) 503 $errors->add( 'bp_xprofile_errors', '' ); 504 505 return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); 506 } 507 add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 ); 508 509 function xprofile_add_profile_meta( $meta ) { 510 global $bp, $bp_blog_signup_meta, $bp_user_signup_meta; 511 512 if ( $_POST['stage'] == 'validate-blog-signup' ) { 513 $bp_meta = $bp_blog_signup_meta; 514 } else if ( $_POST['stage'] == 'validate-user-signup' ) { 515 $bp_meta = $bp_user_signup_meta; 516 } else { 517 $bp_meta = $meta; 518 } 519 520 return $bp_meta; 521 } 522 add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' ); 523 524 function xprofile_load_signup_meta() { 525 global $bp_signup_has_errors, $bp_signup_avatar_has_errors; 526 global $bp_xprofile_callback, $avatar_error_msg; 527 global $canvas, $original; 528 global $current_site, $active_signup; 529 global $wp_upload_error; 530 global $bp_user_signup_meta; 531 532 if ( $_POST['stage'] != 'validate-user-signup' ) return; 533 534 $counter = 0; 535 $bp_signup_has_errors = false; 536 $prev_field_id = -1; 537 538 // Validate all sign up fields 539 $fields = BP_XProfile_Field::get_signup_fields(); 540 541 if ( $fields ) { 542 foreach ( $fields as $field ) { 543 544 $value = $_POST['field_' . $field->id]; 545 546 // Need to check if the previous field had 547 // the same ID, as to not validate individual 548 // day/month/year dropdowns individually. 549 if ( $prev_field_id != $field->id ) { 550 $field = new BP_XProfile_Field($field->id); 551 552 if ( 'datebox' == $field->type ) { 553 if ( $_POST['field_' . $field->id . '_day'] != "" && $_POST['field_' . $field->id . '_month'] != "" && $_POST['field_' . $field->id . '_year'] != "") { 554 $value = strtotime( $_POST['field_' . $field->id . '_day'] . " " . 555 $_POST['field_' . $field->id . '_month'] . " " . 556 $_POST['field_' . $field->id . '_year']); 557 } 558 } 559 560 if ( is_array($value) ) { 561 $value = serialize( $value ); 562 } 563 564 $bp_xprofile_callback[$counter] = array( 565 "field_id" => $field->id, 566 "type" => $field->type, 567 "value" => $value 568 ); 569 570 if ( $field->is_required && empty( $value ) ) { 571 $bp_xprofile_callback[$counter]["error_msg"] = sprintf( __( '%s cannot be left blank', 'buddypress' ), $field->name ); 572 $bp_signup_has_errors = true; 573 } 574 575 $counter++; 576 } 577 578 $prev_field_id = $field->id; 579 } 580 } 581 582 // validate the avatar upload if there is one. 583 $bp_signup_avatar_has_errors = false; 584 $checked_upload = false; 585 $checked_size = false; 586 $checked_type = false; 587 $original = false; 588 $canvas = false; 589 590 // Set friendly error feedback. 591 $uploadErrors = array( 592 0 => __("There is no error, the file uploaded with success", 'buddypress'), 593 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 594 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 595 3 => __("The uploaded file was only partially uploaded", 'buddypress'), 596 6 => __("Missing a temporary folder", 'buddypress') 597 ); 598 599 if ( isset($_FILES['file']) ) { 600 601 if ( 4 !== $_FILES['file']['error'] ) { 602 if ( !$checked_upload = bp_core_check_avatar_upload($_FILES) ) { 603 $bp_signup_avatar_has_errors = true; 604 $avatar_error_msg = $uploadErrors[$_FILES['file']['error']]; 605 } 606 607 if ( $checked_upload && !$checked_size = bp_core_check_avatar_size($_FILES) ) { 608 $bp_signup_avatar_has_errors = true; 609 $avatar_size = size_format(CORE_MAX_FILE_SIZE); 610 $avatar_error_msg = sprintf( __('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), $avatar_size); 611 } 612 613 if ( $checked_upload && $checked_size && !$checked_type = bp_core_check_avatar_type($_FILES) ) { 614 $bp_signup_avatar_has_errors = true; 615 $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.', 'buddypress'); 616 } 617 618 // "Handle" upload into temporary location 619 if ( $checked_upload && $checked_size && $checked_type && !$original = bp_core_handle_avatar_upload($_FILES) ) { 620 $bp_signup_avatar_has_errors = true; 621 $avatar_error_msg = sprintf( __('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error ); 622 } 623 624 if ( $checked_upload && $checked_size && $checked_type && $original && !$canvas = bp_core_resize_avatar($original) ) 625 $canvas = $original; 626 } 627 } 628 629 if ( !$bp_signup_has_errors && !$bp_signup_avatar_has_errors ) { 630 $public = (int) $_POST['blog_public']; 631 632 // put the user profile meta in a session ready to store. 633 for ( $i = 0; $i < count($bp_xprofile_callback); $i++ ) { 634 $bp_user_signup_meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value']; 635 } 636 637 $bp_user_signup_meta['xprofile_field_ids'] = $_POST['xprofile_ids']; 638 $bp_user_signup_meta['avatar_image_resized'] = $canvas; 639 $bp_user_signup_meta['avatar_image_original'] = $original; 640 641 setcookie( 'bp_xprofile_meta', serialize($bp_user_signup_meta), time()+60*60*24, COOKIEPATH ); 642 } 643 } 644 add_action( 'init', 'xprofile_load_signup_meta' ); 645 646 function xprofile_load_blog_signup_meta() { 647 global $bp_blog_signup_meta; 648 649 if ( $_POST['stage'] != 'validate-blog-signup' ) return; 650 651 $blog_meta = array( 652 'public' => $_POST['blog_public'], 653 'lang_id' => 1, // deprecated 654 'blogname' => $_POST['blogname'], 655 'blog_title' => $_POST['blog_title'] 656 ); 657 658 $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) ); 659 $bp_blog_signup_meta = array_merge( $bp_meta, $blog_meta ); 660 } 661 add_action( 'init', 'xprofile_load_blog_signup_meta' ); 662 663 function xprofile_on_activate_blog( $blog_id, $user_id, $password, $title, $meta ) { 664 xprofile_extract_signup_meta( $user_id, $meta ); 665 666 if ( bp_has_custom_activation_page() ) 667 add_action( 'bp_activation_extras', 'xprofile_handle_signup_avatar', 1, 2 ); 668 else 669 xprofile_handle_signup_avatar( $user_id, $meta ); 670 } 671 add_action( 'wpmu_activate_blog', 'xprofile_on_activate_blog', 1, 5 ); 672 673 674 function xprofile_on_activate_user( $user_id, $password, $meta ) { 675 xprofile_extract_signup_meta( $user_id, $meta ); 676 677 if ( bp_has_custom_activation_page() ) 678 add_action( 'bp_activation_extras', 'xprofile_handle_signup_avatar', 1, 2 ); 679 else 680 xprofile_handle_signup_avatar( $user_id, $meta ); 681 } 682 add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 3 ); 683 684 function xprofile_extract_signup_meta( $user_id, $meta ) { 685 // Extract signup meta fields to fill out profile 686 $field_ids = $meta['xprofile_field_ids']; 687 $field_ids = explode( ',', $field_ids ); 688 689 // Loop through each bit of profile data and save it to profile. 690 for ( $i = 0; $i < count($field_ids); $i++ ) { 691 if ( empty( $field_ids[$i] ) ) continue; 692 693 $field_value = $meta["field_{$field_ids[$i]}"]; 694 695 $field = new BP_XProfile_ProfileData(); 696 $field->user_id = $user_id; 697 $field->value = $field_value; 698 $field->field_id = $field_ids[$i]; 699 $field->last_updated = time(); 700 701 $field->save(); 702 } 703 704 update_usermeta( $user_id, 'last_activity', time() ); 705 } 706 707 function xprofile_handle_signup_avatar( $user_id, $meta ) { 708 $resized = $meta['avatar_image_resized']; 709 $original = $meta['avatar_image_original']; 710 711 if ( !empty($resized) && !empty($original) ) { 712 // Create and set up the upload dir first. 713 $upload_dir = bp_core_avatar_upload_dir( false, $user_id ); 714 715 $resized_strip_path = explode( '/', $resized ); 716 $original_strip_path = explode( '/', $original ); 717 718 $resized_filename = $resized_strip_path[count($resized_strip_path) - 1]; 719 $original_filename = $original_strip_path[count($original_strip_path) - 1]; 720 721 $resized_new = $upload_dir['path'] . '/' . $resized_filename; 722 $original_new = $upload_dir['path'] . '/' . $original_filename; 723 724 @copy( $resized, $resized_new ); 725 @copy( $original, $original_new ); 726 727 @unlink($resized); 728 @unlink($original); 729 730 $resized = $resized_new; 731 $original = $original_new; 732 733 // Render the cropper UI 734 $action = bp_activation_page( false ) . '?key=' . $_GET['key'] . '&cropped=true'; 735 bp_core_render_avatar_cropper($original, $resized, $action, $user_id); 736 } 737 } 738 739 function xprofile_catch_activate_crop() { 740 if ( isset( $_GET['cropped'] ) ) { 741 // The user has cropped their avatar after activating account 742 743 // Confirm that the nonce is valid 744 if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'slick_avatars' ) ) 745 bp_core_redirect( get_option('home') ); 746 747 $user_id = xprofile_get_user_by_key($_GET['key']); 748 749 if ( $user_id && isset( $_POST['orig'] ) && isset( $_POST['canvas'] ) ) { 750 bp_core_check_crop( $_POST['orig'], $_POST['canvas'] ); 751 $result = bp_core_avatar_cropstore( $_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h'] ); 752 bp_core_avatar_save( $result, $user_id ); 753 } 754 755 $ud = get_userdata($user_id); 756 $url = site_url( BP_MEMBERS_SLUG . '/' . $ud->user_login ); 757 758 bp_core_redirect( $url ); 759 } 760 } 761 add_action( 'activate_header', 'xprofile_catch_activate_crop' ); 762 763 764 function xprofile_get_user_by_key($key) { 765 global $wpdb; 766 767 $users_table = $wpdb->base_prefix . 'users'; 768 $signup_table = $wpdb->base_prefix . 'signups'; 769 770 $sql = $wpdb->prepare("SELECT ID FROM $users_table u, $signup_table s WHERE u.user_login = s.user_login AND s.activation_key = %s", $key); 771 772 $user_id = $wpdb->get_var($sql); 773 774 return $user_id; 775 } 776 777 /*** END DEPRECATED SIGNUP FUNCTIONS *****/ 412 778 413 779 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)