Skip to:
Content

BuddyPress.org

Changeset 2025


Ignore:
Timestamp:
10/02/2009 10:07:58 PM (17 years ago)
Author:
apeatling
Message:

Fixing registration and avatar bugs with old 1.0 themes in 1.1.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-activation.php

    r1970 r2025  
    55       
    66        if ( BP_ACTIVATION_SLUG != $bp->current_component )
     7                return false;
     8               
     9        /* If we are using a BuddyPress 1.0 theme ignore this. */
     10        if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
    711                return false;
    812               
    … …  
    6872        }
    6973       
    70         bp_core_load_template( 'registration/activate' );
     74        if ( '' != locate_template( array( 'registration/activate' ), false ) )
     75                bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );             
     76        else
     77                bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );         
    7178}
    7279add_action( 'wp', 'bp_core_screen_activation', 3 );
  • trunk/bp-core/bp-core-avatars.php

    r2002 r2025  
    283283        $r = wp_parse_args( $args, $defaults );
    284284        extract( $r, EXTR_SKIP );
    285        
     285
    286286        if ( !$original_file )
    287287                return false;
    … …  
    318318        $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
    319319        $thumb_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
    320        
     320
    321321        /* Remove the original */
    322322        @unlink( WP_CONTENT_DIR . $original_file );
  • trunk/bp-core/bp-core-cssjs.php

    r2017 r2025  
    123123
    124124                                jQuery('#avatar-crop-preview').css({
     125                                <?php if ( $image ) : ?>
    125126                                        width: Math.round(rx * <?php echo $image[0] ?>) + 'px',
    126127                                        height: Math.round(ry * <?php echo $image[1] ?>) + 'px',
     128                                <?php endif; ?>
    127129                                        marginLeft: '-' + Math.round(rx * coords.x) + 'px',
    128130                                        marginTop: '-' + Math.round(ry * coords.y) + 'px'
  • trunk/bp-core/deprecated/bp-core-deprecated.php

    r1984 r2025  
    712712}
    713713
     714function bp_core_handle_avatar_upload($file) {
     715        global $wp_upload_error;
     716       
     717        require_once( ABSPATH . '/wp-admin/includes/file.php' );
     718       
     719        // Change the upload file location to /avatars/user_id
     720        add_filter( 'upload_dir', 'xprofile_avatar_upload_dir' );
     721
     722        $res = wp_handle_upload( $file['file'], array('action'=>'slick_avatars') );
     723
     724        if ( !in_array('error', array_keys($res) ) ) {
     725                return $res['file'];
     726        } else {
     727                $wp_upload_error = $res['error'];
     728                return false;
     729        }
     730}
     731
     732function bp_core_resize_avatar( $file, $size = false ) {
     733        require_once( ABSPATH . '/wp-admin/includes/image.php' );
     734
     735        if ( !$size )
     736                $size = CORE_CROPPING_CANVAS_MAX;
     737
     738        $canvas = wp_create_thumbnail( $file, $size );
     739
     740        if ( $canvas->errors )
     741                return false;
     742
     743        return $canvas = str_replace( '//', '/', $canvas );
     744}
    714745
    715746/*** END OLD AVATAR CROPPING SUPPORT **************************/
  • trunk/bp-groups.php

    r2004 r2025  
    569569                }
    570570        }
    571        
    572         //var_dump($_COOKIE);
     571
    573572        bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
    574573}
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r1977 r2025  
    622622                }
    623623        }
    624 
    625         /* Deprecated - Signup fields are now in the template */
    626         function get_signup_fields() {
    627                 global $wpdb, $bp;
    628                
    629                 $sql = $wpdb->prepare( "SELECT f.id FROM {$bp->profile->table_name_fields} AS f, {$bp->profile->table_name_groups} AS g WHERE g.name = %s AND f.parent_id = 0   AND g.id = f.group_id ORDER BY f.id", get_site_option('bp-xprofile-base-group-name') );
    630 
    631                 if ( !$temp_fields = $wpdb->get_results($sql) )
    632                         return false;
    633                
    634                 for ( $i = 0; $i < count($temp_fields); $i++ ) {
    635                         $fields[] = new BP_XProfile_Field( $temp_fields[$i]->id, null, false );
    636                 }
    637                
    638                 return $fields;
    639         }
    640 
    641624}
    642625
  • trunk/bp-xprofile/deprecated/bp-xprofile-deprecated.php

    r1905 r2025  
    406406                return $html;
    407407        }
     408       
     409        /* Deprecated - Signup fields are now in the template */
     410        function get_signup_fields() {
     411                global $wpdb, $bp;
     412               
     413                $sql = $wpdb->prepare( "SELECT f.id FROM {$bp->profile->table_name_fields} AS f, {$bp->profile->table_name_groups} AS g WHERE g.name = %s AND f.parent_id = 0   AND g.id = f.group_id ORDER BY f.id", get_site_option('bp-xprofile-base-group-name') );
     414
     415                if ( !$temp_fields = $wpdb->get_results($sql) )
     416                        return false;
     417               
     418                for ( $i = 0; $i < count($temp_fields); $i++ ) {
     419                        $fields[] = new BP_XProfile_Field_Deprecated( $temp_fields[$i]->id, null, false );
     420                }
     421               
     422                return $fields;
     423        }
     424
    408425
    409426}
    … …  
    425442
    426443        /* Fetch the fields needed for the signup form */
    427         $fields = BP_XProfile_Field::get_signup_fields();
     444        $fields = BP_XProfile_Field_Deprecated::get_signup_fields();
    428445
    429446        if ( $fields ) {
    … …  
    537554       
    538555        // Validate all sign up fields
    539         $fields = BP_XProfile_Field::get_signup_fields();
     556        $fields = BP_XProfile_Field_Deprecated::get_signup_fields();
    540557
    541558        if ( $fields ) {
    … …  
    619636                        if ( $checked_upload && $checked_size && $checked_type && !$original = bp_core_handle_avatar_upload($_FILES) ) {
    620637                                $bp_signup_avatar_has_errors = true;
    621                                 $avatar_error_msg = sprintf( __('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error );                                             
     638                                $avatar_error_msg = sprintf( __('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error );     
     639                                die;                                   
    622640                        }
    623641       
    … …  
    639657                $bp_user_signup_meta['avatar_image_original'] = $original;
    640658               
    641                 setcookie( 'bp_xprofile_meta', serialize($bp_user_signup_meta), time()+60*60*24, COOKIEPATH );
     659                $bp_user_signup_meta = serialize( $bp_user_signup_meta );
    642660        }
    643661}
    644662add_action( 'init', 'xprofile_load_signup_meta' );
     663
     664function xprofile_render_user_signup_meta() {
     665        global $bp_user_signup_meta;
     666       
     667        echo '<input type="hidden" name="bp_xprofile_meta" id="bp_xprofile_meta" value="' . attribute_escape( $bp_user_signup_meta ) . '" />';
     668}
     669add_action( 'signup_blogform', 'xprofile_render_user_signup_meta' );
    645670
    646671function xprofile_load_blog_signup_meta() {
    … …  
    656681        );
    657682       
    658         $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) );
    659         $bp_blog_signup_meta = array_merge( $bp_meta, $blog_meta );
     683        $bp_meta = unserialize( stripslashes( $_POST['bp_xprofile_meta'] ) );
     684        $bp_blog_signup_meta = array_merge( (array)$bp_meta, (array)$blog_meta );
    660685}
    661686add_action( 'init', 'xprofile_load_blog_signup_meta' );
    … …  
    671696add_action( 'wpmu_activate_blog', 'xprofile_on_activate_blog', 1, 5 );
    672697
    673 
    674698function xprofile_on_activate_user( $user_id, $password, $meta ) {     
    675699        xprofile_extract_signup_meta( $user_id, $meta );
    … …  
    680704                xprofile_handle_signup_avatar( $user_id, $meta );
    681705}
    682 add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 3 );
     706add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 5 );
    683707
    684708function xprofile_extract_signup_meta( $user_id, $meta ) {
    … …  
    706730
    707731function xprofile_handle_signup_avatar( $user_id, $meta ) {
     732        global $bp;
     733       
     734        $meta = maybe_unserialize( $meta );
     735       
    708736        $resized = $meta['avatar_image_resized'];
    709737        $original = $meta['avatar_image_original'];     
    710        
     738
    711739        if ( !empty($resized) && !empty($original) ) {
    712740                // Create and set up the upload dir first.
    713                 $upload_dir = bp_core_avatar_upload_dir( false, $user_id );
     741                $upload_dir = xprofile_avatar_upload_dir( false, $user_id );
    714742               
    715743                $resized_strip_path = explode( '/', $resized );
    … …  
    730758                $resized = $resized_new;
    731759                $original = $original_new;
    732        
    733                 // Render the cropper UI
    734                 $action = bp_activation_page( false ) . '?key=' . $_GET['key'] . '&amp;cropped=true';
    735                 bp_core_render_avatar_cropper($original, $resized, $action, $user_id);
    736         }
    737 }
     760
     761                $bp->avatar_admin->image = new stdClass;
     762                $bp->avatar_admin->image->dir = $resized;
     763               
     764                /* Set the url value for the image */
     765                $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $bp->avatar_admin->image->dir );
     766
     767                ?>
     768                <form action="<?php echo $bp->root_domain . '/' . BP_ACTIVATION_SLUG ?>" method="post">
     769                        <h3><?php _e( 'Crop Your New Avatar', 'buddypress' ) ?></h3>
     770
     771                        <img src="<?php echo attribute_escape( $bp->avatar_admin->image->url ) ?>" id="avatar-to-crop" class="avatar" alt="<?php _e( 'Avatar to crop', 'buddypress' ) ?>" />
     772
     773                        <input type="submit" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php _e( 'Crop Image', 'buddypress' ) ?>" />
     774
     775                        <input type="hidden" name="image_src" id="image_src" value="<?php echo attribute_escape( $bp->avatar_admin->image->dir ) ?>" />
     776                        <input type="hidden" id="x" name="x" />
     777                        <input type="hidden" id="y" name="y" />
     778                        <input type="hidden" id="w" name="w" />
     779                        <input type="hidden" id="h" name="h" />
     780                        <input type="hidden" id="cropped" name="cropped" />
     781                        <input type="hidden" id="key" name="key" value="<?php echo attribute_escape( $_GET['key'] ) ?>"/>
     782
     783                        <?php wp_nonce_field( 'bp_avatar_cropstore' ); ?>
     784                </form><?php
     785        }
     786}
     787
     788function xprofile_deprecated_add_cropper_js() {
     789        global $bp;
     790       
     791        /* If we are using a BuddyPress 1.1+ theme ignore this. */
     792        if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
     793                return false;
     794       
     795        if ( $bp->current_component == BP_ACTIVATION_SLUG )
     796                add_action( 'wp', 'bp_core_add_jquery_cropper' );
     797}
     798add_action( 'init', 'xprofile_deprecated_add_cropper_js' );
    738799
    739800function xprofile_catch_activate_crop() {
    740         if ( isset( $_GET['cropped'] ) ) {
     801        if ( isset( $_POST['cropped'] ) ) {
     802
    741803                // The user has cropped their avatar after activating account
    742                
     804
    743805                // 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                
     806                check_admin_referer( 'bp_avatar_cropstore' );
     807
     808                $user_id = xprofile_get_user_by_key( $_POST['key'] );
     809
     810                bp_core_avatar_handle_crop( array( 'item_id' => $user_id, 'original_file' => str_replace( WP_CONTENT_DIR, '', $_POST['image_src'] ), 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) );
     811
    755812                $ud = get_userdata($user_id);
    756813                $url = site_url( BP_MEMBERS_SLUG . '/' . $ud->user_login );
    757                
     814
    758815                bp_core_redirect( $url );
    759816        }
    760817}
    761818add_action( 'activate_header', 'xprofile_catch_activate_crop' );
    762 
    763819
    764820function xprofile_get_user_by_key($key) {
Note: See TracChangeset for help on using the changeset viewer.