Skip to:
Content

BuddyPress.org

Changeset 1693 for trunk/bp-xprofile.php


Ignore:
Timestamp:
08/25/2009 01:17:25 AM (16 years ago)
Author:
apeatling
Message:

Updated xprofile activity record function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r1687 r1693  
    133133    global $bp, $wpdb;
    134134   
     135    /* For internal identification */
     136    $bp->profile->id = 'profile';
     137       
    135138    $bp->profile->table_name_groups = $wpdb->base_prefix . 'bp_xprofile_groups';
    136139    $bp->profile->table_name_fields = $wpdb->base_prefix . 'bp_xprofile_fields';
    137140    $bp->profile->table_name_data = $wpdb->base_prefix . 'bp_xprofile_data';
    138     $bp->profile->format_activity_function = 'xprofile_format_activity';
     141
    139142    $bp->profile->format_notification_function = 'xprofile_format_notifications';
    140     $bp->profile->image_base = BP_PLUGIN_URL . '/bp-xprofile/images';
    141143    $bp->profile->slug = BP_XPROFILE_SLUG;
    142144   
    143145    $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) );
    144146
    145     $bp->version_numbers->profile = BP_XPROFILE_VERSION;
    146    
    147147    if ( function_exists('bp_wire_install') )
    148148        $bp->profile->table_name_wire = $wpdb->base_prefix . 'bp_xprofile_wire';
     
    482482        return false;
    483483       
    484     if ( !$wire_post_id = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
     484    if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
    485485        bp_core_add_message( __( 'Wire message could not be posted. Please try again.', 'buddypress' ), 'error' );
    486486    } else {
    487487        bp_core_add_message( __( 'Wire message successfully posted.', 'buddypress' ) );
    488 
    489         if ( !bp_is_home() ) {
    490             /* Record the notification for the user */
     488       
     489        /* Record the notification for the reciever if it's not on their own wire */
     490        if ( !bp_is_home() )
    491491            bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, 'profile', 'new_wire_post' );   
    492         }
    493        
    494         do_action( 'xprofile_new_wire_post', $wire_post_id );   
     492       
     493        /* Record this on the poster's activity screen */
     494        if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
     495            $from_user_link = bp_core_get_userlink($wire_post->user_id);
     496            $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';             
     497            $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true );   
     498        } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
     499            $from_user_link = bp_core_get_userlink($wire_post->user_id);
     500            $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true );
     501            $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';         
     502            $primary_link = bp_core_get_userlink( $wire_post->item_id, false, true );
     503        }
     504       
     505        $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>';
     506
     507        /* Now write the values */
     508        xprofile_record_activity( array(
     509            'user_id' => $bp->loggedin_user->id,
     510            'content' => $content,
     511            'primary_link' => $primary_link,
     512            'component_action' => 'new_wire_post',
     513            'item_id' => $wire_post->item_id
     514        ) );
     515               
     516        do_action( 'xprofile_new_wire_post', &$wire_post );
    495517    }
    496518
     
    565587 */
    566588function xprofile_record_activity( $args = true ) {
    567     if ( function_exists('bp_activity_record') ) {
    568         extract($args);
    569         bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
    570     }
     589    global $bp;
     590   
     591    if ( !function_exists( 'bp_activity_add' ) )
     592        return false;
     593
     594    $defaults = array(
     595        'user_id' => $bp->loggedin_user->id,
     596        'content' => false,
     597        'primary_link' => false,
     598        'component_name' => $bp->profile->id,
     599        'component_action' => false,
     600        'item_id' => false,
     601        'secondary_item_id' => false,
     602        'recorded_time' => time(),
     603        'hide_sitewide' => false
     604    );
     605
     606    $r = wp_parse_args( $args, $defaults );
     607    extract( $r, EXTR_SKIP );   
     608   
     609    return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    571610}
    572611
     
    587626        bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    588627    }
    589 }
    590 
    591 /**
    592  * xprofile_format_activity()
    593  *
    594  * The function xprofile_record_activity() simply records ID's, which component and action, and dates into
    595  * the database. These variables need to be formatted into something that can be read and displayed to
    596  * the user.
    597  *
    598  * This function will format an activity item based on the component action and return it for saving
    599  * in the activity cache database tables. It can then be selected and displayed with far less load on
    600  * the server.
    601  *
    602  * @package BuddyPress Xprofile
    603  * @param $item_id The ID of the specific item for which the activity is recorded (could be a wire post id, user id etc)
    604  * @param $action The component action name e.g. 'new_wire_post' or 'updated_profile'
    605  * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    606  * @global $current_user WordPress global variable containing current logged in user information
    607  * @uses BP_Wire_Post Class Creates a new wire post object based on the table name and ID.
    608  * @uses BP_XProfile_Group Class Creates a new group object based on the group ID.
    609  * @return The readable activity item
    610  */
    611 function xprofile_format_activity( $item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false ) {
    612     global $bp;
    613    
    614     switch( $action ) {
    615         case 'new_wire_post':
    616             if ( class_exists('BP_Wire_Post') ) {
    617                 $wire_post = new BP_Wire_Post( $bp->profile->table_name_wire, $item_id );
    618             }
    619            
    620             if ( !$wire_post )
    621                 return false;
    622            
    623             if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
    624                
    625                 $from_user_link = bp_core_get_userlink($wire_post->user_id);
    626                 $to_user_link = false;
    627                                
    628                 $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';             
    629                 $return_values['primary_link'] = bp_core_get_userlink( $wire_post->user_id, false, true );
    630            
    631             } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
    632            
    633                 $from_user_link = bp_core_get_userlink($wire_post->user_id);
    634                 $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true );
    635                
    636                 $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';         
    637                 $return_values['primary_link'] = bp_core_get_userlink( $wire_post->item_id, false, true );
    638            
    639             }
    640            
    641             if ( $content != '' ) {
    642                 $post_excerpt = bp_create_excerpt($wire_post->content);
    643                
    644                 $content .= '<blockquote>' . $post_excerpt . '</blockquote>';
    645                 $return_values['content'] = $content;
    646                
    647                 $return_values['content'] = apply_filters( 'xprofile_new_wire_post_activity', $content, $from_user_link, $to_user_link, $post_excerpt );
    648                
    649                 return $return_values;
    650             }
    651            
    652             return false;
    653         break;
    654         case 'updated_profile':
    655             $profile_group = new BP_XProfile_Group( $item_id );
    656            
    657             if ( !$profile_group )
    658                 return false;
    659            
    660             $user_link = bp_core_get_userlink($user_id);
    661            
    662             return array(
    663                 'primary_link' => bp_core_get_userlink( $user_id, false, true ),
    664                 'content' => apply_filters( 'xprofile_updated_profile_activity', sprintf( __('%s updated the "%s" information on their profile', 'buddypress'), $user_link, '<a href="' . $bp->displayed_user->domain . $bp->profile->slug . '">' . $profile_group->name . '</a>' ) . ' <span class="time-since">%s</span>', $user_link, $profile_group->name )
    665             );
    666         break;
    667     }
    668    
    669     do_action( 'xprofile_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user );
    670    
    671     return false;
    672628}
    673629
Note: See TracChangeset for help on using the changeset viewer.