/** * Post an activity to the group * * @uses check_admin_referer() for security reasons * @uses bp_loggedin_user_id() to get the current user id * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type * @uses buddydrive_get_file_post_type() to get the BuddyFile post type * @uses get_post_meta() to get item extra data (privacy) * @uses buddydrive_get_buddyfile() to get item * @uses groups_get_group() to get the group * @uses bp_core_get_userlink() to get link to user's profile * @uses buddydrive_get_name() so that it's possible to brand the plugin * @uses bp_get_group_permalink() to build the group permalink * @uses groups_record_activity() to finaly record the activity * @return int 1 or string an error message */ function buddydrive_share_in_group() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } // Check the nonce check_admin_referer('buddydrive_actions', '_wpnonce_buddydrive_actions'); $buddyitem = intval($_POST['itemid']); if (empty($buddyitem)) { _e('this is embarassing, it did not work :(', 'buddydrive'); die; } if (!bp_is_active('groups')) { _e('Group component is deactivated, please contact the administrator.', 'buddydrive'); die; } $link = $_POST['url']; $result = false; $user_id = bp_loggedin_user_id(); $item_type = 'folder' == $_POST['itemtype'] ? buddydrive_get_folder_post_type() : buddydrive_get_file_post_type(); if (!empty($buddyitem)) { $group_id = get_post_meta($buddyitem, '_buddydrive_sharing_groups', true); if (empty($group_id)) { $buddyfile = buddydrive_get_buddyfile($buddyitem, $item_type); $parent_id = $buddyfile->post_parent; $group_id = get_post_meta($parent_id, '_buddydrive_sharing_groups', true); } if (!empty($group_id)) { $group = groups_get_group(array('group_id' => $group_id)); $action = $activity_action = sprintf(__('%1$s shared a %2$s Item in the group %3$s', 'buddydrive'), bp_core_get_userlink($user_id), esc_html(buddydrive_get_name()), '<a href="' . esc_url(bp_get_group_permalink($group)) . '">' . esc_html($group->name) . '</a>'); $content = $link; $args = array('user_id' => $user_id, 'action' => $action, 'content' => $content, 'type' => 'activity_update', 'component' => 'groups', 'item_id' => $group_id); $result = groups_record_activity($args); } } if (!empty($result)) { // Update the group's latest activity groups_update_last_activity($group_id); echo 1; } else { _e('this is embarassing, it did not work :(', 'buddydrive'); } die; }
/** * Update group last activity. * * @param $group_id */ static function update_last_active($group_id) { groups_update_last_activity($group_id); }
/** * Update the last activity of the group when a rendez-vous attached to it is saved * * @package Rendez Vous * @subpackage Groups * * @since Rendez Vous (1.1.0) * * @param Rendez_Vous_Item $rendez_vous the rendez-vous object * @uses groups_update_last_activity() to update group's latest activity */ public function group_last_activity($rendez_vous = null) { if (empty($rendez_vous->group_id)) { return; } // Update group's latest activity groups_update_last_activity($rendez_vous->group_id); }
/** * screen_handler() * * @todo needs rewritten, it's not compatible with BuddyPress > 1.6 * * Courseware action for handling the screens on group pages */ function screen_handler() { global $bp; if (!$this->courseware_status($bp->groups->current_group->id)) { return; } if ($bp->current_action == $bp->courseware->slug) { self::$current_nav_option = self::$nav_options[__('Home', 'bpsp')]; if (reset($bp->action_variables)) { self::$current_nav_option .= '/' . reset($bp->action_variables); } add_action('bp_before_group_body', array($this, 'nav_options')); do_action('courseware_group_screen_handler', $bp->action_variables); add_action('bp_template_content', array($this, 'load_template')); } groups_update_last_activity($bp->groups->current_group->id); bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins')); }
/** * Map a forum post to its corresponding group in the group activity stream. * * @since bbPress (r4396) * * @param array $args Arguments from BBP_BuddyPress_Activity::record_activity() * @uses groups_get_current_group() To see if we're posting from a BP group * * @return array */ public function map_activity_to_group($args = array()) { // Get current BP group $group = groups_get_current_group(); // Not posting from a BuddyPress group? stop now! if (empty($group)) { return $args; } // Set the component to 'groups' so the activity item shows up in the group $args['component'] = buddypress()->groups->id; // Move the forum post ID to the secondary item ID $args['secondary_item_id'] = $args['item_id']; // Set the item ID to the group ID so the activity item shows up in the group $args['item_id'] = $group->id; // Update the group's last activity groups_update_last_activity($group->id); return $args; }
/** * Updates group's latest activity in case an idea or a comment was inserted * * @package WP Idea Stream * @subpackage buddypress/groups * * @since 2.0.0 * * @param int $object_id an idea or comment ID * @param object $object an idea or comment object * @uses get_post_meta() to get the attached group ID * @uses groups_update_last_activity() to update latest group's activity */ public function group_last_activity($object_id = 0, $object = null) { if (empty($object)) { return; } // Check for inserted idea if (is_a($object, 'WP_Idea_Stream_Idea') && !empty($object->metas['group_id'])) { $group_id = (int) $object->metas['group_id']; // Check for inserted idea about a comment } else { if (!empty($object->comment_post_ID)) { $group_id = (int) get_post_meta($object->comment_post_ID, '_ideastream_group_id', true); // Default is null } else { $group_id = 0; } } // Ne need to carry on if (empty($group_id)) { return; } // Update group's latest activity groups_update_last_activity($group_id); }
/** * When posting via email, we also update the last activity entries in BuddyPress. * * This is so your BuddyPress site doesn't look dormant when your members * are emailing each other back and forth! :) * * @param array $args Depending on the filter that this function is hooked into, contents will vary * @since 1.0-RC1 */ function bp_rbe_log_last_activity($args) { // get user id from activity entry if (!empty($args['user_id'])) { $user_id = $args['user_id']; } elseif (!empty($args['sender_id'])) { $user_id = $args['sender_id']; } else { $user_id = false; } // if no user ID, return now if (empty($user_id)) { return; } // update user's last activity bp_update_user_last_activity($user_id); // now update 'last_activity' group meta entry if applicable if (!empty($args['type'])) { switch ($args['type']) { case 'new_forum_topic': case 'new_forum_post': case 'bbp_topic_create': case 'bbp_reply_create': // sanity check! if (!bp_is_active('groups')) { return; } groups_update_last_activity($args['item_id']); break; // for group activity comments, we have to look up the parent activity to see // if the activity comment came from a group // for group activity comments, we have to look up the parent activity to see // if the activity comment came from a group case 'activity_comment': // we don't need to proceed if the groups component was disabled if (!bp_is_active('groups')) { return; } // sanity check! if (!bp_is_active('activity')) { return; } // grab the parent activity $activity = bp_activity_get_specific('activity_ids=' . $args['item_id']); if (!empty($activity['activities'][0])) { $parent_activity = $activity['activities'][0]; // if parent activity update is from the groups component, // that means the activity comment was in a group! // so update group 'last_activity' meta entry if ($parent_activity->component == 'groups') { groups_update_last_activity($parent_activity->item_id); } } break; } } }
/** * Create a new group deposity activity record. */ function humcore_new_group_deposit_activity($deposit_id, $group_id, $deposit_content = '', $deposit_link = '') { if (!bp_is_active('activity')) { return false; } $bp = buddypress(); $user_id = bp_loggedin_user_id(); $userlink = bp_core_get_userlink($user_id); $group = groups_get_group($group_id); if (isset($group->status) && 'public' != $group->status) { $hide_sitewide = true; } else { $hide_sitewide = false; } $activity_ID = bp_activity_add(array('user_id' => $user_id, 'item_id' => $group_id, 'secondary_item_id' => $deposit_id, 'action' => '', 'component' => $bp->groups->id, 'content' => $deposit_content, 'primary_link' => $deposit_link, 'type' => 'new_group_deposit', 'hide_sitewide' => $hide_sitewide)); // Update the group's last activity groups_update_last_activity($group_id); return $activity_ID; }