Skip to:
Content

BuddyPress.org

Ticket #3856: 3856.02.diff

File 3856.02.diff, 10.4 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 eca743a..0084a8a 100644
    class BP_Activity_Activity { 
    442442                if ( $activities && $display_comments )
    443443                        $activities = BP_Activity_Activity::append_comments( $activities, $spam );
    444444
     445                // Generate action string
     446                $activities = BP_Activity_Activity::generate_action_strings( $activities );
     447
    445448                // If $max is set, only return up to the max results
    446449                if ( !empty( $max ) ) {
    447450                        if ( (int) $total_activities > (int) $max )
    class BP_Activity_Activity { 
    569572        }
    570573
    571574        /**
     575         * Generate action strings for the activities located in BP_Activity_Activity::get().
     576         *
     577         * @since BuddyPress (2.0.0)
     578         *
     579         * @param array $activities Array of activities.
     580         * @return array
     581         */
     582        protected static function generate_action_strings( $activities ) {
     583                foreach ( $activities as $key => $activity ) {
     584                        // Load action_data, the cached strings that will be
     585                        // used by the callback to generate the action strings
     586                        $activity->action_data = bp_activity_get_meta( $activity->id, 'action_data' );
     587
     588                        $generated_action = bp_activity_generate_action_string( $activity );
     589                        if ( false !== $generated_action ) {
     590                                $activity->action = $generated_action;
     591                        }
     592
     593                        $activities[ $key ] = $activity;
     594                }
     595
     596                return $activities;
     597        }
     598
     599        /**
    572600         * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().
    573601         *
    574602         * 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 8599d50..1beb746 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' ); 
    860868function bp_activity_register_activity_actions() {
    861869        global $bp;
    862870
    863         bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) );
     871        bp_activity_set_action(
     872                $bp->activity->id,
     873                'activity_update',
     874                __( 'Posted a status update', 'buddypress' ),
     875                'bp_activity_format_activity_action_activity_update'
     876        );
     877
    864878        bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) );
    865879
    866880        do_action( 'bp_activity_register_activity_actions' );
    function bp_activity_register_activity_actions() { 
    870884}
    871885add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' );
    872886
     887/**
     888 * Generate an activity action string for an activity item.
     889 *
     890 * @param object $activity Activity data object.
     891 * @return string|bool Returns false if no callback is found, otherwise returns
     892 *         the formatted action string.
     893 */
     894function bp_activity_generate_action_string( $activity ) {
     895        // Check for valid input
     896        if ( empty( $activity->component ) || empty( $activity->type ) || empty( $activity->action_data ) ) {
     897                return false;
     898        }
     899
     900        // Check for registered format callback
     901        if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
     902                return false;
     903        }
     904
     905        return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity );
     906}
     907
     908/**
     909 * Format 'activity_update' activity actions.
     910 *
     911 * @since BuddyPress (2.0.0)
     912 *
     913 * @param object $activity Activity data object.
     914 * @return string
     915 */
     916function bp_activity_format_activity_action_activity_update( $activity ) {
     917        $user_link = isset( $activity->action_data['user_link'] ) ? $activity->action_data['user_link'] : '';
     918        return sprintf( __( '%s posted an update', 'buddypress' ), $user_link );
     919}
     920
    873921/******************************************************************************
    874922 * Business functions are where all the magic happens in BuddyPress. They will
    875923 * handle the actual saving or manipulation of information. Usually they will
    function bp_activity_add( $args = '' ) { 
    10621110                'id'                => false, // Pass an existing activity ID to update an existing entry.
    10631111
    10641112                'action'            => '',    // The activity action - e.g. "Jon Doe posted an update"
     1113                'action_data'       => array(),
    10651114                'content'           => '',    // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
    10661115
    10671116                'component'         => false, // The name/ID of the component e.g. groups, profile, mycomponent
    function bp_activity_add( $args = '' ) { 
    10901139        $activity->user_id           = $user_id;
    10911140        $activity->component         = $component;
    10921141        $activity->type              = $type;
    1093         $activity->action            = $action;
    10941142        $activity->content           = $content;
    10951143        $activity->primary_link      = $primary_link;
    10961144        $activity->item_id           = $item_id;
    function bp_activity_add( $args = '' ) { 
    10981146        $activity->date_recorded     = $recorded_time;
    10991147        $activity->hide_sitewide     = $hide_sitewide;
    11001148        $activity->is_spam           = $is_spam;
     1149        $activity->action_data       = $action_data;
     1150        $activity->action            = ! empty( $action ) ? $action : bp_activity_generate_action_string( $activity );
    11011151
    11021152        if ( !$activity->save() )
    11031153                return false;
    11041154
     1155        if ( ! empty( $action_data ) )
     1156                bp_activity_update_meta( $activity->id, 'action_data', $action_data );
     1157
    11051158        // If this is an activity comment, rebuild the tree
    11061159        if ( 'activity_comment' == $activity->type )
    11071160                BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
    function bp_activity_post_update( $args = '' ) { 
    11531206
    11541207        // Record this on the user's profile
    11551208        $from_user_link   = bp_core_get_userlink( $user_id );
    1156         $activity_action  = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );
    11571209        $activity_content = $content;
    11581210        $primary_link     = bp_core_get_userlink( $user_id, false, true );
    11591211
    11601212        // Now write the values
    11611213        $activity_id = bp_activity_add( array(
    11621214                'user_id'      => $user_id,
    1163                 'action'       => apply_filters( 'bp_activity_new_update_action', $activity_action ),
    11641215                'content'      => apply_filters( 'bp_activity_new_update_content', $activity_content ),
    11651216                'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
    11661217                'component'    => $bp->activity->id,
    1167                 'type'         => 'activity_update'
     1218                'type'         => 'activity_update',
     1219                'action_data'  => array(
     1220                        'user_link' => $from_user_link,
     1221                ),
    11681222        ) );
    11691223
    11701224        $activity_content = apply_filters( 'bp_activity_latest_update_content', $content, $activity_content );
  • bp-groups/bp-groups-activity.php

    diff --git bp-groups/bp-groups-activity.php bp-groups/bp-groups-activity.php
    index 324064c..aefb5f1 100644
    function groups_register_activity_actions() { 
    2424        }
    2525
    2626        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' ) );
     27        bp_activity_set_action(
     28                $bp->groups->id,
     29                'joined_group',
     30                __( 'Joined a group', 'buddypress' ),
     31                'bp_groups_format_activity_action_joined_group'
     32        );
    2833
    2934        // These actions are for the legacy forums
    3035        // Since the bbPress plugin also shares the same 'forums' identifier, we also
    function groups_register_activity_actions() { 
    3944add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' );
    4045
    4146/**
     47 * Format 'joined_group' activity actions.
     48 *
     49 * @since BuddyPress (2.0.0)
     50 *
     51 * @param object $activity Activity data object.
     52 * @return string
     53 */
     54function bp_groups_format_activity_action_joined_group( $activity ) {
     55        $user_link  = isset( $activity->action_data['user_link'] ) ? $activity->action_data['user_link'] : '';
     56        $group_link = isset( $activity->action_data['group_link'] ) ? $activity->action_data['group_link'] : '';
     57        return sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link );
     58}
     59
     60/**
    4261 * Record an activity item related to the Groups component.
    4362 *
    4463 * A wrapper for {@link bp_activity_add()} that provides some Groups-specific
  • bp-groups/bp-groups-functions.php

    diff --git bp-groups/bp-groups-functions.php bp-groups/bp-groups-functions.php
    index 251ae96..3234c24 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,
     335                'action_data' => array(
     336                        'user_link' => bp_core_get_userlink( $user_id ),
     337                        'group_link' => '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>',
     338                ),
    336339        ) );
    337340
    338341        // Modify group meta