Skip to:
Content

BuddyPress.org

Changeset 2381 for trunk/bp-activity.php


Ignore:
Timestamp:
01/20/2010 04:21:20 PM (16 years ago)
Author:
apeatling
Message:

Standardizing activity stream fields and splitting the action from the content for better manageability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2362 r2381  
    11<?php
    22
    3 define ( 'BP_ACTIVITY_DB_VERSION', '2020' );
     3define ( 'BP_ACTIVITY_DB_VERSION', '2031' );
    44
    55/* Define the slug for the component */
     
    1818
    1919    /* Rename the old user activity cached table if needed. */
    20     $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
    21 
     20    if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) ) {
     21        $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
     22    }
     23
     24    /* Rename fields from pre BP 1.2 */
     25    if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
     26        $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE type type varchar(75) NOT NULL" );
     27        $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component component varchar(75) NOT NULL" );
     28    }
     29
     30    /**
     31     * Build the tables
     32     */
    2233    $sql[] = "CREATE TABLE {$bp->activity->table_name} (
    2334                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    2435                user_id bigint(20) NOT NULL,
    25                 component_name varchar(75) NOT NULL,
    26                 component_action varchar(75) NOT NULL,
     36                component varchar(75) NOT NULL,
     37                type varchar(75) NOT NULL,
     38                action text NOT NULL
    2739                content longtext NOT NULL,
    2840                primary_link varchar(150) NOT NULL,
    2941                item_id varchar(75) NOT NULL,
    30                 secondary_item_id varchar(75) NOT NULL,
     42                secondary_item_id varchar(75) DEFAULT NULL,
    3143                date_recorded datetime NOT NULL,
    3244                hide_sitewide bool DEFAULT 0,
     
    3648                KEY user_id (user_id),
    3749                KEY item_id (item_id),
    38                 KEY component_name (component_name)
     50                KEY component (component)
    3951               ) {$charset_collate};";
    4052
     
    167179    $has_access = true;
    168180    /* Redirect based on the type of activity */
    169     if ( $activity->component_name == $bp->groups->id ) {
     181    if ( $activity->component == $bp->groups->id ) {
    170182        if ( !function_exists( 'groups_get_group' ) )
    171183            bp_core_redirect( $bp->root_domain );
     
    248260    $redirect = false;
    249261    /* Redirect based on the type of activity */
    250     if ( $activity->component_name == $bp->groups->id ) {
     262    if ( $activity->component == $bp->groups->id ) {
    251263        if ( $activity->user_id )
    252264            $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
     
    445457        'id' => false, // Pass an existing activity ID to update an existing entry.
    446458
    447         'content' => false, // The content of the activity item
    448         'primary_link' => false, // The primary URL for this item in RSS feeds
    449         'component_name' => false, // The name/ID of the component e.g. groups, profile, mycomponent
    450         'component_action' => false, // The component action e.g. activity_update, profile_updated
     459        'action' => '', // The activity action - e.g. "Jon Doe posted an update"
     460        'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
     461
     462        'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
     463        'type' => false, // The activity type e.g. activity_update, profile_updated
     464        'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
    451465
    452466        'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
     
    460474    extract( $params, EXTR_SKIP );
    461475
    462     /* Insert the "time-since" placeholder */
    463     if ( $content )
     476    /* Make sure we are backwards compatible */
     477    if ( empty( $component ) && !empty( $component_name ) )
     478        $component = $component_name;
     479
     480    if ( empty( $type ) && !empty( $component_action ) )
     481        $type = $component_action;
     482
     483    /* Insert the "time-since" placeholder (use content if action empty for backwards compat) */
     484    if ( !empty( $action ) )
     485        $action = bp_activity_add_timesince_placeholder( $action );
     486    else if ( empty( $action ) && !empty( $content ) )
    464487        $content = bp_activity_add_timesince_placeholder( $content );
    465488
     489    /* Remove any images and replace the first image with a thumbnail */
     490    //$content = bp_activity_thumbnail_images( $content );
     491
    466492    $activity = new BP_Activity_Activity( $id );
    467493
    468494    $activity->user_id = $user_id;
     495    $activity->component = $component;
     496    $activity->type = $type;
     497    $activity->action = $action;
    469498    $activity->content = $content;
    470499    $activity->primary_link = $primary_link;
    471     $activity->component_name = $component_name;
    472     $activity->component_action = $component_action;
    473500    $activity->item_id = $item_id;
    474501    $activity->secondary_item_id = $secondary_item_id;
     
    480507
    481508    /* If this is an activity comment, rebuild the tree */
    482     if ( 'activity_comment' == $activity->component_action )
     509    if ( 'activity_comment' == $activity->type )
    483510        BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
    484511
     
    499526    extract( $r, EXTR_SKIP );
    500527
    501     if ( empty($content) || empty($content) )
     528    if ( empty( $content ) )
    502529        return false;
    503530
    504531    /* Record this on the user's profile */
    505532    $from_user_link = bp_core_get_userlink( $user_id );
    506     $activity_content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link );
    507     $activity_content .= '<div class="activity-inner">' . $content . '</div>';
     533    $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
     534    $activity_content = '<div class="activity-inner">' . $content . '</div>';
    508535
    509536    $primary_link = bp_core_get_userlink( $user_id, false, true );
     
    512539    $activity_id = bp_activity_add( array(
    513540        'user_id' => $user_id,
     541        'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
    514542        'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
    515543        'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
    516         'component_name' => $bp->activity->id,
    517         'component_action' => 'activity_update'
     544        'component' => $bp->activity->id,
     545        'type' => 'activity_update'
    518546    ) );
    519547
     
    552580        'content' => apply_filters( 'bp_activity_comment_content', $comment_header . '<div class="activity-inner">' . $content . '</div>' ),
    553581        'primary_link' => '',
    554         'component_name' => $bp->activity->id,
    555         'component_action' => 'activity_comment',
     582        'component' => $bp->activity->id,
     583        'type' => 'activity_comment',
    556584        'user_id' => $user_id,
    557585        'item_id' => $activity_id,
     
    588616    $defaults = array(
    589617        'item_id' => false,
    590         'component_name' => false,
    591         'component_action' => false, // optional
     618        'component' => false,
     619        'type' => false, // optional
    592620        'user_id' => false, // optional
    593621        'secondary_item_id' => false // optional
     
    597625    extract( $r, EXTR_SKIP );
    598626
    599     if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_item_id( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) )
    600         return false;
    601 
    602     do_action( 'bp_activity_delete_by_item_id', $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
     627    if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_item_id( $item_id, $component, $type, $user_id, $secondary_item_id ) )
     628        return false;
     629
     630    do_action( 'bp_activity_delete_by_item_id', $item_id, $component, $type, $user_id, $secondary_item_id );
    603631    do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
    604632
     
    616644}
    617645
    618 function bp_activity_delete_by_content( $user_id, $content, $component_name, $component_action ) {
     646function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
    619647    /* Insert the "time-since" placeholder to match the existing content in the DB */
    620648    $content = bp_activity_add_timesince_placeholder( $content );
    621649
    622     if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_content( $user_id, $content, $component_name, $component_action ) )
    623         return false;
    624 
    625     do_action( 'bp_activity_delete_by_content', $user_id, $content, $component_name, $component_action );
     650    if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_content( $user_id, $content, $component, $type ) )
     651        return false;
     652
     653    do_action( 'bp_activity_delete_by_content', $user_id, $content, $component, $type );
    626654    do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
    627655
     
    629657}
    630658
    631 function bp_activity_delete_for_user_by_component( $user_id, $component_name ) {
    632     if ( !$activity_ids_deleted = BP_Activity_Activity::delete_for_user_by_component( $user_id, $component_name ) )
    633         return false;
    634 
    635     do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component_name );
     659function bp_activity_delete_for_user_by_component( $user_id, $component ) {
     660    if ( !$activity_ids_deleted = BP_Activity_Activity::delete_for_user_by_component( $user_id, $component ) )
     661        return false;
     662
     663    do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component );
    636664    do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
    637665
     
    645673        $activity_obj = new BP_Activity_Activity( $activity_id );
    646674
    647     if ( 'new_blog_post' == $activity_obj->component_action || 'new_blog_comment' == $activity_obj->component_action || 'new_forum_topic' == $activity_obj->component_action || 'new_forum_post' == $activity_obj->component_action )
     675    if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type )
    648676        $link = $activity_obj->primary_link;
    649677    else {
    650         if ( 'activity_comment' == $activity_obj->component_action )
     678        if ( 'activity_comment' == $activity_obj->type )
    651679            $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
    652680        else
     
    682710}
    683711
     712function bp_activity_thumbnail_images( $content ) {
     713    preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
     714    $content = preg_replace('/<img[^>]*>/Ui', '', $content );
     715
     716    if ( !empty( $matches ) ) {
     717        /* Get the SRC value */
     718        preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
     719
     720        if ( !empty( $src ) ) {
     721            $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
     722            $pos = strpos( $content, '<blockquote>' );
     723            $before = substr( $content, 0, (int) $pos );
     724            $after = substr( $content, (int) $pos, strlen( $content ) );
     725
     726            $content = $before . '<img src="' . esc_attr( $src) . '" width="100" height="100" alt="thumb" class="align-left thumbnail" />' . $after;
     727        }
     728    }
     729
     730    return $content;
     731}
     732
    684733function bp_activity_set_action( $component_id, $key, $value ) {
    685734    global $bp;
Note: See TracChangeset for help on using the changeset viewer.