Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/03/2009 10:49:34 PM (16 years ago)
Author:
apeatling
Message:

Removed the use of sessions in BuddyPress, as this is not a robust solution when installed on a multi-server setup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-signup.php

    r1473 r1503  
    8686
    8787function xprofile_validate_signup_fields( $result ) {
    88     global $bp_xprofile_callback, $avatar_error, $avatar_error_msg, $has_errors;
     88    global $bp_xprofile_callback, $avatar_error_msg;
    8989    global $canvas, $original;
    9090    global $current_site, $active_signup;
    9191    global $wp_upload_error;
     92    global $bp_signup_has_errors, $bp_signup_avatar_has_errors;
    9293   
    9394    if ( $_POST['stage'] != 'validate-user-signup' ) return $result;
    9495   
    95     // form has been submitted, let's validate the form
    96     // using the built in Wordpress functions and our own.
    97 
    9896    extract($result);
    9997   
     98    if ( $bp_signup_has_errors || $bp_signup_avatar_has_errors )
     99        $errors->add( 'bp_xprofile_errors', '' );
     100       
     101    return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
     102}
     103add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 );
     104
     105function xprofile_add_profile_meta( $meta ) {
     106    global $bp, $bp_blog_signup_meta;
     107   
     108    if ( $_POST['stage'] == 'validate-blog-signup' ) {
     109        $bp_meta = $bp_blog_signup_meta;
     110    } else if ( $_POST['stage'] == 'validate-user-signup' ) {
     111        $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) );
     112    } else {
     113        $bp_meta = $meta;
     114    }
     115
     116    return $bp_meta;
     117}
     118add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' );
     119
     120function xprofile_load_signup_meta() {
     121    global $bp_signup_has_errors, $bp_signup_avatar_has_errors;
     122    global $bp_xprofile_callback, $avatar_error_msg;
     123    global $canvas, $original;
     124    global $current_site, $active_signup;
     125    global $wp_upload_error;
     126
     127    if ( $_POST['stage'] != 'validate-user-signup' ) return;
     128   
    100129    $counter = 0;
    101     $has_errors = false;
     130    $bp_signup_has_errors = false;
    102131    $prev_field_id = -1;
    103132   
    104133    // Validate all sign up fields
    105134    $fields = BP_XProfile_Field::get_signup_fields();
    106    
     135
    107136    if ( $fields ) {
    108137        foreach ( $fields as $field ) {
    109138       
    110139            $value = $_POST['field_' . $field->id];
    111        
     140
    112141            // Need to check if the previous field had
    113142            // the same ID, as to not validate individual
     
    133162                    "value" => $value
    134163                );
    135            
     164
    136165                if ( $field->is_required && empty( $value ) ) {
    137166                    $bp_xprofile_callback[$counter]["error_msg"] = sprintf( __( '%s cannot be left blank', 'buddypress' ), $field->name );
    138                     $has_errors = true;
     167                    $bp_signup_has_errors = true;
    139168                }
    140169           
     
    167196        if ( 4 !== $_FILES['file']['error'] ) {
    168197            if ( !$checked_upload = bp_core_check_avatar_upload($_FILES) ) {
    169                 $avatar_error = true;
     198                $bp_signup_avatar_has_errors = true;
    170199                $avatar_error_msg = $uploadErrors[$_FILES['file']['error']];
    171200            }
    172201
    173202            if ( $checked_upload && !$checked_size = bp_core_check_avatar_size($_FILES) ) {
    174                 $avatar_error = true;
     203                $bp_signup_avatar_has_errors = true;
    175204                $avatar_size = size_format(CORE_MAX_FILE_SIZE);
    176205                $avatar_error_msg = sprintf( __('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), $avatar_size);
     
    178207
    179208            if ( $checked_upload && $checked_size && !$checked_type = bp_core_check_avatar_type($_FILES) ) {
    180                 $avatar_error = true;
     209                $bp_signup_avatar_has_errors = true;
    181210                $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.', 'buddypress');     
    182211            }
     
    184213            // "Handle" upload into temporary location
    185214            if ( $checked_upload && $checked_size && $checked_type && !$original = bp_core_handle_avatar_upload($_FILES) ) {
    186                 $avatar_error = true;
     215                $bp_signup_avatar_has_errors = true;
    187216                $avatar_error_msg = sprintf( __('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error );                     
    188217            }
     
    192221        }
    193222    }
    194    
    195     if ( !$has_errors && !$avatar_error ) {
     223
     224    if ( !$bp_signup_has_errors && !$bp_signup_avatar_has_errors ) {
     225        /* Destroy and existing cookies */
     226        setcookie( 'bp_xprofile_meta', false, time()-1000, COOKIEPATH );
     227       
    196228        $public = (int) $_POST['blog_public'];
    197229       
    198230        // put the user profile meta in a session ready to store.
    199231        for ( $i = 0; $i < count($bp_xprofile_callback); $i++ ) {
    200             $meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value'];
    201         }
    202 
    203         $meta['xprofile_field_ids'] = $_POST['xprofile_ids'];
    204         $meta['avatar_image_resized'] = $canvas;
    205         $meta['avatar_image_original'] = $original;
    206 
    207         $_SESSION['xprofile_meta'] = $meta;
    208     } else {
    209         $errors->add( 'bp_xprofile_errors', '' );
    210     }
    211    
    212     return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
    213 }
    214 add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 );
    215 
    216 
    217 function xprofile_add_blog_signup_meta( $meta ) {
    218     $_SESSION['xprofile_meta']['public'] = (int) $_POST['blog_public'];
    219     $_SESSION['xprofile_meta']['lang_id'] = 1; // deprecated
    220     $_SESSION['xprofile_meta']['blogname'] = $_POST['blogname'];
    221     $_SESSION['xprofile_meta']['blog_title'] = $_POST['blog_title'];
    222 
    223     return $meta;
    224 }
    225 
    226 add_filter( 'wpmu_validate_blog_signup', 'xprofile_add_blog_signup_meta' );
    227 
    228 
    229 function xprofile_add_profile_meta( $meta ) {
    230     global $bp;
    231    
    232     if ( $bp->current_component != $bp->blogs->slug )
    233         return $_SESSION['xprofile_meta'];
    234     else
    235         return $meta;
    236 }
    237 add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' );
     232            $bp_meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value'];
     233        }
     234
     235        $bp_meta['xprofile_field_ids'] = $_POST['xprofile_ids'];
     236        $bp_meta['avatar_image_resized'] = $canvas;
     237        $bp_meta['avatar_image_original'] = $original;
     238       
     239        setcookie( 'bp_xprofile_meta', serialize($bp_meta), time()+60*60*24, COOKIEPATH );
     240    }
     241}
     242add_action( 'init', 'xprofile_load_signup_meta' );
     243
     244function xprofile_load_blog_signup_meta() {
     245    global $bp_blog_signup_meta;
     246   
     247    if ( $_POST['stage'] != 'validate-blog-signup' ) return;
     248
     249    $blog_meta = array(
     250        'public' => $_POST['blog_public'],
     251        'lang_id' => 1, // deprecated
     252        'blogname' => $_POST['blogname'],
     253        'blog_title' => $_POST['blog_title']
     254    );
     255   
     256    $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) );
     257    $bp_blog_signup_meta = array_merge( $bp_meta, $blog_meta );
     258}
     259add_action( 'init', 'xprofile_load_blog_signup_meta' );
    238260
    239261/**************************************************************************
     
    265287add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 3 );
    266288
    267 
    268289function xprofile_extract_signup_meta( $user_id, $meta ) {
    269290    // Extract signup meta fields to fill out profile
Note: See TracChangeset for help on using the changeset viewer.