Skip to:
Content

BuddyPress.org

Ticket #3856: 3856.03--no-prefix.patch

File 3856.03--no-prefix.patch, 56.8 KB (added by imath, 10 years ago)
  • bp-activity/bp-activity-classes.php

    diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
    index 6876663..04fb1c4 100644
    class BP_Activity_Activity { 
    161161                        $this->mptt_right        = $row->mptt_right;
    162162                        $this->is_spam           = $row->is_spam;
    163163                }
     164
     165                $action = bp_activity_generate_action_string( $this );
     166
     167                if ( $action ) {
     168                        $this->action = $action;
     169                }
    164170        }
    165171
    166172        /**
    class BP_Activity_Activity { 
    442448                if ( $activities && $display_comments )
    443449                        $activities = BP_Activity_Activity::append_comments( $activities, $spam );
    444450
     451                // Pre-fetch data associated with activity users and other objects
     452                BP_Activity_Activity::prefetch_object_data( $activities );
     453
     454                // Generate action strings
     455                $activities = BP_Activity_Activity::generate_action_strings( $activities );
     456
    445457                // If $max is set, only return up to the max results
    446458                if ( !empty( $max ) ) {
    447459                        if ( (int) $total_activities > (int) $max )
    class BP_Activity_Activity { 
    559571        }
    560572
    561573        /**
     574         * Pre-fetch data for objects associated with activity items.
     575         *
     576         * Activity items are associated with users, and often with other
     577         * BuddyPress data objects. Here, we pre-fetch data about these
     578         * associated objects, so that inline lookups - done primarily when
     579         * building action strings - do not result in excess database queries.
     580         *
     581         * The only object data required for activity component activity types
     582         * (activity_update and activity_comment) is related to users, and that
     583         * info is fetched separately in BP_Activity_Activity::get_activity_data().
     584         * So this method contains nothing but a filter that allows other
     585         * components, such as bp-friends and bp-groups, to hook in and prime
     586         * their own caches at the beginning of an activity loop.
     587         *
     588         * @since BuddyPress (2.0.0)
     589         *
     590         * @param array $activities Array of activities.
     591         */
     592        protected static function prefetch_object_data( $activities ) {
     593                return apply_filters( 'bp_activity_prefetch_object_data', $activities );
     594        }
     595
     596        /**
     597         * Generate action strings for the activities located in BP_Activity_Activity::get().
     598         *
     599         * @since BuddyPress (2.0.0)
     600         *
     601         * @param array $activities Array of activities.
     602         * @return array
     603         */
     604        protected static function generate_action_strings( $activities ) {
     605                foreach ( $activities as $key => $activity ) {
     606                        $generated_action = bp_activity_generate_action_string( $activity );
     607                        if ( false !== $generated_action ) {
     608                                $activity->action = $generated_action;
     609                        }
     610
     611                        $activities[ $key ] = $activity;
     612                }
     613
     614                return $activities;
     615        }
     616
     617        /**
    562618         * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().
    563619         *
    564620         * We use WP_Meta_Query to do the heavy lifting of parsing the
  • bp-activity/bp-activity-functions.php

    diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php
    index cb062f9..7fde206 100644
    function bp_activity_get_userid_from_mentionname( $mentionname ) { 
    266266 * @param string $component_id The unique string ID of the component.
    267267 * @param string $key The action key.
    268268 * @param string $value The action value.
     269 * @param callable $format_callback Callback for formatting the action string.
    269270 * @return bool False if any param is empty, otherwise true.
    270271 */
    271 function bp_activity_set_action( $component_id, $key, $value ) {
     272function bp_activity_set_action( $component_id, $key, $value, $format_callback = false ) {
    272273        global $bp;
    273274
    274275        // Return false if any of the above values are not set
    275         if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
     276        if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) {
    276277                return false;
     278        }
    277279
    278280        // Set activity action
    279281        if ( !isset( $bp->activity->actions ) || !is_object( $bp->activity->actions ) ) {
    280282                $bp->activity->actions = new stdClass;
    281283        }
    282284
     285        // Verify callback
     286        if ( ! is_callable( $format_callback ) ) {
     287                $format_callback = '';
     288        }
     289
    283290        if ( !isset( $bp->activity->actions->{$component_id} ) || !is_object( $bp->activity->actions->{$component_id} ) ) {
    284291                $bp->activity->actions->{$component_id} = new stdClass;
    285292        }
    286293
    287294        $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
    288                 'key'   => $key,
    289                 'value' => $value
     295                'key'             => $key,
     296                'value'           => $value,
     297                'format_callback' => $format_callback,
    290298        ), $component_id, $key, $value );
    291299
    292300        return true;
    add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' ); 
    857865function bp_activity_register_activity_actions() {
    858866        global $bp;
    859867
    860         bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) );
    861         bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) );
     868        bp_activity_set_action(
     869                $bp->activity->id,
     870                'activity_update',
     871                __( 'Posted a status update', 'buddypress' ),
     872                'bp_activity_format_activity_action_activity_update'
     873        );
     874
     875        bp_activity_set_action(
     876                $bp->activity->id,
     877                'activity_comment',
     878                __( 'Replied to a status update', 'buddypress' ),
     879                'bp_activity_format_activity_action_activity_comment'
     880        );
    862881
    863882        do_action( 'bp_activity_register_activity_actions' );
    864883
    function bp_activity_register_activity_actions() { 
    867886}
    868887add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' );
    869888
     889/**
     890 * Generate an activity action string for an activity item.
     891 *
     892 * @param object $activity Activity data object.
     893 * @return string|bool Returns false if no callback is found, otherwise returns
     894 *         the formatted action string.
     895 */
     896function bp_activity_generate_action_string( $activity ) {
     897        // Check for valid input
     898        if ( empty( $activity->component ) || empty( $activity->type ) ) {
     899                return false;
     900        }
     901
     902        // Check for registered format callback
     903        if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
     904                return false;
     905        }
     906
     907        return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity );
     908}
     909
     910/**
     911 * Format 'activity_update' activity actions.
     912 *
     913 * @since BuddyPress (2.0.0)
     914 *
     915 * @param object $activity Activity data object.
     916 * @return string
     917 */
     918function bp_activity_format_activity_action_activity_update( $activity ) {
     919        $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     920        return apply_filters( 'bp_activity_new_update_action', $action, $activity );
     921}
     922
     923/**
     924 * Format 'activity_comment' activity actions.
     925 *
     926 * @since BuddyPress (2.0.0)
     927 *
     928 * @param object $activity Activity data object.
     929 * @return string
     930 */
     931function bp_activity_format_activity_action_activity_comment( $activity ) {
     932        $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     933        return apply_filters( 'bp_activity_comment_action', $action, $activity );
     934}
     935
    870936/******************************************************************************
    871937 * Business functions are where all the magic happens in BuddyPress. They will
    872938 * handle the actual saving or manipulation of information. Usually they will
    function bp_activity_add( $args = '' ) { 
    10871153        $activity->user_id           = $user_id;
    10881154        $activity->component         = $component;
    10891155        $activity->type              = $type;
    1090         $activity->action            = $action;
    10911156        $activity->content           = $content;
    10921157        $activity->primary_link      = $primary_link;
    10931158        $activity->item_id           = $item_id;
    function bp_activity_add( $args = '' ) { 
    10951160        $activity->date_recorded     = $recorded_time;
    10961161        $activity->hide_sitewide     = $hide_sitewide;
    10971162        $activity->is_spam           = $is_spam;
     1163        $activity->action            = ! empty( $action ) ? $action : bp_activity_generate_action_string( $activity );
    10981164
    10991165        if ( !$activity->save() )
    11001166                return false;
    function bp_activity_post_update( $args = '' ) { 
    11501216
    11511217        // Record this on the user's profile
    11521218        $from_user_link   = bp_core_get_userlink( $user_id );
    1153         $activity_action  = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );
    11541219        $activity_content = $content;
    11551220        $primary_link     = bp_core_get_userlink( $user_id, false, true );
    11561221
    11571222        // Now write the values
    11581223        $activity_id = bp_activity_add( array(
    11591224                'user_id'      => $user_id,
    1160                 'action'       => apply_filters( 'bp_activity_new_update_action', $activity_action ),
    11611225                'content'      => apply_filters( 'bp_activity_new_update_content', $activity_content ),
    11621226                'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
    11631227                'component'    => $bp->activity->id,
    1164                 'type'         => 'activity_update'
     1228                'type'         => 'activity_update',
    11651229        ) );
    11661230
    11671231        $activity_content = apply_filters( 'bp_activity_latest_update_content', $content, $activity_content );
    function bp_activity_new_comment( $args = '' ) { 
    12301294        // Insert the activity comment
    12311295        $comment_id = bp_activity_add( array(
    12321296                'id'                => $id,
    1233                 'action'            => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
    12341297                'content'           => apply_filters( 'bp_activity_comment_content', $content ),
    12351298                'component'         => buddypress()->activity->id,
    12361299                'type'              => 'activity_comment',
  • bp-blogs/bp-blogs-activity.php

    diff --git bp-blogs/bp-blogs-activity.php bp-blogs/bp-blogs-activity.php
    index 70c41c6..49b58ce 100644
    function bp_blogs_register_activity_actions() { 
    2828        }
    2929
    3030        if ( is_multisite() ) {
    31                 bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created',        'buddypress' ) );
     31                bp_activity_set_action(
     32                        $bp->blogs->id,
     33                        'new_blog',
     34                        __( 'New site created', 'buddypress' ),
     35                        'bp_blogs_format_activity_action_new_blog'
     36                );
    3237        }
    3338
    34         bp_activity_set_action( $bp->blogs->id, 'new_blog_post',    __( 'New post published',      'buddypress' ) );
    35         bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New post comment posted', 'buddypress' ) );
     39        bp_activity_set_action(
     40                $bp->blogs->id,
     41                'new_blog_post',
     42                __( 'New post published', 'buddypress' ),
     43                'bp_blogs_format_activity_action_new_blog_post'
     44        );
     45
     46        bp_activity_set_action(
     47                $bp->blogs->id,
     48                'new_blog_comment',
     49                __( 'New post comment posted', 'buddypress' ),
     50                'bp_blogs_format_activity_action_new_blog_comment'
     51        );
    3652
    3753        do_action( 'bp_blogs_register_activity_actions' );
    3854}
    3955add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
    4056
    4157/**
     58 * Format 'new_blog' activity actions.
     59 *
     60 * @since BuddyPress (2.0.0)
     61 *
     62 * @param obj $activity Activity data object.
     63 */
     64function bp_blogs_format_activity_action_new_blog( $activity ) {
     65        $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     66        $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     67
     68        $action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     69
     70        // Legacy filter - requires the BP_Blogs_Blog object
     71        if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) {
     72                $user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id );
     73                if ( $user_blog ) {
     74                        $recorded_blog = new BP_Blogs_Blog( $user_blog );
     75                }
     76
     77                if ( isset( $recorded_blog ) ) {
     78                        $action = apply_filters( 'bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta( $activity->item_id, 'description' ) );
     79                }
     80        }
     81
     82        return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity );
     83}
     84
     85/**
     86 * Format 'new_blog_post' activity actions.
     87 *
     88 * @since BuddyPress (2.0.0)
     89 *
     90 * @param obj $activity Activity data object.
     91 */
     92function bp_blogs_format_activity_action_new_blog_post( $activity ) {
     93        $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     94        $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     95
     96        if ( empty( $blog_url ) || empty( $blog_name ) ) {
     97                $blog_url  = get_home_url( $activity->item_id );
     98                $blog_name = get_blog_option( $activity->item_id, 'blogname' );
     99
     100                bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url );
     101                bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
     102        }
     103
     104        $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
     105
     106        $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     107
     108        // Should only be empty at the time of post creation
     109        if ( empty( $post_title ) ) {
     110                switch_to_blog( $activity->item_id );
     111
     112                $post = get_post( $activity->secondary_item_id );
     113                if ( is_a( $post, 'WP_Post' ) ) {
     114                        $post_title = $post->post_title;
     115                        bp_activity_update_meta( $activity->id, 'post_title', $post_title );
     116                }
     117
     118                restore_current_blog();
     119        }
     120
     121        $post_link  = '<a href="' . $post_url . '">' . $post_title . '</a>';
     122
     123        $user_link = bp_core_get_userlink( $activity->user_id );
     124
     125        if ( is_multisite() ) {
     126                $action  = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     127        } else {
     128                $action  = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), $user_link, $post_link );
     129        }
     130
     131        // Legacy filter - requires the post object
     132        if ( has_filter( 'bp_blogs_activity_new_post_action' ) ) {
     133                switch_to_blog( $activity->item_id );
     134                $post = get_post( $activity->secondary_item_id );
     135                restore_current_blog();
     136
     137                if ( ! empty( $post ) && ! is_wp_error( $post ) ) {
     138                        $action = apply_filters( 'bp_blogs_activity_new_post_action', $action, $post, $post_url );
     139                }
     140        }
     141
     142        return apply_filters( 'bp_blogs_format_activity_action_new_blog_post', $action, $activity );
     143}
     144
     145/**
     146 * Format 'new_blog_comment' activity actions.
     147 *
     148 * @since BuddyPress (2.0.0)
     149 *
     150 * @param obj $activity Activity data object.
     151 */
     152function bp_blogs_format_activity_action_new_blog_comment( $activity ) {
     153        $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     154        $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     155
     156        if ( empty( $blog_url ) || empty( $blog_name ) ) {
     157                $blog_url  = get_home_url( $activity->item_id );
     158                $blog_name = get_blog_option( $activity->item_id, 'blogname' );
     159
     160                bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url );
     161                bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
     162        }
     163
     164        $post_url   = bp_activity_get_meta( $activity->id, 'post_url' );
     165        $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     166
     167        // Should only be empty at the time of post creation
     168        if ( empty( $post_url ) || empty( $post_title ) ) {
     169                switch_to_blog( $activity->item_id );
     170
     171                $comment = get_comment( $activity->secondary_item_id );
     172
     173                if ( ! empty( $comment->comment_post_ID ) ) {
     174                        $post_url = add_query_arg( 'p', $comment->comment_post_ID, trailingslashit( $blog_url ) );
     175                        bp_activity_update_meta( $activity->id, 'post_url', $post_url );
     176
     177                        $post = get_post( $comment->comment_post_ID );
     178
     179                        if ( is_a( $post, 'WP_Post' ) ) {
     180                                $post_title = $post->post_title;
     181                                bp_activity_update_meta( $activity->id, 'post_title', $post_title );
     182                        }
     183                }
     184
     185                restore_current_blog();
     186        }
     187
     188        $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     189        $user_link = bp_core_get_userlink( $activity->user_id );
     190
     191        if ( is_multisite() ) {
     192                $action  = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     193        } else {
     194                $action  = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), $user_link, $post_link );
     195        }
     196
     197        // Legacy filter - requires the comment object
     198        if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) {
     199                switch_to_blog( $activity->item_id );
     200                $comment = get_comment( $activity->secondary_item_id );
     201                restore_current_blog();
     202
     203                if ( ! empty( $comment ) && ! is_wp_error( $comment ) ) {
     204                        $action = apply_filters( 'bp_blogs_activity_new_comment_action', $action, $comment, $post_url . '#' . $activity->secondary_item_id );
     205                }
     206        }
     207
     208        return apply_filters( 'bp_blogs_format_activity_action_new_blog_comment', $action, $activity );
     209}
     210
     211/**
     212 * Fetch data related to blogs at the beginning of an activity loop.
     213 *
     214 * This reduces database overhead during the activity loop.
     215 *
     216 * @since BuddyPress (2.0.0)
     217 *
     218 * @param array $activities Array of activity items.
     219 * @return array
     220 */
     221function bp_blogs_prefetch_activity_object_data( $activities ) {
     222        if ( empty( $activities ) ) {
     223                return $activities;
     224        }
     225
     226        $blog_ids = array();
     227
     228        foreach ( $activities as $activity ) {
     229                if ( buddypress()->blogs->id !== $activity->component ) {
     230                        continue;
     231                }
     232
     233                $blog_ids[] = $activity->item_id;
     234        }
     235
     236        if ( ! empty( $blog_ids ) ) {
     237                bp_blogs_update_meta_cache( $blog_ids );
     238        }
     239}
     240add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_object_data' );
     241/**
    42242 * Record blog-related activity to the activity stream.
    43243 *
    44244 * @since BuddyPress (1.0.0)
  • bp-blogs/bp-blogs-classes.php

    diff --git bp-blogs/bp-blogs-classes.php bp-blogs/bp-blogs-classes.php
    index 160a000..956fbb8 100644
    class BP_Blogs_Blog { 
    503503
    504504                return false;
    505505        }
     506
     507        /**
     508         * Get ID of user-blog link.
     509         *
     510         * @param int $user_id ID of user.
     511         * @param int $blog_id ID of blog.
     512         * @return int|bool ID of user-blog link, or false if not found.
     513         */
     514        public static function get_user_blog( $user_id, $blog_id ) {
     515                global $bp, $wpdb;
     516
     517                $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
     518
     519                if ( empty( $user_blog ) ) {
     520                        $user_blog = false;
     521                } else {
     522                        $user_blog = intval( $user_blog );
     523                }
     524
     525                return $user_blog;
     526        }
    506527}
  • bp-blogs/bp-blogs-functions.php

    diff --git bp-blogs/bp-blogs-functions.php bp-blogs/bp-blogs-functions.php
    index e9ba275..c81747c 100644
    function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 
    182182        if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) )
    183183                return false;
    184184
     185        $url         = get_home_url( $blog_id );
    185186        $name        = get_blog_option( $blog_id, 'blogname' );
    186187        $description = get_blog_option( $blog_id, 'blogdescription' );
    187188
    function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 
    194195        $recorded_blog_id       = $recorded_blog->save();
    195196        $is_recorded            = !empty( $recorded_blog_id ) ? true : false;
    196197
     198        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url );
    197199        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    198200        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    199201        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
    function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 
    207209                // Record this in activity streams
    208210                bp_blogs_record_activity( array(
    209211                        'user_id'      => $recorded_blog->user_id,
    210                         'action'       => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the site %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_home_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), $recorded_blog, $name, $description ),
    211                         'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_home_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
     212                        'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', $url, $recorded_blog->blog_id ),
    212213                        'type'         => 'new_blog',
    213214                        'item_id'      => $recorded_blog->blog_id
    214215                ) );
    function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) { 
    355356
    356357                        bp_blogs_record_activity( array(
    357358                                'user_id'           => (int) $post->post_author,
    358                                 'action'            => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ),
    359359                                'content'           => apply_filters( 'bp_blogs_activity_new_post_content',      $activity_content, $post, $post_permalink ),
    360360                                'primary_link'      => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink,   $post_id               ),
    361361                                'type'              => 'new_blog_post',
    function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 
    450450                // Record in activity streams
    451451                bp_blogs_record_activity( array(
    452452                        'user_id'           => $user_id,
    453                         'action'            => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action',       array( $activity_action,  &$recorded_comment, $comment_link ) ),
    454453                        'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    455454                        'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
    456455                        'type'              => 'new_blog_comment',
  • bp-friends/bp-friends-activity.php

    diff --git bp-friends/bp-friends-activity.php bp-friends/bp-friends-activity.php
    index 7b7be59..e0cfba1 100644
    function friends_register_activity_actions() { 
    9292        $bp = buddypress();
    9393
    9494        // These two added in BP 1.6
    95         bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) );
    96         bp_activity_set_action( $bp->friends->id, 'friendship_created',  __( 'New friendships',      'buddypress' ) );
     95        bp_activity_set_action(
     96                $bp->friends->id,
     97                'friendship_accepted',
     98                __( 'Friendships accepted', 'buddypress' ),
     99                'bp_friends_format_activity_action_friendship_accepted'
     100        );
     101
     102        bp_activity_set_action(
     103                $bp->friends->id,
     104                'friendship_created',
     105                __( 'New friendships', 'buddypress' ),
     106                'bp_friends_format_activity_action_friendship_created'
     107        );
    97108
    98109        // < BP 1.6 backpat
    99110        bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
    function friends_register_activity_actions() { 
    103114add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
    104115
    105116/**
     117 * Format 'friendship_accepted' activity actions.
     118 *
     119 * @since BuddyPress (2.0.0)
     120 *
     121 * @param object $activity Activity data.
     122 * @return string $action Formatted activity action.
     123 */
     124function bp_friends_format_activity_action_friendship_accepted( $activity ) {
     125        $initiator_link = bp_core_get_userlink( $activity->user_id );
     126        $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
     127
     128        $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link );
     129
     130        // Backward compatibility for legacy filter
     131        // The old filter has the $friendship object passed to it. We want to
     132        // avoid having to build this object if it's not necessary
     133        if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
     134                $friendship = new BP_Friends_Friendship( $activity->item_id );
     135                $action     = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship );
     136        }
     137
     138        return apply_filters( 'bp_friends_format_activity_action_friendship_accepted', $action, $activity );
     139}
     140
     141/**
     142 * Format 'friendship_created' activity actions.
     143 *
     144 * @since BuddyPress (2.0.0)
     145 *
     146 * @param object $activity Activity data.
     147 * @return string $action Formatted activity action.
     148 */
     149function bp_friends_format_activity_action_friendship_created( $activity ) {
     150        $initiator_link = bp_core_get_userlink( $activity->user_id );
     151        $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
     152
     153        $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link );
     154
     155        // Backward compatibility for legacy filter
     156        // The old filter has the $friendship object passed to it. We want to
     157        // avoid having to build this object if it's not necessary
     158        if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
     159                $friendship = new BP_Friends_Friendship( $activity->item_id );
     160                $action     = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship );
     161        }
     162
     163        return apply_filters( 'bp_friends_format_activity_action_friendship_created', $action, $activity );
     164}
     165
     166/**
     167 * Fetch data related to friended users at the beginning of an activity loop.
     168 *
     169 * This reduces database overhead during the activity loop.
     170 *
     171 * @since BuddyPress (2.0.0)
     172 *
     173 * @param array $activities Array of activity items.
     174 * @return array
     175 */
     176function bp_friends_prefetch_activity_object_data( $activities ) {
     177        if ( empty( $activities ) ) {
     178                return $activities;
     179        }
     180
     181        $friend_ids = array();
     182
     183        foreach ( $activities as $activity ) {
     184                if ( buddypress()->friends->id !== $activity->component ) {
     185                        continue;
     186                }
     187
     188                $friend_ids[] = $activity->secondary_item_id;
     189        }
     190
     191        if ( ! empty( $friend_ids ) ) {
     192                // Fire a user query to prime user caches
     193                new BP_User_Query( array(
     194                        'user_ids'          => $friend_ids,
     195                        'populate_extras'   => false,
     196                        'update_meta_cache' => false,
     197                ) );
     198        }
     199}
     200add_filter( 'bp_activity_prefetch_object_data', 'bp_friends_prefetch_activity_object_data' );
     201
     202/**
    106203 * Add activity stream items when one members accepts another members request
    107204 * for virtual friendship.
    108205 *
    function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_use 
    128225        friends_record_activity( array(
    129226                'user_id'           => $initiator_user_id,
    130227                'type'              => 'friendship_created',
    131                 'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ),
    132228                'item_id'           => $friendship_id,
    133229                'secondary_item_id' => $friend_user_id
    134230        ) );
    function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_use 
    137233        friends_record_activity( array(
    138234                'user_id'           => $friend_user_id,
    139235                'type'              => 'friendship_created',
    140                 'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ),
    141236                'item_id'           => $friendship_id,
    142237                'secondary_item_id' => $initiator_user_id,
    143238                'hide_sitewide'     => true // We've already got the first entry site wide
  • bp-groups/bp-groups-actions.php

    diff --git bp-groups/bp-groups-actions.php bp-groups/bp-groups-actions.php
    index b81d244..38fb4e2 100644
    function groups_action_create_group() { 
    150150
    151151                        // Once we compelete all steps, record the group creation in the activity stream.
    152152                        groups_record_activity( array(
    153                                 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
    154153                                'type' => 'created_group',
    155154                                'item_id' => $bp->groups->new_group_id
    156155                        ) );
  • bp-groups/bp-groups-activity.php

    diff --git bp-groups/bp-groups-activity.php bp-groups/bp-groups-activity.php
    index 324064c..62e558b 100644
    function groups_register_activity_actions() { 
    2323                return false;
    2424        }
    2525
    26         bp_activity_set_action( $bp->groups->id, 'created_group',   __( 'Created a group',       'buddypress' ) );
    27         bp_activity_set_action( $bp->groups->id, 'joined_group',    __( 'Joined a group',        'buddypress' ) );
     26        bp_activity_set_action(
     27                $bp->groups->id,
     28                'created_group',
     29                __( 'Created a group', 'buddypress' ),
     30                'bp_groups_format_activity_action_created_group'
     31        );
     32
     33        bp_activity_set_action(
     34                $bp->groups->id,
     35                'joined_group',
     36                __( 'Joined a group', 'buddypress' ),
     37                'bp_groups_format_activity_action_joined_group'
     38        );
    2839
    2940        // These actions are for the legacy forums
    3041        // Since the bbPress plugin also shares the same 'forums' identifier, we also
    function groups_register_activity_actions() { 
    3950add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' );
    4051
    4152/**
     53 * Format 'created_group' activity actions.
     54 *
     55 * @since BuddyPress (2.0.0)
     56 *
     57 * @param object $activity Activity data object.
     58 * @return string
     59 */
     60function bp_groups_format_activity_action_created_group( $activity ) {
     61        $user_link = bp_core_get_userlink( $activity->user_id );
     62
     63        $group = groups_get_group( array(
     64                'group_id'        => $activity->item_id,
     65                'populate_extras' => false,
     66        ) );
     67        $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
     68
     69        $action = sprintf( __( '%1$s created the group %2$s', 'buddypress'), $user_link, $group_link );
     70
     71        return apply_filters( 'groups_activity_created_group_action', $action, $activity );
     72}
     73
     74/**
     75 * Format 'joined_group' activity actions.
     76 *
     77 * @since BuddyPress (2.0.0)
     78 *
     79 * @param object $activity Activity data object.
     80 * @return string
     81 */
     82function bp_groups_format_activity_action_joined_group( $activity ) {
     83        $user_link = bp_core_get_userlink( $activity->user_id );
     84
     85        $group = groups_get_group( array(
     86                'group_id'        => $activity->item_id,
     87                'populate_extras' => false,
     88        ) );
     89        $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
     90
     91        $action = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link );
     92
     93        // Legacy filters (do not follow parameter patterns of other activity
     94        // action filters, and requires apply_filters_ref_array())
     95        if ( has_filter( 'groups_activity_membership_accepted_action' ) ) {
     96                $action = apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( $action, $user_link, &$group ) );
     97        }
     98
     99        // Another legacy filter
     100        if ( has_filter( 'groups_activity_accepted_invite_action' ) ) {
     101                $action = apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( $action, $activity->user_id, &$group ) );
     102        }
     103
     104        return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity );
     105}
     106
     107/**
     108 * Fetch data related to groups at the beginning of an activity loop.
     109 *
     110 * This reduces database overhead during the activity loop.
     111 *
     112 * @since BuddyPress (2.0.0)
     113 *
     114 * @param array $activities Array of activity items.
     115 * @return array
     116 */
     117function bp_groups_prefetch_activity_object_data( $activities ) {
     118        $group_ids = array();
     119
     120        if ( empty( $activities ) ) {
     121                return $activities;
     122        }
     123
     124        foreach ( $activities as $activity ) {
     125                if ( buddypress()->groups->id !== $activity->component ) {
     126                        continue;
     127                }
     128
     129                $group_ids[] = $activity->item_id;
     130        }
     131
     132        if ( ! empty( $group_ids ) ) {
     133
     134                // TEMPORARY - Once the 'populate_extras' issue is solved
     135                // in the groups component, we can do this with groups_get_groups()
     136                // rather than manually
     137                $uncached_ids = array();
     138                foreach ( $group_ids as $group_id ) {
     139                        if ( false === wp_cache_get( $group_id, 'bp_groups' ) ) {
     140                                $uncached_ids[] = $group_id;
     141                        }
     142                }
     143
     144                global $wpdb, $bp;
     145                $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
     146                $groups = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name} WHERE id IN ({$uncached_ids_sql})" );
     147                foreach ( $groups as $group ) {
     148                        wp_cache_set( $group->id, $group, 'bp_groups' );
     149                }
     150        }
     151}
     152add_filter( 'bp_activity_prefetch_object_data', 'bp_groups_prefetch_activity_object_data' );
     153
     154/**
    42155 * Record an activity item related to the Groups component.
    43156 *
    44157 * A wrapper for {@link bp_activity_add()} that provides some Groups-specific
    function bp_groups_membership_accepted_add_activity( $user_id, $group_id ) { 
    141254                'type'    => 'joined_group',
    142255                'item_id' => $group_id,
    143256                'user_id' => $user_id
    144         ) );   
     257        ) );
    145258}
    146259add_action( 'groups_membership_accepted', 'bp_groups_membership_accepted_add_activity', 10, 2 );
    147260
    function bp_groups_leave_group_delete_recent_activity( $group_id, $user_id ) { 
    192305}
    193306add_action( 'groups_leave_group',   'bp_groups_leave_group_delete_recent_activity', 10, 2 );
    194307add_action( 'groups_remove_member', 'bp_groups_leave_group_delete_recent_activity', 10, 2 );
    195 add_action( 'groups_ban_member',    'bp_groups_leave_group_delete_recent_activity', 10, 2 );
    196  No newline at end of file
     308add_action( 'groups_ban_member',    'bp_groups_leave_group_delete_recent_activity', 10, 2 );
  • bp-groups/bp-groups-functions.php

    diff --git bp-groups/bp-groups-functions.php bp-groups/bp-groups-functions.php
    index 251ae96..3f20225 100644
    function groups_join_group( $group_id, $user_id = 0 ) { 
    329329
    330330        // Record this in activity streams
    331331        groups_record_activity( array(
    332                 'action'  => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),
    333332                'type'    => 'joined_group',
    334333                'item_id' => $group_id,
    335                 'user_id' => $user_id
     334                'user_id' => $user_id,
    336335        ) );
    337336
    338337        // Modify group meta
  • bp-groups/bp-groups-screens.php

    diff --git bp-groups/bp-groups-screens.php bp-groups/bp-groups-screens.php
    index f461e6f..a0eadf4 100644
    function groups_screen_group_invites() { 
    4949                        $group = groups_get_group( array( 'group_id' => $group_id ) );
    5050
    5151                        groups_record_activity( array(
    52                                 'action'  => apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), bp_loggedin_user_id(), &$group ) ),
    5352                                'type'    => 'joined_group',
    5453                                'item_id' => $group->id
    5554                        ) );
  • bp-members/bp-members-functions.php

    diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
    index faa7a92..1a83816 100644
    function bp_core_new_user_activity( $user ) { 
    15531553
    15541554        bp_activity_add( array(
    15551555                'user_id'   => $user_id,
    1556                 'action'    => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
    15571556                'component' => 'xprofile',
    15581557                'type'      => 'new_member'
    15591558        ) );
  • bp-xprofile/bp-xprofile-activity.php

    diff --git bp-xprofile/bp-xprofile-activity.php bp-xprofile/bp-xprofile-activity.php
    index b901d91..9298ca8 100644
    function xprofile_register_activity_actions() { 
    1717        global $bp;
    1818
    1919        // Register the activity stream actions for this component
    20         bp_activity_set_action( $bp->profile->id, 'new_avatar',      __( 'Member changed profile picture', 'buddypress' ) );
    21         bp_activity_set_action( $bp->profile->id, 'new_member',      __( 'New member registered', 'buddypress' ) );
    22         bp_activity_set_action( $bp->profile->id, 'updated_profile', __( 'Updated Profile', 'buddypress' ) );
     20        bp_activity_set_action(
     21                $bp->profile->id,
     22                'new_avatar',
     23                __( 'Member changed profile picture', 'buddypress' ),
     24                'bp_xprofile_format_activity_action_new_avatar'
     25        );
     26
     27        bp_activity_set_action(
     28                $bp->profile->id,
     29                'new_member',
     30                __( 'New member registered', 'buddypress' ),
     31                'bp_xprofile_format_activity_action_new_member'
     32        );
     33
     34        bp_activity_set_action(
     35                $bp->profile->id,
     36                'updated_profile',
     37                __( 'Updated Profile', 'buddypress' ),
     38                'bp_xprofile_format_activity_action_updated_profile'
     39        );
    2340
    2441        do_action( 'xprofile_register_activity_actions' );
    2542}
    2643add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' );
    2744
    2845/**
     46 * Format 'new_avatar' activity actions.
     47 *
     48 * @since BuddyPress (2.0.0)
     49 *
     50 * @param object $activity Activity object.
     51 * @return string
     52 */
     53function bp_xprofile_format_activity_action_new_avatar( $activity ) {
     54        $userlink = bp_core_get_userlink( $activity->user_id );
     55        $action   = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink );
     56
     57        // Legacy filter - pass $user_id instead of $activity
     58        if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
     59                $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
     60        }
     61
     62        return apply_filters( 'bp_xprofile_format_activity_action_new_avatar', $action, $activity );
     63}
     64
     65/**
     66 * Format 'new_member' activity actions.
     67 *
     68 * @since BuddyPress (2.0.0)
     69 *
     70 * @param object $activity Activity object.
     71 * @return string
     72 */
     73function bp_xprofile_format_activity_action_new_member( $activity ) {
     74        $userlink = bp_core_get_userlink( $activity->user_id );
     75        $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
     76
     77        // Legacy filter - pass $user_id instead of $activity
     78        if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
     79                $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
     80        }
     81
     82        return apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
     83}
     84
     85/**
     86 * Format 'updated_profile' activity actions.
     87 *
     88 * @since BuddyPress (2.0.0)
     89 *
     90 * @param object $activity Activity object.
     91 * @return string
     92 */
     93function bp_xprofile_format_activity_action_updated_profile( $activity ) {
     94        // Note for translators: The natural phrasing in English, "Joe updated
     95        // his profile", requires that we know Joe's gender, which we don't. If
     96        // your language doesn't have this restriction, feel free to use a more
     97        // natural translation.
     98        $profile_link = trailingslashit( bp_core_get_user_domain( $activity->user_id ) . buddypress()->profile->slug );
     99        $action       = sprintf( __( '%1$s&#8217;s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $activity->user_id ) . '</a>' );
     100
     101        return apply_filters( 'bp_xprofile_format_activity_action_updated_profile', $action, $activity );
     102}
     103
     104/**
    29105 * Records activity for the logged in user within the profile component so that
    30106 * it will show in the users activity stream (if installed)
    31107 *
    function bp_xprofile_new_avatar_activity() { 
    126202
    127203        bp_activity_add( array(
    128204                'user_id' => $user_id,
    129                 'action' => apply_filters( 'bp_xprofile_new_avatar_action', sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ), $user_id ),
    130205                'component' => 'profile',
    131206                'type' => 'new_avatar'
    132207        ) );
    function bp_xprofile_updated_profile_activity( $user_id, $field_ids, $errors, $o 
    207282        }
    208283
    209284        // If we've reached this point, assemble and post the activity item
    210 
    211         // Note for translators: The natural phrasing in English, "Joe updated
    212         // his profile", requires that we know Joe's gender, which we don't. If
    213         // your language doesn't have this restriction, feel free to use a more
    214         // natural translation.
    215285        $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug );
    216         $action = sprintf( __( '%1$s&#8217;s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $user_id ) . '</a>' );
    217286
    218287        $retval = xprofile_record_activity( array(
    219288                'user_id'      => $user_id,
    220                 'action'       => $action,
    221289                'primary_link' => $profile_link,
    222290                'component'    => buddypress()->profile->id,
    223291                'type'         => 'updated_profile',
  • tests/includes/factory.php

    diff --git tests/includes/factory.php tests/includes/factory.php
    index 317e58d..6b32872 100644
    class BP_UnitTest_Factory_For_Activity extends WP_UnitTest_Factory_For_Thing { 
    1919                parent::__construct( $factory );
    2020
    2121                $this->default_generation_definitions = array(
    22                         'action'       => new WP_UnitTest_Generator_Sequence( 'Activity action %s' ),
    2322                        'component'    => buddypress()->activity->id,
    2423                        'content'      => new WP_UnitTest_Generator_Sequence( 'Activity content %s' ),
    2524                        'primary_link' => 'http://example.com',
  • tests/testcases/activity/functions.php

    diff --git tests/testcases/activity/functions.php tests/testcases/activity/functions.php
    index 24a7dd5..b89a699 100644
    Bar!'; 
    540540                remove_filter( 'bp_is_username_compatibility_mode', '__return_true' );
    541541        }
    542542
     543        /**
     544         * @group activity_action
     545         * @group bp_activity_format_activity_action_activity_update
     546         */
     547        public function test_bp_activity_format_activity_action_activity_update() {
     548                $u = $this->create_user();
     549                $a = $this->factory->activity->create( array(
     550                        'component' => buddypress()->activity->id,
     551                        'type' => 'activity_update',
     552                        'user_id' => $u,
     553                ) );
     554
     555                $a_obj = new BP_Activity_Activity( $a );
     556
     557                $expected = sprintf( '%s posted an update', bp_core_get_userlink( $u ) );
     558
     559                $this->assertSame( $expected, $a_obj->action );
     560        }
     561
     562        /**
     563         * @group activity_action
     564         * @group bp_activity_format_activity_action_activity_comment
     565         */
     566        public function test_bp_activity_format_activity_action_activity_comment() {
     567                $u = $this->create_user();
     568                $a = $this->factory->activity->create( array(
     569                        'component' => buddypress()->activity->id,
     570                        'type' => 'activity_comment',
     571                        'user_id' => $u,
     572                ) );
     573
     574                $a_obj = new BP_Activity_Activity( $a );
     575
     576                $expected = sprintf( '%s posted a new activity comment', bp_core_get_userlink( $u ) );
     577
     578                $this->assertSame( $expected, $a_obj->action );
     579        }
     580
    543581}
  • tests/testcases/blogs/activity.php

    diff --git tests/testcases/blogs/activity.php tests/testcases/blogs/activity.php
    index e69de29..33b83e8 100644
     
     1<?php
     2
     3class BP_Tests_Blogs_Activity extends BP_UnitTestCase {
     4        /**
     5         * @group activity_action
     6         * @group bp_blogs_format_activity_action_new_blog
     7         */
     8        public function test_bp_blogs_format_activity_action_new_blog() {
     9                if ( ! is_multisite() ) {
     10                        return;
     11                }
     12
     13                $b = $this->factory->blog->create();
     14                $u = $this->create_user();
     15                $a = $this->factory->activity->create( array(
     16                        'component' => buddypress()->blogs->id,
     17                        'type' => 'new_blog',
     18                        'user_id' => $u,
     19                        'item_id' => $b,
     20                ) );
     21
     22                $a_obj = new BP_Activity_Activity( $a );
     23
     24                $expected = sprintf( '%s created the site %s', bp_core_get_userlink( $u ), '<a href="' . get_blog_option( $b, 'home' ) . '">' . get_blog_option( $b, 'blogname' ) . '</a>' );
     25
     26                $this->assertSame( $expected, $a_obj->action );
     27        }
     28
     29        /**
     30         * @group activity_action
     31         * @group bp_blogs_format_activity_action_new_blog_post
     32         */
     33        public function test_bp_blogs_format_activity_action_new_blog_post_nonms() {
     34                if ( is_multisite() ) {
     35                        return;
     36                }
     37
     38                $u = $this->create_user();
     39                $p = $this->factory->post->create( array(
     40                        'post_author' => $u,
     41                ) );
     42                $a = $this->factory->activity->create( array(
     43                        'component' => buddypress()->blogs->id,
     44                        'type' => 'new_blog_post',
     45                        'user_id' => $u,
     46                        'item_id' => 1,
     47                        'secondary_item_id' => $p,
     48                ) );
     49
     50                $a_obj = new BP_Activity_Activity( $a );
     51
     52                $user_link = bp_core_get_userlink( $u );
     53                $blog_url = get_home_url();
     54                $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
     55                $post_title = bp_activity_get_meta( $a, 'post_title' );
     56                $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     57
     58                $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
     59
     60                $this->assertSame( $expected, $a_obj->action );
     61        }
     62
     63        /**
     64         * @group activity_action
     65         * @group bp_blogs_format_activity_action_new_blog_post
     66         */
     67        public function test_bp_blogs_format_activity_action_new_blog_post_ms_rootblog() {
     68                if ( ! is_multisite() ) {
     69                        return;
     70                }
     71
     72                $u = $this->create_user();
     73                $p = $this->factory->post->create( array(
     74                        'post_author' => $u,
     75                ) );
     76                $a = $this->factory->activity->create( array(
     77                        'component' => buddypress()->blogs->id,
     78                        'type' => 'new_blog_post',
     79                        'user_id' => $u,
     80                        'item_id' => 1,
     81                        'secondary_item_id' => $p,
     82                ) );
     83
     84                $a_obj = new BP_Activity_Activity( $a );
     85
     86                $user_link = bp_core_get_userlink( $u );
     87                $blog_url = get_home_url();
     88                $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
     89                $post_title = bp_activity_get_meta( $a, 'post_title' );
     90                $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     91
     92                $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . bp_blogs_get_blogmeta( $a_obj->item_id, 'name' ) . '</a>' );
     93
     94                $this->assertSame( $expected, $a_obj->action );
     95        }
     96
     97        /**
     98         * @group activity_action
     99         * @group bp_blogs_format_activity_action_new_blog_post
     100         */
     101        public function test_bp_blogs_format_activity_action_new_blog_post_ms_nonrootblog() {
     102                if ( ! is_multisite() ) {
     103                        return;
     104                }
     105
     106                $b = $this->factory->blog->create();
     107                $u = $this->create_user();
     108
     109                switch_to_blog( $b );
     110                $p = $this->factory->post->create( array(
     111                        'post_author' => $u,
     112                ) );
     113                $p_obj = get_post( $p );
     114                restore_current_blog();
     115
     116                $a = $this->factory->activity->create( array(
     117                        'component' => buddypress()->blogs->id,
     118                        'type' => 'new_blog_post',
     119                        'user_id' => $u,
     120                        'item_id' => $b,
     121                        'secondary_item_id' => $p,
     122                ) );
     123
     124                $a_obj = new BP_Activity_Activity( $a );
     125
     126                $user_link = bp_core_get_userlink( $u );
     127                $blog_url = get_blog_option( $a_obj->item_id, 'home' );
     128                $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
     129                $post_title = $p_obj->post_title;
     130                $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     131
     132                $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     133
     134                $this->assertSame( $expected, $a_obj->action );
     135        }
     136
     137        /**
     138         * @group activity_action
     139         * @group bp_blogs_format_activity_action_new_blog_comment
     140         */
     141        public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() {
     142                if ( ! is_multisite() ) {
     143                        return;
     144                }
     145
     146                $b = $this->factory->blog->create();
     147                $u = $this->create_user();
     148
     149                switch_to_blog( $b );
     150                $p = $this->factory->post->create( array(
     151                        'post_author' => $u,
     152                ) );
     153                $p_obj = get_post( $p );
     154                $c = $this->factory->comment->create( array(
     155                        'comment_post_ID' => $p,
     156                ) );
     157                $c_obj = get_comment( $c );
     158                restore_current_blog();
     159
     160                $a = $this->factory->activity->create( array(
     161                        'component' => buddypress()->blogs->id,
     162                        'type' => 'new_blog_comment',
     163                        'user_id' => $u,
     164                        'item_id' => $b,
     165                        'secondary_item_id' => $c,
     166                ) );
     167
     168                $a_obj = new BP_Activity_Activity( $a );
     169
     170                $user_link = bp_core_get_userlink( $u );
     171                $blog_url = get_blog_option( $a_obj->item_id, 'home' );
     172                $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
     173                $post_title = $p_obj->post_title;
     174                $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     175
     176                $expected = sprintf( '%s commented on the post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     177
     178                $this->assertSame( $expected, $a_obj->action );
     179        }
     180
     181        /**
     182         * @group bp_blogs_format_activity_action_new_blog
     183         */
     184        public function test_bp_activity_format_activity_action_new_blog_backpat() {
     185                if ( ! is_multisite() ) {
     186                        return;
     187                }
     188
     189                add_filter( 'bp_blogs_activity_created_blog_action', array( $this, 'created_blog_passthrough' ), 10, 2 );
     190
     191                $b = $this->factory->blog->create();
     192                $u = $this->create_user();
     193
     194                $recorded_blog          = new BP_Blogs_Blog;
     195                $recorded_blog->user_id = $u;
     196                $recorded_blog->blog_id = $b;
     197                $recorded_blog_id       = $recorded_blog->save();
     198
     199                $a = $this->factory->activity->create( array(
     200                        'component' => buddypress()->blogs->id,
     201                        'type' => 'new_blog',
     202                        'user_id' => $u,
     203                        'item_id' => $b,
     204                ) );
     205
     206                $this->assertEquals( $this->userblog_id, $recorded_blog_id );
     207        }
     208
     209        /**
     210         * @group bp_blogs_format_activity_action_new_blog_post
     211         */
     212        public function test_bp_activity_format_activity_action_new_blog_post_backpat() {
     213                if ( ! is_multisite() ) {
     214                        return;
     215                }
     216
     217                add_filter( 'bp_blogs_activity_new_post_action', array( $this, 'new_post_passthrough' ), 10, 2 );
     218
     219                $b = $this->factory->blog->create();
     220
     221                switch_to_blog( $b );
     222                $p = $this->factory->post->create();
     223                restore_current_blog();
     224
     225                $u = $this->create_user();
     226                $a = $this->factory->activity->create( array(
     227                        'component' => buddypress()->blogs->id,
     228                        'type' => 'new_blog_post',
     229                        'user_id' => $u,
     230                        'item_id' => $b,
     231                        'secondary_item_id' => $p,
     232                ) );
     233
     234                $this->assertEquals( $this->post_id, $p );
     235        }
     236
     237        /**
     238         * @group bp_blogs_format_activity_action_new_blog_comment
     239         */
     240        public function test_bp_activity_format_activity_action_new_blog_comment_backpat() {
     241                if ( ! is_multisite() ) {
     242                        return;
     243                }
     244
     245                add_filter( 'bp_blogs_activity_new_comment_action', array( $this, 'new_comment_passthrough' ), 10, 2 );
     246
     247                $b = $this->factory->blog->create();
     248
     249                switch_to_blog( $b );
     250                $p = $this->factory->post->create();
     251                $c = $this->factory->comment->create( array(
     252                        'comment_post_ID' => $c,
     253                ) );
     254                restore_current_blog();
     255
     256                $u = $this->create_user();
     257                $a = $this->factory->activity->create( array(
     258                        'component' => buddypress()->blogs->id,
     259                        'type' => 'new_blog_comment',
     260                        'user_id' => $u,
     261                        'item_id' => $b,
     262                        'secondary_item_id' => $c,
     263                ) );
     264
     265                $this->assertEquals( $this->comment_post_id, $p );
     266        }
     267        /**
     268         * Dopey passthrough method so we can check that the correct values
     269         * are being passed to the filter
     270         */
     271        public function created_blog_passthrough( $a, $b ) {
     272                $this->userblog_id = isset( $b->id ) ? $b->id : '';
     273                return $a;
     274        }
     275
     276        /**
     277         * Dopey passthrough method so we can check that the correct values
     278         * are being passed to the filter
     279         */
     280        public function new_post_passthrough( $a, $b ) {
     281                $this->post_id = isset( $b->ID ) ? $b->ID : '';
     282                return $a;
     283        }
     284
     285        /**
     286         * Dopey passthrough method so we can check that the correct values
     287         * are being passed to the filter
     288         */
     289        public function new_comment_passthrough( $a, $b ) {
     290                $this->comment_post_id = isset( $b->comment_post_ID ) ? $b->comment_post_ID : '';
     291                return $a;
     292        }
     293}
  • tests/testcases/friends/activity.php

    diff --git tests/testcases/friends/activity.php tests/testcases/friends/activity.php
    index e69de29..9646ea4 100644
     
     1<?php
     2
     3/**
     4 * @group friends
     5 * @group activity
     6 */
     7class BP_Tests_Friends_Activity extends BP_UnitTestCase {
     8        /**
     9         * @group activity_action
     10         * @group bp_friends_format_activity_action_friendship_accepted
     11         */
     12        public function test_bp_friends_format_activity_action_friendship_accepted() {
     13                $u1 = $this->create_user();
     14                $u2 = $this->create_user();
     15
     16                $a = $this->factory->activity->create( array(
     17                        'component' => buddypress()->friends->id,
     18                        'type' => 'friendship_accepted',
     19                        'user_id' => $u1,
     20                        'secondary_item_id' => $u2,
     21                ) );
     22
     23                $expected = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), bp_core_get_userlink( $u1 ), bp_core_get_userlink( $u2 ) );
     24
     25                $a_obj = new BP_Activity_Activity( $a );
     26
     27                $this->assertSame( $expected, $a_obj->action );
     28        }
     29
     30        /**
     31         * @group activity_action
     32         * @group bp_friends_format_activity_action_friendship_created
     33         */
     34        public function test_bp_friends_format_activity_action_friendship_created() {
     35                $u1 = $this->create_user();
     36                $u2 = $this->create_user();
     37
     38                $a = $this->factory->activity->create( array(
     39                        'component' => buddypress()->friends->id,
     40                        'type' => 'friendship_created',
     41                        'user_id' => $u1,
     42                        'secondary_item_id' => $u2,
     43                ) );
     44
     45                $expected = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), bp_core_get_userlink( $u1 ), bp_core_get_userlink( $u2 ) );
     46
     47                $a_obj = new BP_Activity_Activity( $a );
     48
     49                $this->assertSame( $expected, $a_obj->action );
     50        }
     51}
     52
  • tests/testcases/groups/activity.php

    diff --git tests/testcases/groups/activity.php tests/testcases/groups/activity.php
    index e69de29..ed91c3b 100644
     
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group activity
     6 */
     7class BP_Tests_Groups_Activity extends BP_UnitTestCase {
     8        /**
     9         * @group activity_action
     10         * @group bp_groups_format_activity_action_created_group
     11         */
     12        public function test_bp_groups_format_activity_action_created_group() {
     13                $u = $this->create_user();
     14                $g = $this->factory->group->create();
     15                $a = $this->factory->activity->create( array(
     16                        'component' => buddypress()->groups->id,
     17                        'type' => 'created_group',
     18                        'user_id' => $u,
     19                        'item_id' => $g,
     20                ) );
     21
     22                $a_obj = new BP_Activity_Activity( $a );
     23                $g_obj = groups_get_group( array( 'group_id' => $g, ) );
     24
     25                $expected = sprintf( __( '%s created the group %s', 'buddypress' ), bp_core_get_userlink( $u ),  '<a href="' . bp_get_group_permalink( $g_obj ) . '">' . $g_obj->name . '</a>' );
     26
     27                $this->assertSame( $expected, $a_obj->action );
     28        }
     29
     30        /**
     31         * @group activity_action
     32         * @group bp_groups_format_activity_action_joined_group
     33         */
     34        public function test_bp_groups_format_activity_action_joined_group() {
     35                $u = $this->create_user();
     36                $g = $this->factory->group->create();
     37                $a = $this->factory->activity->create( array(
     38                        'component' => buddypress()->groups->id,
     39                        'type' => 'joined_group',
     40                        'user_id' => $u,
     41                        'item_id' => $g,
     42                ) );
     43
     44                $a_obj = new BP_Activity_Activity( $a );
     45                $g_obj = groups_get_group( array( 'group_id' => $g, ) );
     46
     47                $expected = sprintf( __( '%s joined the group %s', 'buddypress' ), bp_core_get_userlink( $u ),  '<a href="' . bp_get_group_permalink( $g_obj ) . '">' . $g_obj->name . '</a>' );
     48
     49                $this->assertSame( $expected, $a_obj->action );
     50        }
     51}
  • tests/testcases/xprofile/activity.php

    diff --git tests/testcases/xprofile/activity.php tests/testcases/xprofile/activity.php
    index a90f5b0..b71511a 100644
    class BP_Tests_XProfile_Activity extends BP_UnitTestCase { 
    270270                $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
    271271        }
    272272
     273        /**
     274         * @group activity_action
     275         * @group bp_xprofile_format_activity_action_new_avatar
     276         */
     277        public function test_bp_xprofile_format_activity_action_new_avatar() {
     278                $u = $this->create_user();
     279                $a = $this->factory->activity->create( array(
     280                        'component' => buddypress()->profile->id,
     281                        'type' => 'new_avatar',
     282                        'user_id' => $u,
     283                ) );
     284
     285                $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
     286
     287                $a_obj = new BP_Activity_Activity( $a );
     288
     289                $this->assertSame( $expected, $a_obj->action );
     290        }
     291
     292        /**
     293         * @group activity_action
     294         * @group bp_xprofile_format_activity_action_new_member
     295         */
     296        public function test_bp_xprofile_format_activity_action_new_member_xprofile_on() {
     297                $active = bp_is_active( 'xprofile' );
     298                buddypress()->active_components['xprofile'] = '1';
     299
     300                $u = $this->create_user();
     301                $a = $this->factory->activity->create( array(
     302                        'component' => buddypress()->profile->id,
     303                        'type' => 'new_member',
     304                        'user_id' => $u,
     305                ) );
     306
     307                $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
     308
     309                $a_obj = new BP_Activity_Activity( $a );
     310
     311                $this->assertSame( $expected, $a_obj->action );
     312
     313                if ( ! $active ) {
     314                        unset( buddypress()->active_components['xprofile'] );
     315                }
     316        }
     317
     318        /**
     319         * @group activity_action
     320         * @group bp_xprofile_format_activity_action_new_member
     321         */
     322        public function test_bp_xprofile_format_activity_action_new_member_xprofile_off() {
     323                $active = bp_is_active( 'xprofile' );
     324                unset( buddypress()->active_components['xprofile'] );
     325
     326                $u = $this->create_user();
     327                $a = $this->factory->activity->create( array(
     328                        'component' => buddypress()->profile->id,
     329                        'type' => 'new_member',
     330                        'user_id' => $u,
     331                ) );
     332
     333                $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
     334
     335                $a_obj = new BP_Activity_Activity( $a );
     336
     337                $this->assertSame( $expected, $a_obj->action );
     338
     339                if ( $active ) {
     340                        buddypress()->active_components['xprofile'] = '1';
     341                }
     342        }
     343
     344        /**
     345         * @group activity_action
     346         * @group bp_xprofile_format_activity_action_updated_profile
     347         */
     348        public function test_bp_xprofile_format_activity_action_updated_profile() {
     349                $u = $this->create_user();
     350                $a = $this->factory->activity->create( array(
     351                        'component' => buddypress()->profile->id,
     352                        'type' => 'updated_profile',
     353                        'user_id' => $u,
     354                ) );
     355
     356                $expected = sprintf( __( '%s&#8217;s profile was updated', 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . buddypress()->profile->slug . '/">' . bp_core_get_user_displayname( $u ) . '</a>' );
     357
     358                $a_obj = new BP_Activity_Activity( $a );
     359
     360                $this->assertSame( $expected, $a_obj->action );
     361        }
    273362
    274363        protected function setup_updated_profile_data() {
    275364                $this->updated_profile_data['u'] = $this->create_user();