Skip to:
Content

BuddyPress.org

Ticket #5880: 5880.patch

File 5880.patch, 6.3 KB (added by boonebgorges, 10 years ago)
  • src/bp-groups/bp-groups-activity.php

    diff --git src/bp-groups/bp-groups-activity.php src/bp-groups/bp-groups-activity.php
    index 5d1a401..9fe7d49 100644
    function groups_register_activity_actions() { 
    4343                array( 'activity', 'group', 'member', 'member_groups' )
    4444        );
    4545
     46        bp_activity_set_action(
     47                $bp->groups->id,
     48                'group_details_updated',
     49                __( 'Group details edited', 'buddypress' ),
     50                'bp_groups_format_activity_action_group_details_updated',
     51                __( 'Group Updates', 'buddypress' ),
     52                array( 'activity', 'group', 'member', 'member_groups' )
     53        );
     54
    4655        // These actions are for the legacy forums
    4756        // Since the bbPress plugin also shares the same 'forums' identifier, we also
    4857        // check for the legacy forums loader class to be extra cautious
    function bp_groups_format_activity_action_joined_group( $action, $activity ) { 
    128137}
    129138
    130139/**
     140 * Format 'group_details_updated' activity actions.
     141 *
     142 * @since BuddyPress (2.2.0)
     143 *
     144 * @param string $action Static activity action.
     145 * @param object $activity Activity data object.
     146 * @return string
     147 */
     148function bp_groups_format_activity_action_group_details_updated( $action, $activity ) {
     149        $user_link = bp_core_get_userlink( $activity->user_id );
     150
     151        $group = groups_get_group( array(
     152                'group_id'        => $activity->item_id,
     153                'populate_extras' => false,
     154        ) );
     155        $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
     156
     157        // Changed group details are stored in groupmeta, keyed by the activity
     158        // timestamp. See {@link bp_groups_group_details_updated_add_activity()}.
     159        $changed = groups_get_groupmeta( $activity->item_id, 'updated_details_' . $activity->date_recorded );
     160
     161        // No changed details were found, so use a generic message
     162        if ( empty( $changed ) ) {
     163                $action = sprintf( __( '%1$s updated details for the group %2$s', 'buddypress' ), $user_link, $group_link );
     164
     165        // Name and description changed - to keep things short, don't describe
     166        // changes in detail
     167        } else if ( isset( $changed['name'] ) && isset( $changed['description'] ) ) {
     168                $action = sprintf( __( '%1$s changed the name and description of the group %2$s', 'buddypress' ), $user_link, $group_link );
     169
     170        // Name only
     171        } else if ( ! empty( $changed['name']['old'] ) && ! empty( $changed['name']['new'] ) ) {
     172                $action = sprintf( __( '%1$s changed the name of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), $user_link, $group_link, $changed['name']['old'], $changed['name']['new'] );
     173
     174        // Description only
     175        } else if ( ! empty( $changed['description']['old'] ) && ! empty( $changed['description']['new'] ) ) {
     176                $action = sprintf( __( '%1$s changed the description of the group %2$s from "%3$s" to "%4$s"', 'buddypress' ), $user_link, $group_link, $changed['description']['old'], $changed['description']['new'] );
     177
     178        }
     179
     180        return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity );
     181}
     182
     183/**
    131184 * Fetch data related to groups at the beginning of an activity loop.
    132185 *
    133186 * This reduces database overhead during the activity loop.
    function bp_groups_membership_accepted_add_activity( $user_id, $group_id ) { 
    290343add_action( 'groups_membership_accepted', 'bp_groups_membership_accepted_add_activity', 10, 2 );
    291344
    292345/**
     346 * Add an activity item when a group's details are updated.
     347 *
     348 * @since BuddyPress (2.2.0)
     349 *
     350 * @param int $group_id ID of the group.
     351 * @param BP_Groups_Group Group object before the details had been changed.
     352 * @param bool $notify_members True if the admin has opted to notify group
     353 *        members, otherwise false.
     354 * @return int|bool The ID of the activity on success. False on error.
     355 */
     356function bp_groups_group_details_updated_add_activity( $group_id, $old_group, $notify_members ) {
     357
     358        // Bail if Activity is not active
     359        if ( ! bp_is_active( 'activity' ) ) {
     360                return false;
     361        }
     362
     363        if ( ! isset( $old_group->name ) || ! isset( $old_group->description ) ) {
     364                return false;
     365        }
     366
     367        // If the admin has opted not to notify members, don't post an activity
     368        // item either
     369        if ( empty( $notify_members ) ) {
     370                return;
     371        }
     372
     373        $group = groups_get_group( array(
     374                'group_id' => $group_id,
     375        ) );
     376
     377        // Store the changed data, which will be used to generate the activity
     378        // action. Since we haven't yet created the activity item, we store the
     379        // old group data in groupmeta, keyed by the timestamp that we'll put
     380        // on the activity item.
     381        $changed = array();
     382
     383        if ( $group->name !== $old_group->name ) {
     384                $changed['name'] = array(
     385                        'old' => $old_group->name,
     386                        'new' => $group->name,
     387                );
     388        }
     389
     390        if ( $group->description !== $old_group->description ) {
     391                $changed['description'] = array(
     392                        'old' => $old_group->description,
     393                        'new' => $group->description,
     394                );
     395        }
     396
     397        // If there are no changes, don't post an activity item
     398        if ( empty( $changed ) ) {
     399                return;
     400        }
     401
     402        $time = bp_core_current_time();
     403        groups_update_groupmeta( $group_id, 'updated_details_' . $time, $changed );
     404
     405        // Record in activity streams
     406        return groups_record_activity( array(
     407                'type'          => 'group_details_updated',
     408                'item_id'       => $group_id,
     409                'user_id'       => bp_loggedin_user_id(),
     410                'recorded_time' => $time,
     411
     412        ) );
     413
     414}
     415add_action( 'groups_details_updated', 'bp_groups_group_details_updated_add_activity', 10, 3 );
     416
     417/**
    293418 * Delete all activity items related to a specific group.
    294419 *
    295420 * @since BuddyPress (1.9.0)
  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index c83e743..5b62807 100644
    function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $n 
    186186        if ( empty( $group_name ) || empty( $group_desc ) )
    187187                return false;
    188188
    189         $group              = groups_get_group( array( 'group_id' => $group_id ) );
     189        $group     = groups_get_group( array( 'group_id' => $group_id ) );
     190        $old_group = clone $group;
     191
    190192        $group->name        = $group_name;
    191193        $group->description = $group_desc;
    192194
    function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $n 
    197199                groups_notification_group_updated( $group->id );
    198200        }
    199201
    200         do_action( 'groups_details_updated', $group->id );
     202        do_action( 'groups_details_updated', $group->id, $old_group, $notify_members );
    201203
    202204        return true;
    203205}