Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/23/2018 02:37:41 AM (7 years ago)
Author:
boonebgorges
Message:

Privacy: Data exporter for Activity.

See #7818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r11883 r12112  
    41564156}
    41574157add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );
     4158
     4159/**
     4160 * Finds and exports personal data associated with an email address from the Activity tables.
     4161 *
     4162 * @since 4.0.0
     4163 *
     4164 * @param string $email_address  The user's email address.
     4165 * @param int    $page           Batch number.
     4166 * @return array An array of personal data.
     4167 */
     4168function bp_activity_personal_data_exporter( $email_address, $page ) {
     4169    $number = 50;
     4170
     4171    $email_address = trim( $email_address );
     4172
     4173    $data_to_export = array();
     4174
     4175    $user = get_user_by( 'email', $email_address );
     4176
     4177    if ( ! $user ) {
     4178        return array(
     4179            'data' => array(),
     4180            'done' => true,
     4181        );
     4182    }
     4183
     4184    $activities = bp_activity_get( array(
     4185        'display_comments' => 'stream',
     4186        'per_page'         => $number,
     4187        'page'             => $page,
     4188        'show_hidden'      => true,
     4189        'filter'           => array(
     4190            'user_id' => $user->ID,
     4191        ),
     4192    ) );
     4193
     4194    $user_data_to_export = array();
     4195    $activity_actions    = bp_activity_get_actions();
     4196
     4197    foreach ( $activities['activities'] as $activity ) {
     4198        if ( ! empty( $activity_actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
     4199            $description = call_user_func( $activity_actions->{$activity->component}->{$activity->type}['format_callback'], '', $activity );
     4200        } elseif ( ! empty( $activity->action ) ) {
     4201            $description = $activity->action;
     4202        } else {
     4203            $description = $activity->type;
     4204        }
     4205
     4206        $item_data = array(
     4207            array(
     4208                'name'  => __( 'Activity Date', 'buddypress' ),
     4209                'value' => $activity->date_recorded,
     4210            ),
     4211            array(
     4212                'name'  => __( 'Activity Description', 'buddypress' ),
     4213                'value' => $description,
     4214            ),
     4215            array(
     4216                'name'  => __( 'Activity URL', 'buddypress' ),
     4217                'value' => bp_activity_get_permalink( $activity->id, $activity ),
     4218            ),
     4219        );
     4220
     4221        if ( ! empty( $activity->content ) ) {
     4222            $item_data[] = array(
     4223                'name'  => __( 'Activity Content', 'buddypress' ),
     4224                'value' => $activity->content,
     4225            );
     4226        }
     4227
     4228        /**
     4229         * Filters the data associated with an activity item when assembled for a WP personal data export.
     4230         *
     4231         * Plugins that register activity types whose `action` string doesn't adequately
     4232         * describe the activity item for the purposes of data export may filter the activity
     4233         * item data here.
     4234         *
     4235         * @since 4.0.0
     4236         *
     4237         * @param array                $item_data Array of data describing the activity item.
     4238         * @param BP_Activity_Activity $activity  Activity item.
     4239         */
     4240        $item_data = apply_filters( 'bp_activity_personal_data_export_item_data', $item_data, $activity );
     4241
     4242        $data_to_export[] = array(
     4243            'group_id'    => 'bp_activity',
     4244            'group_label' => __( 'Activity' ),
     4245            'item_id'     => "bp-activity-{$activity->id}",
     4246            'data'        => $item_data,
     4247        );
     4248    }
     4249
     4250    // Tell core if we have more items to process.
     4251    $done = count( $activities['activities'] ) < $number;
     4252
     4253    return array(
     4254        'data' => $data_to_export,
     4255        'done' => $done,
     4256    );
     4257}
Note: See TracChangeset for help on using the changeset viewer.