/** * Create a activity item * @param $params * @return string */ function buddystreamCreateActivity($params) { global $bp, $wpdb; $buddyStreamExtensions = new BuddyStreamExtensions(); $buddyStreamFilters = new BuddyStreamFilters(); /** * buddystreamCreateActivity(array( * 'user_id' => $user_meta->user_id, * 'extension' => 'facebook', * 'type' => 'photo', * 'content' => $content, * 'item_id' => $item['id'], * 'raw_date' => $item['created_time'], * 'actionlink' => 'url_to_original_item') * )); * */ if (is_array($params)) { //load config of extension $originalText = $params['content']; foreach ($buddyStreamExtensions->getExtensionsConfigs() as $extension) { if (isset($extension['hashtag'])) { $originalText = str_replace($extension['hashtag'], "", $originalText); $originalText = trim($originalText); } } //set the content $content = ""; $content = '<div class="buddystream_activity_container ' . $params['extension'] . '">' . $originalText . '</div>'; if (!buddyStreamCheckImportLog($params['user_id'], $params['item_id'], $params['extension']) && !buddyStreamCheckExistingContent($content) && !buddyStreamCheckExistingContent($originalText)) { buddyStreamAddToImportLog($params['user_id'], $params['item_id'], $params['extension']); remove_filter('bp_activity_action_before_save', 'bp_activity_filter_kses', 1); $activity = new BP_Activity_Activity(); $activity->user_id = $params['user_id']; $activity->component = $params['extension']; $activity->type = $params['extension']; $activity->content = $content; $activity->item_id = $params['item_id']; $activity->secondary_item_id = ''; $activity->date_recorded = $params['raw_date']; $activity->hide_sitewide = 0; $activity->action .= '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>'; $activity->action .= ' ' . __('posted a', 'buddystream_lang') . ' '; $activity->action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'buddystream_' . $extension['name']); $activity->action .= '</a>: '; $activity->primary_link = $params['actionlink']; if (!preg_match("/" . $params['item_id'] . "/i", get_user_meta($params['user_id'], 'buddystream_blacklist_ids', 1))) { $activity->save(); $buddyStreamFilters->updateDayLimitByOne($params['extension'], $params['user_id']); return true; } } } return false; }
/** * Post a gallery or media Main comment on single page * * @return type */ public function post_comment() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } // Check the nonce check_admin_referer('post_update', '_wpnonce_post_update'); if (!is_user_logged_in()) { exit('-1'); } $mpp_type = $_POST['mpp-type']; $mpp_id = $_POST['mpp-id']; if (empty($_POST['content'])) { exit('-1<div id="message" class="error"><p>' . __('Please enter some content to post.', 'mediapress') . '</p></div>'); } $activity_id = 0; if (empty($_POST['object']) && bp_is_active('activity')) { //we are preventing this comment to be set as the user's lastes_update $user_id = bp_loggedin_user_id(); $old_latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true); $activity_id = bp_activity_post_update(array('content' => $_POST['content'])); //restore if (!empty($old_latest_update)) { bp_update_user_meta($user_id, 'bp_latest_update', $old_latest_update); } } elseif ($_POST['object'] == 'groups') { if (!empty($_POST['item_id']) && bp_is_active('groups')) { $activity_id = groups_post_update(array('content' => $_POST['content'], 'group_id' => $_POST['item_id'])); } } else { $activity_id = apply_filters('bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content']); } if (empty($activity_id)) { exit('-1<div id="message" class="error"><p>' . __('There was a problem posting your update, please try again.', 'mediapress') . '</p></div>'); } //if we have got activity id, let us add a meta key if ($mpp_type == 'gallery') { mpp_activity_update_gallery_id($activity_id, $mpp_id); } elseif ($mpp_type == 'media') { mpp_activity_update_media_id($activity_id, $mpp_id); } $activity = new BP_Activity_Activity($activity_id); // $activity->component = buddypress()->mediapress->id; $activity->type = 'mpp_media_upload'; $activity->save(); if (bp_has_activities('include=' . $activity_id)) { while (bp_activities()) { bp_the_activity(); mpp_locate_template(array('activity/entry.php'), true); } } exit; }
/** * @group bp_activity_clear_cache_for_activity */ public function test_bp_activity_clear_cache_for_activity() { $u = $this->factory->user->create(); $a = $this->factory->activity->create(array('component' => buddypress()->activity->id, 'type' => 'activity_update', 'user_id' => $u, 'content' => 'foo bar')); $a_fp = bp_activity_get(array('type' => 'activity_update', 'user' => array('filter' => array('user_id' => $u)))); $activity_updated = new BP_Activity_Activity($a); $activity_updated->content = 'bar foo'; $activity_updated->save(); $a_fp = bp_activity_get(array('type' => 'activity_update', 'user' => array('filter' => array('user_id' => $u)))); $this->assertSame('bar foo', $a_fp['activities'][0]->content); }
function update_object($activity_id, $fields) { $activity = new BP_Activity_Activity($activity_id); foreach ($fields as $field_name => $value) { if (isset($activity->{$field_name})) { $activity->{$field_name} = $value; } } $activity->save(); return $activity; }
/** * Syncs activity comments and posts them back as blog comments. * * Note: This is only a one-way sync - activity comments -> blog comment. * * For blog post -> activity comment, see {@link bp_blogs_record_comment()}. * * @since BuddyPress (2.0.0) * * @param int $comment_id The activity ID for the posted activity comment. * @param array $params Parameters for the activity comment. * @param object Parameters of the parent activity item (in this case, the blog post). */ function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { // if parent activity isn't a blog post, stop now! if ( $parent_activity->type != 'new_blog_post' ) { return; } // if activity comments are disabled for blog posts, stop now! if ( bp_disable_blogforum_comments() ) { return; } // get userdata if ( $params['user_id'] == bp_loggedin_user_id() ) { $user = buddypress()->loggedin_user->userdata; } else { $user = bp_core_get_core_userdata( $params['user_id'] ); } // see if a parent WP comment ID exists if ( ! empty( $params['parent_id'] ) ) { $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); } else { $comment_parent = 0; } // comment args $args = array( 'comment_post_ID' => $parent_activity->secondary_item_id, 'comment_author' => bp_core_get_user_displayname( $params['user_id'] ), 'comment_author_email' => $user->user_email, 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 'comment_content' => $params['content'], 'comment_type' => '', // could be interesting to add 'buddypress' here... 'comment_parent' => (int) $comment_parent, 'user_id' => $params['user_id'], // commenting these out for now //'comment_author_IP' => '127.0.0.1', //'comment_agent' => '', 'comment_approved' => 1 ); // prevent separate activity entry being made remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); // handle multisite switch_to_blog( $parent_activity->item_id ); // handle timestamps for the WP comment after we've switched to the blog $args['comment_date'] = current_time( 'mysql' ); $args['comment_date_gmt'] = current_time( 'mysql', 1 ); // post the comment $post_comment_id = wp_insert_comment( $args ); // add meta to comment add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); // add meta to activity comment bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); // resave activity comment with WP comment permalink // // in bp_blogs_activity_comment_permalink(), we change activity comment // permalinks to use the post comment link // // @todo since this is done after AJAX posting, the activity comment permalink // doesn't change on the frontend until the next page refresh. $resave_activity = new BP_Activity_Activity( $comment_id ); $resave_activity->primary_link = get_comment_link( $post_comment_id ); $resave_activity->save(); // multisite again! restore_current_blog(); // add the comment hook back add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); /** * Fires after activity comments have been synced and posted as blog comments. * * @since BuddyPress (2.0.0) * * @param int $comment_id The activity ID for the posted activity comment. * @param array $args Array of args used for the comment syncing. * @param object $parent_activity Parameters of the blog post parent activity item. * @param object $user User data object for the blog comment. */ do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user ); }
/** * Add an activity item * * @since 1.1.0 * * @param array $args See docs for $defaults for details * * @global object $bp BuddyPress global settings * @uses nxt_parse_args() * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity} * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity} * @uses nxt_cache_delete() * @uses do_action() To call the 'bp_activity_add' hook * * @return int The activity id */ function bp_activity_add($args = '') { global $bp; $defaults = array('id' => false, 'action' => '', 'content' => '', 'component' => false, 'type' => false, 'primary_link' => '', 'user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false); $params = nxt_parse_args($args, $defaults); extract($params, EXTR_SKIP); // Make sure we are backwards compatible if (empty($component) && !empty($component_name)) { $component = $component_name; } if (empty($type) && !empty($component_action)) { $type = $component_action; } // Setup activity to be added $activity = new BP_Activity_Activity($id); $activity->user_id = $user_id; $activity->component = $component; $activity->type = $type; $activity->action = $action; $activity->content = $content; $activity->primary_link = $primary_link; $activity->item_id = $item_id; $activity->secondary_item_id = $secondary_item_id; $activity->date_recorded = $recorded_time; $activity->hide_sitewide = $hide_sitewide; if (!$activity->save()) { return false; } // If this is an activity comment, rebuild the tree if ('activity_comment' == $activity->type) { BP_Activity_Activity::rebuild_activity_comment_tree($activity->item_id); } nxt_cache_delete('bp_activity_sitewide_front', 'bp'); do_action('bp_activity_add', $params); return $activity->id; }
/** * Syncs activity comments and posts them back as blog comments. * * Note: This is only a one-way sync - activity comments -> blog comment. * * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}. * * @since 2.0.0 * @since 2.5.0 Allow custom post types to sync their comments with activity ones * * @param int $comment_id The activity ID for the posted activity comment. * @param array $params Parameters for the activity comment. * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post). */ function bp_blogs_sync_add_from_activity_comment($comment_id, $params, $parent_activity) { // if parent activity isn't a post type having the buddypress-activity support, stop now! if (!bp_activity_type_supports($parent_activity->type, 'post-type-comment-tracking')) { return; } // If activity comments are disabled for blog posts, stop now! if (bp_disable_blogforum_comments()) { return; } // Get userdata. if ($params['user_id'] == bp_loggedin_user_id()) { $user = buddypress()->loggedin_user->userdata; } else { $user = bp_core_get_core_userdata($params['user_id']); } // Get associated post type and set default comment parent $post_type = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type'); $comment_parent = 0; // See if a parent WP comment ID exists. if (!empty($params['parent_id']) && !empty($post_type)) { $comment_parent = bp_activity_get_meta($params['parent_id'], "bp_blogs_{$post_type}_comment_id"); } // Comment args. $args = array('comment_post_ID' => $parent_activity->secondary_item_id, 'comment_author' => bp_core_get_user_displayname($params['user_id']), 'comment_author_email' => $user->user_email, 'comment_author_url' => bp_core_get_user_domain($params['user_id'], $user->user_nicename, $user->user_login), 'comment_content' => $params['content'], 'comment_type' => '', 'comment_parent' => (int) $comment_parent, 'user_id' => $params['user_id'], 'comment_approved' => 1); // Prevent separate activity entry being made. remove_action('comment_post', 'bp_activity_post_type_comment', 10, 2); // Handle multisite. switch_to_blog($parent_activity->item_id); // Handle timestamps for the WP comment after we've switched to the blog. $args['comment_date'] = current_time('mysql'); $args['comment_date_gmt'] = current_time('mysql', 1); // Post the comment. $post_comment_id = wp_insert_comment($args); // Add meta to comment. add_comment_meta($post_comment_id, 'bp_activity_comment_id', $comment_id); // Add meta to activity comment. if (!empty($post_type)) { bp_activity_update_meta($comment_id, "bp_blogs_{$post_type}_comment_id", $post_comment_id); } // Resave activity comment with WP comment permalink. // // in bp_blogs_activity_comment_permalink(), we change activity comment // permalinks to use the post comment link // // @todo since this is done after AJAX posting, the activity comment permalink // doesn't change on the frontend until the next page refresh. $resave_activity = new BP_Activity_Activity($comment_id); $resave_activity->primary_link = get_comment_link($post_comment_id); /** * Now that the activity id exists and the post comment was created, we don't need to update * the content of the comment as there are no chances it has evolved. */ remove_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20); $resave_activity->save(); // Add the edit activity comment hook back. add_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20); // Multisite again! restore_current_blog(); // Add the comment hook back. add_action('comment_post', 'bp_activity_post_type_comment', 10, 2); /** * Fires after activity comments have been synced and posted as blog comments. * * @since 2.0.0 * * @param int $comment_id The activity ID for the posted activity comment. * @param array $args Array of args used for the comment syncing. * @param object $parent_activity Parameters of the blog post parent activity item. * @param object $user User data object for the blog comment. */ do_action('bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user); }
/** * Update the activity item for a custom post type entry. * * @since 2.2.0 * * @param WP_Post|null $post Post item. * @return bool True on success, false on failure. */ function bp_activity_post_type_update($post = null) { if (!is_a($post, 'WP_Post')) { return; } // Get the post type tracking args. $activity_post_object = bp_activity_get_post_type_tracking_args($post->post_type); if (empty($activity_post_object->action_id)) { return; } $activity_id = bp_activity_get_activity_id(array('component' => $activity_post_object->component_id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post->ID, 'type' => $activity_post_object->action_id)); // Activity ID doesn't exist, so stop! if (empty($activity_id)) { return; } // Delete the activity if the post was updated with a password. if (!empty($post->post_password)) { bp_activity_delete(array('id' => $activity_id)); } // Update the activity entry. $activity = new BP_Activity_Activity($activity_id); if (!empty($post->post_content)) { $activity_summary = bp_activity_create_summary($post->post_content, (array) $activity); // Backward compatibility filter for the blogs component. if ('blogs' == $activity_post_object->component_id) { $activity->content = apply_filters('bp_blogs_record_activity_content', $activity_summary, $post->post_content, (array) $activity, $post->post_type); } else { $activity->content = $activity_summary; } } // Save the updated activity. $updated = $activity->save(); /** * Fires after the updating of an activity item for a custom post type entry. * * @since 2.2.0 * @since 2.5.0 Add the post type tracking args parameter * * @param WP_Post $post Post object. * @param BP_Activity_Activity $activity Activity object. * @param object $activity_post_object The post type tracking args object. */ do_action('bp_activity_post_type_updated', $post, $activity, $activity_post_object); return $updated; }
function bp_checkins_update_to_checkin_type($activity_id, $old_activity, $new_type = 'activity_checkin') { if (!empty($activity_id) && !empty($old_activity)) { $activity = new BP_Activity_Activity($activity_id); $activity->user_id = $old_activity->user_id; $activity->component = $old_activity->component; $activity->type = $new_type; $activity->action = $old_activity->action; $activity->content = $old_activity->content; $activity->primary_link = $old_activity->primary_link; $activity->item_id = $old_activity->item_id; $activity->secondary_item_id = $old_activity->secondary_item_id; $activity->date_recorded = $old_activity->date_recorded; $activity->hide_sitewide = $old_activity->hide_sitewide; $test = $activity->save(); } }
/** * Update the activity item for a custom post type entry. * * @since BuddyPress (2.2.0) * * @param WP_Post $post Post item. * @return bool True on success, false on failure. */ function bp_activity_post_type_update( $post = null ) { $bp = buddypress(); if ( ! is_a( $post, 'WP_Post' ) ) { return; } // Get the post type tracking args. $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); if ( empty( $activity_post_object->action_id ) ) { return; } $activity_id = bp_activity_get_activity_id( array( 'component' => $activity_post_object->component_id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post->ID, 'type' => $activity_post_object->action_id, ) ); // Activity ID doesn't exist, so stop! if ( empty( $activity_id ) ) { return; } // Delete the activity if the post was updated with a password. if ( ! empty( $post->post_password ) ) { bp_activity_delete( array( 'id' => $activity_id ) ); } // Update the activity entry. $activity = new BP_Activity_Activity( $activity_id ); if ( ! empty( $post->post_content ) ) { // Make sure to update the thumbnail image. $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity ); // Generate an excerpt. $activity_excerpt = bp_create_excerpt( $post_content ); // Backward compatibility filter for the blogs component. if ( 'blogs' == $activity_post_object->component_id ) { $activity->content = apply_filters( 'bp_blogs_record_activity_content', $activity_excerpt, $post_content, (array) $activity, $post->post_type ); } else { $activity->content = $activity_excerpt; } } // Save the updated activity. $updated = $activity->save(); /** * Fires after the updating of an activity item for a custom post type entry. * * @since BuddyPress (2.2.0) * * @param WP_Post $post Post object. * @param BP_Activity_Activity $activity Activity object. */ do_action( 'bp_activity_post_type_updated', $post, $activity ); return $updated; }
/** * When an activity is saved, check if there exists a media attachment cookie, * if yes, mark it as non orphaned and store in the activity meta * */ function mpp_activity_mark_attached_media($activity_id) { if (!is_user_logged_in()) { return; } if (empty($_POST['mpp-attached-media'])) { return; } //don't do anything //let us process $media_ids = $_POST['mpp-attached-media']; $media_ids = explode(',', $media_ids); //make an array $media_ids = array_filter(array_unique($media_ids)); foreach ($media_ids as $media_id) { //should we verify the logged in user & owner of media is same? mpp_delete_media_meta($media_id, '_mpp_is_orphan'); //or should we delete the key? } mpp_activity_update_attached_media_ids($activity_id, $media_ids); mpp_activity_update_context($activity_id, 'gallery'); mpp_activity_update_activity_type($activity_id, 'media_upload'); //store the media ids in the activity meta //also add the activity to gallery & gallery to activity link $media = mpp_get_media($media_id); if ($media->gallery_id) { mpp_activity_update_gallery_id($activity_id, $media->gallery_id); } //also update this activity and set its action to be mpp_media_upload $activity = new BP_Activity_Activity($activity_id); // $activity->component = buddypress()->mediapress->id; $activity->type = 'mpp_media_upload'; $activity->save(); //save activity privacy $status_object = mpp_get_status_object($media->status); //if you have BuddyPress Activity privacy plugin enabled, this will work out of the box if ($status_object) { bp_activity_update_meta($activity->id, 'activity-privacy', $status_object->activity_privacy); } do_action('mpp_activity_media_marked_attached', $media_ids); //reset the cookie }
function bp_activity_add( $args = '' ) { global $bp; $defaults = array( 'id' => false, // Pass an existing activity ID to update an existing entry. 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent 'type' => false, // The activity type e.g. activity_update, profile_updated 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user. 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream? ); $params = wp_parse_args( $args, $defaults ); extract( $params, EXTR_SKIP ); /* Make sure we are backwards compatible */ if ( empty( $component ) && !empty( $component_name ) ) $component = $component_name; if ( empty( $type ) && !empty( $component_action ) ) $type = $component_action; $activity = new BP_Activity_Activity( $id ); $activity->user_id = $user_id; $activity->component = $component; $activity->type = $type; $activity->action = $action; $activity->content = $content; $activity->primary_link = $primary_link; $activity->item_id = $item_id; $activity->secondary_item_id = $secondary_item_id; $activity->date_recorded = $recorded_time; $activity->hide_sitewide = $hide_sitewide; if ( !$activity->save() ) return false; /* If this is an activity comment, rebuild the tree */ if ( 'activity_comment' == $activity->type ) BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id ); wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); do_action( 'bp_activity_add', $params ); return $activity->id; }
/** * Updates a blog post's corresponding activity entry during a post edit. * * @since BuddyPress (2.0.0) * * @see bp_blogs_catch_transition_post_status() * * @param WP_Post $post */ function bp_blogs_update_post($post) { if (!bp_is_active('activity')) { return; } $activity_id = bp_activity_get_activity_id(array('component' => buddypress()->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post->ID, 'type' => 'new_blog_post')); // activity ID doesn't exist, so stop! if (empty($activity_id)) { return; } // update the activity entry $activity = new BP_Activity_Activity($activity_id); if (!empty($post->post_content)) { // Make sure to update the thumbnail image $post_content = bp_activity_thumbnail_content_images($post->post_content, $activity->primary_link, (array) $activity); // Make sure to apply the blop post excerpt $activity->content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($post_content), $post_content, (array) $activity); } // Save the updated activity $activity->save(); // update post title in activity meta $existing_title = bp_activity_get_meta($activity_id, 'post_title'); if ($post->post_title !== $existing_title) { bp_activity_update_meta($activity_id, 'post_title', $post->post_title); // now update activity meta for post comments... sigh add_filter('comments_clauses', 'bp_blogs_comments_clauses_select_by_id'); $comments = get_comments(array('post_id' => $post->ID)); remove_filter('comments_clauses', 'bp_blogs_comments_clauses_select_by_id'); if (!empty($comments)) { $activity_ids = array(); $comment_ids = wp_list_pluck($comments, 'comment_ID'); // setup activity args $args = array('update_meta_cache' => false, 'show_hidden' => true, 'per_page' => 99999); // query for old-style "new_blog_comment" activity items $args['filter'] = array('object' => buddypress()->blogs->id, 'action' => 'new_blog_comment', 'secondary_id' => implode(',', $comment_ids)); $activities = bp_activity_get($args); if (!empty($activities['activities'])) { $activity_ids = (array) wp_list_pluck($activities['activities'], 'id'); } // query for activity comments connected to a blog post unset($args['filter']); $args['meta_query'] = array(array('key' => 'bp_blogs_post_comment_id', 'value' => $comment_ids, 'compare' => 'IN')); $args['type'] = 'activity_comment'; $args['display_comments'] = 'stream'; $activities = bp_activity_get($args); if (!empty($activities['activities'])) { $activity_ids = array_merge($activity_ids, (array) wp_list_pluck($activities['activities'], 'id')); } // update activity meta for all found activity items if (!empty($activity_ids)) { foreach ($activity_ids as $aid) { bp_activity_update_meta($aid, 'post_title', $post->post_title); } } unset($activities, $activity_ids, $comment_ids, $comments); } } // add post comment status to activity meta if closed if ('closed' == $post->comment_status) { bp_activity_update_meta($activity_id, 'post_comment_status', $post->comment_status); } else { bp_activity_delete_meta($activity_id, 'post_comment_status'); } }
/** * When an activity is saved, check if there exists a media attachment cookie, * if yes, mark it as non orphaned and store in the activity meta * */ function mpp_activity_mark_attached_media($activity_id) { if (!is_user_logged_in()) { return; } if (empty($_COOKIE['_mpp_activity_attached_media_ids'])) { return; } //don't do anything //let us process $media_ids = $_COOKIE['_mpp_activity_attached_media_ids']; $media_ids = explode(',', $media_ids); //make an array foreach ($media_ids as $media_id) { //should we verify the logged in user & owner of media is same? mpp_delete_media_meta($media_id, '_mpp_is_orphan'); //or should we delete the key? } mpp_activity_update_attached_media_ids($activity_id, $media_ids); //store the media ids in the activity meta //also add the activity to gallery & gallery to activity link $media = mpp_get_media($media_id); if ($media->gallery_id) { mpp_activity_update_gallery_id($activity_id, $media->gallery_id); } //also update this activity and set its action to be mpp_media_upload $activity = new BP_Activity_Activity($activity_id); // $activity->component = buddypress()->mediapress->id; $activity->type = 'mpp_media_upload'; $activity->save(); mpp_activity_clear_attached_media_cookie(); //clear cookies //reset the cookie }
function bp_activity_record($item_id, $component_name, $component_action, $is_private, $secondary_item_id = false, $user_id = false, $secondary_user_id = false, $recorded_time = false) { global $bp, $wpdb; if (!$user_id) { $user_id = $bp->loggedin_user->id; } if (!$recorded_time) { $recorded_time = time(); } $activity = new BP_Activity_Activity(); $activity->item_id = $item_id; $activity->secondary_item_id = $secondary_item_id; $activity->user_id = $user_id; $activity->component_name = $component_name; $activity->component_action = $component_action; $activity->date_recorded = $recorded_time; $activity->is_private = $is_private; $loggedin_user_save = $activity->save(); /* Save an activity entry for both logged in and secondary user. For example for a new friend connection you would want to show "X and Y are now friends" on both users activity stream */ if ($secondary_user_id) { $activity = new BP_Activity_Activity(); $activity->item_id = $item_id; $activity->user_id = $secondary_user_id; $activity->component_name = $component_name; $activity->component_action = $component_action; $activity->date_recorded = $recorded_time; $activity->is_private = $is_private; // We don't want to record this on the sitewide stream, otherwise we will get duplicates. $activity->no_sitewide_cache = true; $secondary_user_save = $activity->save(); } do_action('bp_activity_record', $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id); return true; }