Skip to:
Content

BuddyPress.org

Changeset 2088 for trunk/bp-activity.php


Ignore:
Timestamp:
11/13/2009 01:01:37 AM (16 years ago)
Author:
apeatling
Message:

Initial support for threaded activity stream commenting. Some major performance improvements around fetching profile and group data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2077 r2088  
    11<?php
    22
    3 define ( 'BP_ACTIVITY_DB_VERSION', '1800' );
     3define ( 'BP_ACTIVITY_DB_VERSION', '1900' );
    44
    55/* Define the slug for the component */
     
    3333                date_recorded datetime NOT NULL,
    3434                hide_sitewide bool DEFAULT 0,
     35                mptt_left int(11) NOT NULL,
     36                mptt_right int(11) NOT NULL,
    3537                KEY date_recorded (date_recorded),
    3638                KEY user_id (user_id),
     
    224226 */
    225227
     228function bp_activity_get_sitewide( $args = '' ) {
     229    $defaults = array(
     230        'max' => false, // Maximum number of results to return
     231        'page' => 1, // page 1 without a per_page will result in no pagination.
     232        'per_page' => false, // results per page
     233        'sort' => 'DESC', // sort ASC or DESC
     234        'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
     235
     236        'search_terms' => false, // Pass search terms as a string
     237
     238        /**
     239         * Pass filters as an array:
     240         * array(
     241         *  'user_id' => false, // user_id to filter on
     242         *  'object' => false, // object to filter on e.g. groups, profile, status, friends
     243         *  'action' => false, // action to filter on e.g. new_wire_post, new_forum_post, profile_updated
     244         *  'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
     245         *  'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
     246         * );
     247         */
     248        'filter' => array()
     249    );
     250
     251    $r = wp_parse_args( $args, $defaults );
     252    extract( $r, EXTR_SKIP );
     253
     254    return apply_filters( 'bp_activity_get_sitewide', BP_Activity_Activity::get_sitewide_activity( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments ), &$r );
     255}
     256
     257function bp_activity_get_for_user( $args = '' ) {
     258    global $bp;
     259
     260    $defaults = array(
     261        'user_id' => $bp->displayed_user->id,
     262        'max' => false, // Maximum number of results to return
     263        'page' => 1, // page 1 without a per_page will result in no pagination.
     264        'per_page' => false, // results per page
     265        'sort' => 'DESC', // sort ASC or DESC
     266        'display_comments' => 'stream', // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
     267
     268        'search_terms' => false, // Pass search terms as a string
     269        'filter' => array()
     270    );
     271
     272    $r = wp_parse_args( $args, $defaults );
     273    extract( $r, EXTR_SKIP );
     274
     275    return apply_filters( 'bp_activity_get_for_user', BP_Activity_Activity::get_activity_for_user( $user_id, $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments ), &$r );
     276}
     277
     278function bp_activity_get_friends_activity( $user_id, $max = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {
     279    return apply_filters( 'bp_activity_get_friends_activity', BP_Activity_Activity::get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter ), $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter );
     280}
     281
     282function bp_activity_get_specific( $args = '' ) {
     283    $defaults = array(
     284        'activity_ids' => false, // A single activity_id or array of IDs.
     285        'max' => false, // Maximum number of results to return
     286        'page' => 1, // page 1 without a per_page will result in no pagination.
     287        'per_page' => false, // results per page
     288        'sort' => 'DESC', // sort ASC or DESC
     289        'display_comments' => false // true or false to display threaded comments for these specific activity items
     290    );
     291
     292    $r = wp_parse_args( $args, $defaults );
     293    extract( $r, EXTR_SKIP );
     294
     295    return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
     296}
     297
    226298function bp_activity_add( $args = '' ) {
    227299    global $bp, $wpdb;
     
    247319        $content = bp_activity_add_timesince_placeholder( $content );
    248320
    249     $activity = new BP_Activity_Activity;
     321    /* Pass certain values so we can update an activity item if it already exists */
     322    $activity = new BP_Activity_Activity();
     323
    250324    $activity->user_id = $user_id;
    251325    $activity->content = $content;
     
    261335        return false;
    262336
    263     do_action( 'bp_activity_add', $args );
    264 
    265     return true;
     337    /* If this is an activity comment, rebuild the tree */
     338    if ( 'activity_comment' == $activity->component_action )
     339        BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
     340
     341    do_action( 'bp_activity_add', $r );
     342
     343    return $activity->id;
    266344}
    267345
     
    374452}
    375453
    376 function bp_activity_get_sitewide_activity( $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) {
    377     return apply_filters( 'bp_activity_get_sitewide_activity', BP_Activity_Activity::get_sitewide_activity( $max_items, $pag_num, $pag_page, $filter ), $max_items, $pag_num, $pag_page, $filter );
    378 }
    379 
    380 function bp_activity_get_user_activity( $user_id, $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) {
    381     return apply_filters( 'bp_activity_get_user_activity', BP_Activity_Activity::get_activity_for_user( $user_id, $max_items, $pag_num, $pag_page, $filter ), $user_id, $max_items, $pag_num, $pag_page, $filter );
    382 }
    383 
    384 function bp_activity_get_friends_activity( $user_id, $max_items = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {
    385     return apply_filters( 'bp_activity_get_friends_activity', BP_Activity_Activity::get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter ), $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter );
    386 }
    387 
    388454function bp_activity_remove_data( $user_id ) {
    389455    // Clear the user's activity from the sitewide stream and clear their activity tables
Note: See TracChangeset for help on using the changeset viewer.