Skip to:
Content

BuddyPress.org

Changeset 1749


Ignore:
Timestamp:
09/01/2009 01:45:37 AM (15 years ago)
Author:
apeatling
Message:

Centrally registered activity actions in $bp->activity->actions. This will be used to add privacy support to activity feeds.

Location:
trunk
Files:
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r1733 r1749  
    6060    $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity_user_activity_cached';
    6161    $bp->activity->slug = BP_ACTIVITY_SLUG;
    62    
     62       
    6363    /* Register this in the active components array */
    6464    $bp->active_components[$bp->activity->slug] = $bp->activity->id;
     
    330330}
    331331
     332function bp_activity_set_action( $component_id, $key, $value ) {
     333    global $bp;
     334   
     335    if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
     336        return false;
     337   
     338    $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
     339        'key' => $key,
     340        'value' => $value
     341    ), $component_id, $key, $value );
     342}
     343
     344function bp_activity_get_action( $component_id, $key ) {
     345    global $bp;
     346   
     347    if ( empty( $component_id ) || empty( $key ) )
     348        return false;
     349   
     350    return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
     351}
     352
     353function groups_get_activity_action( $key ) {
     354    if ( !function_exists( 'bp_activity_get_action' ) )
     355        return false;
     356   
     357    return apply_filters( 'groups_get_activity_action', bp_activity_get_action( $key ), $key );
     358}
     359
    332360function bp_activity_get_last_updated() {
    333361    return BP_Activity_Activity::get_last_updated();
  • trunk/bp-blogs.php

    r1723 r1749  
    117117    $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
    118118    $bp->blogs->slug = BP_BLOGS_SLUG;
     119   
     120    /* Register the activity stream actions for this component */
     121    bp_blogs_register_activity_action( 'new_blog', __( 'New blog created', 'buddypress' ) );
     122    bp_blogs_register_activity_action( 'new_blog_post', __( 'New blog post published', 'buddypress' ) );
     123    bp_blogs_register_activity_action( 'new_blog_comment', __( 'New blog post comment posted', 'buddypress' ) );
    119124
    120125    /* Register this in the active components array */
     
    256261}
    257262
     263function bp_blogs_register_activity_action( $key, $value ) {
     264    global $bp;
     265   
     266    if ( !function_exists( 'bp_activity_set_action' ) )
     267        return false;
     268   
     269    return apply_filters( 'bp_blogs_register_activity_action', bp_activity_set_action( $bp->blogs->id, $key, $value ), $key, $value );
     270}
     271
    258272/********************************************************************************
    259273 * Business Functions
     
    315329        'content' => sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ),
    316330        'primary_link' => get_blog_option( $recorded_blog->blog_id, 'siteurl' ),
    317         'component_action' => 'new_blog',
     331        'component_action' => $bp->activity->actions->blogs['new_blog'],
    318332        'item_id' => $recorded_blog_id
    319333    ) );
     
    363377                'content' => sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ),
    364378                'primary_link' => $post_permalink,
    365                 'component_action' => 'new_blog_post',
     379                'component_action' => $bp->activity->actions->blogs['new_blog_post'],
    366380                'item_id' => $recorded_post->id,
    367381                'recorded_time' => $recorded_post->date_created
     
    398412            'content' => sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ),
    399413            'primary_link' => $post_permalink,
    400             'component_action' => 'new_blog_post',
     414            'component_action' => $bp->activity->actions->blogs['new_blog_post'],
    401415            'item_id' => $existing_post->id,
    402416            'recorded_time' => $existing_post->date_created
     
    444458        'content' => $content,
    445459        'primary_link' => $comment_link,
    446         'component_action' => 'new_blog_comment',
     460        'component_action' => $bp->activity->actions->blogs['new_blog_comment'],
    447461        'item_id' => $recorded_comment->blog_id,
    448462        'recorded_time' =>  $recorded_comment->date_created
     
    468482        'content' => $content,
    469483        'primary_link' => $comment_link,
    470         'component_action' => 'new_blog_comment',
     484        'component_action' => $bp->activity->actions->blogs['new_blog_comment'],
    471485        'item_id' => $recorded_comment->blog_id,
    472486        'recorded_time' =>  $recorded_comment->date_created
  • trunk/bp-forums.php

    r1723 r1749  
    2222    $bp->forums->bbconfig = get_site_option( 'bb-config-location' );
    2323    $bp->forums->slug = BP_FORUMS_SLUG;
    24 
     24   
    2525    /* Register this in the active components array */
    2626    $bp->active_components[$bp->forums->slug] = $bp->forums->id;
  • trunk/bp-friends.php

    r1723 r1749  
    4747    $bp->friends->format_notification_function = 'friends_format_notifications';
    4848    $bp->friends->slug = BP_FRIENDS_SLUG;
     49
     50    /* Register the activity stream actions for this component */
     51    friends_register_activity_action( 'friendship_created', __( 'New friendship created', 'buddypress' ) );
    4952
    5053    /* Register this in the active components array */
     
    290293   
    291294    switch( $action ) {
    292         case 'friendship_accepted':
     295        case 'friendship_created':
    293296            $friendship = new BP_Friends_Friendship( $item_id, false, false );
    294297
     
    323326}
    324327
     328function friends_register_activity_action( $key, $value ) {
     329    global $bp;
     330   
     331    if ( !function_exists( 'bp_activity_set_action' ) )
     332        return false;
     333   
     334    return apply_filters( 'friends_register_activity_action', bp_activity_set_action( $bp->friends->id, $key, $value ), $key, $value );
     335}
     336
    325337function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    326338    global $bp;
     
    636648       
    637649        // Record in activity streams
    638         friends_record_activity( array( 'item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_accepted', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id ) );
     650        friends_record_activity( array( 'item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_created', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id ) );
    639651       
    640652        // Send the email notification
  • trunk/bp-groups.php

    r1729 r1749  
    148148   
    149149    $bp->groups->valid_status = apply_filters( 'groups_valid_status', array( 'public', 'private', 'hidden' ) );
    150    
    151     return $bp;
     150
     151    /* Register the activity stream actions for this component */
     152    groups_register_activity_action( 'created_group', __( 'Created a group', 'buddypress' ) );
     153    groups_register_activity_action( 'joined_group', __( 'Joined a group', 'buddypress' ) );
     154    groups_register_activity_action( 'new_wire_post', __( 'New group wire post', 'buddypress' ) );
     155    groups_register_activity_action( 'new_forum_topic', __( 'New group forum topic', 'buddypress' ) );
     156    groups_register_activity_action( 'new_forum_post', __( 'New group forum post', 'buddypress' ) );
    152157}
    153158add_action( 'plugins_loaded', 'groups_setup_globals', 5 ); 
     
    13971402}
    13981403
     1404function groups_register_activity_action( $key, $value ) {
     1405    global $bp;
     1406   
     1407    if ( !function_exists( 'bp_activity_set_action' ) )
     1408        return false;
     1409   
     1410    return apply_filters( 'groups_register_activity_action', bp_activity_set_action( $bp->groups->id, $key, $value ), $key, $value );
     1411}
     1412
    13991413function groups_update_last_activity( $group_id ) {
    14001414    groups_update_groupmeta( $group_id, 'last_activity', time() );
     
    16631677    /* Delete the activity stream item */
    16641678    if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    1665         bp_activity_delete_by_item_id( array( 'item_id' => $group_id, 'component_name' => 'groups', 'component_action' => 'created_group' ) );
     1679        bp_activity_delete_by_item_id( array( 'item_id' => $group_id, 'component_name' => 'groups', 'component_action' => $bp->activity->actions->groups['created_group'] ) );
    16661680    }   
    16671681 
     
    19781992        /* Delete the activity stream item */
    19791993        if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    1980             bp_activity_delete_by_item_id( array( 'item_id' => $wire_post_id, 'component_name' => 'groups', 'component_action' => 'new_wire_post' ) );
     1994            bp_activity_delete_by_item_id( array( 'item_id' => $wire_post_id, 'component_name' => 'groups', 'component_action' => $bp->activity->actions->groups['new_wire_post'] ) );
    19811995        }
    19821996           
     
    20662080    if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id ) ) ) {
    20672081        /* Update the activity stream item */
    2068         bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2082        bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => $bp->activity->actions->groups['new_forum_topic'] ) );
    20692083       
    20702084        $activity_content = sprintf( __( '%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug .'">' . attribute_escape( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     
    20962110        /* Delete the activity stream item */
    20972111        if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    2098             bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2112            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => $bp->activity->actions->groups['new_forum_topic'] ) );
    20992113            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
    21002114        }
  • trunk/bp-messages.php

    r1724 r1749  
    364364 */
    365365
    366 function messages_record_activity( $args = true ) {
    367     if ( function_exists('bp_activity_record') ) {
    368         extract($args);
    369         bp_activity_record( $item_id, $component_name, $component_action, $is_private );
    370     }
    371 }
    372 
    373 function messages_delete_activity( $args = true ) {
    374     if ( function_exists('bp_activity_delete') ) {
    375         extract($args);
    376         bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    377     }
    378 }
    379 
    380366function messages_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    381367    global $bp;
  • trunk/bp-status.php

    r1723 r1749  
    1212    $bp->status->id = 'status';
    1313    $bp->status->slug = BP_STATUS_SLUG;
     14   
     15    /* Register the activity stream actions for this component */
     16    bp_status_register_activity_action( 'new_status', __( 'New status update', 'buddypress' ) );
    1417
    1518    /* Register this in the active components array */
     
    1922add_action( 'admin_menu', 'bp_status_setup_globals', 2 );
    2023
    21 function bp_status_record_activity( $user_id, $content, $primary_link ) {
     24
     25/********************************************************************************
     26 * Activity & Notification Functions
     27 *
     28 * These functions handle the recording, deleting and formatting of activity and
     29 * notifications for the user and for this specific component.
     30 */
     31
     32function bp_status_record_activity( $user_id, $content, $primary_link, $component_action = 'new_status' ) {
    2233    if ( !function_exists( 'bp_activity_add' ) )
    2334        return false;
     
    2839            'primary_link' => $primary_link,
    2940            'component_name' => 'status',
    30             'component_action' => 'new_status'
     41            'component_action' => $component_action
    3142           ) );
    3243}
     
    5566   
    5667    return apply_filters( 'bp_status_format_activity', $stream_item, $user_id, $content, $component_action );
     68}
     69
     70function bp_status_register_activity_action( $key, $value ) {
     71    global $bp;
     72   
     73    if ( !function_exists( 'bp_activity_set_action' ) )
     74        return false;
     75   
     76    return apply_filters( 'bp_status_register_activity_action', bp_activity_set_action( $bp->status->id, $key, $value ), $key, $value );
    5777}
    5878
  • trunk/bp-xprofile.php

    r1739 r1749  
    88require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-classes.php' );
    99require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-filters.php' );
    10 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-signup.php' );
    1110require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-templatetags.php' );
    1211require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-notifications.php' );
     
    142141    $bp->profile->slug = BP_XPROFILE_SLUG;
    143142
     143    /* Register the activity stream actions for this component */
     144    xprofile_register_activity_action( 'new_wire_post', __( 'New profile wire post', 'buddypress' ) );
     145
    144146    /* Register this in the active components array */
    145147    $bp->active_components[$bp->profile->slug] = $bp->profile->id;
    146 
     148   
     149    /* Set the support field type ids */
    147150    $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) );
    148151
    149     if ( function_exists('bp_wire_install') )
     152    if ( function_exists( 'bp_wire_install' ) )
    150153        $bp->profile->table_name_wire = $wpdb->base_prefix . 'bp_xprofile_wire';
    151154}
     
    630633}
    631634
     635function xprofile_register_activity_action( $key, $value ) {
     636    global $bp;
     637   
     638    if ( !function_exists( 'bp_activity_set_action' ) )
     639        return false;
     640   
     641    return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( $bp->profile->id, $key, $value ), $key, $value );
     642}
     643
    632644/**
    633645 * xprofile_format_notifications()
  • trunk/bp-xprofile/deprecated/bp-xprofile-deprecated.php

    r1726 r1749  
    409409}
    410410
    411 
     411/*** DEPRECATED SIGNUP FUNCTIONS *******/
     412
     413function 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}
     421add_action( 'init', 'xprofile_clear_signup_cookie' );
     422
     423function 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}
     489add_action( 'signup_extra_fields', 'xprofile_add_signup_fields' );
     490
     491function 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}
     507add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 );
     508
     509function 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}
     522add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' );
     523
     524function 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}
     644add_action( 'init', 'xprofile_load_signup_meta' );
     645
     646function 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}
     661add_action( 'init', 'xprofile_load_blog_signup_meta' );
     662
     663function 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}
     671add_action( 'wpmu_activate_blog', 'xprofile_on_activate_blog', 1, 5 );
     672
     673
     674function 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}
     682add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 3 );
     683
     684function 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
     707function 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'] . '&amp;cropped=true';
     735        bp_core_render_avatar_cropper($original, $resized, $action, $user_id);
     736    }
     737}
     738
     739function 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}
     761add_action( 'activate_header', 'xprofile_catch_activate_crop' );
     762
     763
     764function 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 *****/
    412778
    413779?>
Note: See TracChangeset for help on using the changeset viewer.