Skip to:
Content

BuddyPress.org

Changeset 1503


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.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r1482 r1503  
    11<?php
    2 
    32/* Define the current version number for checking if DB tables are up to date. */
    43define( 'BP_CORE_VERSION', '1.0' );
     
    171170add_action( 'plugins_loaded', 'bp_core_setup_root_components', 1 );
    172171
    173 function bp_core_setup_session() {
    174     // Start a session for error/success feedback on redirect and for signup functions.
    175     @session_start();
     172function bp_core_setup_cookies() {
     173    global $bp_message, $bp_message_type;
    176174   
    177175    // Render any error/success feedback on the template
    178     if ( $_SESSION['message'] != '' )
    179         add_action( 'template_notices', 'bp_core_render_notice' );
    180 }
    181 add_action( 'wp', 'bp_core_setup_session', 3 );
     176    if ( $_COOKIE['bp-message'] == '' || !isset( $_COOKIE['bp-message'] ) )
     177        return false;
     178
     179    $bp_message = $_COOKIE['bp-message'];
     180    $bp_message_type = $_COOKIE['bp-message-type'];
     181    add_action( 'template_notices', 'bp_core_render_notice' );
     182
     183    setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
     184    setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
     185}
     186add_action( 'wp', 'bp_core_setup_cookies', 3 );
    182187
    183188function bp_core_install() {
     
    847852    if ( !$type )
    848853        $type = 'success';
    849    
    850     $_SESSION['message'] = $message;
    851     $_SESSION['message_type'] = $type;
     854
     855    setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
     856    setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
    852857}
    853858
     
    862867 */
    863868function bp_core_render_notice() {
    864     if ( $_SESSION['message'] ) {
    865         $type = ( 'success' == $_SESSION['message_type'] ) ? 'updated' : 'error';
     869    if ( $_COOKIE['bp-message'] ) {
     870        $type = ( 'success' == $_COOKIE['bp-message-type'] ) ? 'updated' : 'error';
    866871    ?>
    867872        <div id="message" class="<?php echo $type; ?>">
    868             <p><?php echo $_SESSION['message']; ?></p>
     873            <p><?php echo $_COOKIE['bp-message']; ?></p>
    869874        </div>
    870     <?php
    871         unset( $_SESSION['message'] );
    872         unset( $_SESSION['message_type'] );
    873        
     875    <?php
    874876        do_action( 'bp_core_render_notice' );
    875877    }
  • trunk/bp-groups.php

    r1477 r1503  
    362362        $completed_to_step = 0;
    363363       
    364         unset($_SESSION['group_obj_id']);
    365         unset($_SESSION['completed_to_step']);
     364        setcookie( 'bp_group_obj_id', false, time() - 1000, COOKIEPATH );
     365        setcookie( 'bp_group_completed_to_step', false, time() - 1000, COOKIEPATH );
    366366       
    367367        $no_instantiate = true;
     
    369369    }
    370370   
    371     if ( isset($_SESSION['completed_to_step']) && !$reset_steps ) {
    372         $completed_to_step = $_SESSION['completed_to_step'];
     371    if ( isset($_COOKIE['bp_group_completed_to_step']) && !$reset_steps ) {
     372        $completed_to_step = $_COOKIE['bp_group_completed_to_step'];
    373373    }
    374374   
    375375    if ( isset( $_POST['save'] ) || isset( $_POST['skip'] ) ) {
    376         $group_obj = new BP_Groups_Group( $_SESSION['group_obj_id'] );
    377 
    378         if ( !$group_id = groups_create_group( $create_group_step, $_SESSION['group_obj_id'] ) ) {
     376        $group_obj = new BP_Groups_Group( $_COOKIE['bp_group_obj_id'] );
     377
     378        if ( !$group_id = groups_create_group( $create_group_step, $_COOKIE['bp_group_obj_id'] ) ) {
    379379            bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
    380380            bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $create_group_step );
     
    382382            $create_group_step++;
    383383            $completed_to_step++;
    384             $_SESSION['completed_to_step'] = $completed_to_step;
    385             $_SESSION['group_obj_id'] = $group_id;
     384           
     385            /* Unset cookie info */
     386            setcookie( 'bp_group_obj_id', false, time() - 1000, COOKIEPATH );
     387            setcookie( 'bp_group_completed_to_step', false, time() - 1000, COOKIEPATH );
     388           
     389            /* Reset cookie info */
     390            setcookie( 'bp_group_obj_id', $group_id, time()+60*60*24, COOKIEPATH );
     391            setcookie( 'bp_group_completed_to_step', $completed_to_step, time()+60*60*24, COOKIEPATH );
    386392        }
    387393       
     
    390396    }
    391397
    392     if ( isset($_SESSION['group_obj_id']) && !$group_obj && !$no_instantiate )
    393         $group_obj = new BP_Groups_Group( $_SESSION['group_obj_id'] );
     398    if ( isset($_COOKIE['bp_group_obj_id']) && !$group_obj && !$no_instantiate )
     399        $group_obj = new BP_Groups_Group( $_COOKIE['bp_group_obj_id'] );
    394400   
    395401    bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
  • trunk/bp-groups/bp-groups-ajax.php

    r1486 r1503  
    2222       
    2323        echo '<li id="uid-' . $user->id . '">';
    24         echo attribute_escape( $user->avatar_thumb );
    25         echo '<h4>' . attribute_escape( $user->user_link ) . '</h4>';
     24        echo $user->avatar_thumb;
     25        echo '<h4>' . $user->user_link . '</h4>';
    2626        echo '<span class="activity">' . attribute_escape( $user->last_active ) . '</span>';
    2727        echo '<div class="action">
  • trunk/bp-messages.php

    r1460 r1503  
    501501
    502502function messages_add_callback_values( $recipients, $subject, $content ) {
    503     $_SESSION['send_to'] = $recipients;
    504     $_SESSION['subject'] = $subject;
    505     $_SESSION['content'] = $content;
     503    setcookie( 'bp_messages_send_to', $recipients, time()+60*60*24, COOKIEPATH );
     504    setcookie( 'bp_messages_subject', $subject, time()+60*60*24, COOKIEPATH );
     505    setcookie( 'bp_messages_content', $content, time()+60*60*24, COOKIEPATH );
    506506}
    507507
    508508function messages_remove_callback_values() {
    509     unset($_SESSION['send_to']);
    510     unset($_SESSION['subject']);
    511     unset($_SESSION['content']);
     509    setcookie( 'bp_messages_send_to', false, time()-1000, COOKIEPATH );
     510    setcookie( 'bp_messages_subject', false, time()-1000, COOKIEPATH );
     511    setcookie( 'bp_messages_content', false, time()-1000, COOKIEPATH );
    512512}
    513513
  • trunk/bp-messages/bp-messages-templatetags.php

    r1473 r1503  
    284284}
    285285    function bp_get_messages_username_value() {
    286         if ( isset( $_SESSION['send_to'] ) ) {
    287             return apply_filters( 'bp_get_messages_username_value', $_SESSION['send_to'] );
    288         } else if ( isset( $_GET['r'] ) && !isset( $_SESSION['send_to'] ) ) {
     286        if ( isset( $_COOKIE['bp_messages_send_to'] ) ) {
     287            return apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );
     288        } else if ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) {
    289289            return apply_filters( 'bp_get_messages_username_value', $_GET['r'] );
    290290        }
     
    295295}
    296296    function bp_get_messages_subject_value() {
    297         return apply_filters( 'bp_get_messages_subject_value', $_SESSION['subject'] );
     297        return apply_filters( 'bp_get_messages_subject_value', $_COOKIE['bp_messages_subject'] );
    298298    }
    299299
     
    302302}
    303303    function bp_get_messages_content_value() {
    304         return apply_filters( 'bp_get_messages_content_value', $_SESSION['content'] );
     304        return apply_filters( 'bp_get_messages_content_value', $_COOKIE['bp_messages_content'] );
    305305    }
    306306
  • 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.