function post_review($args = '') { global $bp; $defaults = array('content' => false, 'rating' => false, 'user_id' => $bp->loggedin_user->id, 'group_id' => $bp->groups->current_group->id); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($content) || !strlen(trim($content)) || empty($user_id) || empty($group_id)) { return false; } // Be sure the user is a member of the group before posting. if (!is_super_admin() && !groups_is_user_member($user_id, $group_id)) { return false; } // Record this in activity streams $activity_action = sprintf(__('%s reviewed %s:', 'bpgr'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_html($bp->groups->current_group->name) . '</a>'); $rating_content = false; if (!empty($rating)) { $rating_content = '<span class="p-rating">' . bpgr_get_review_rating_html($rating) . '</span>'; } $activity_content = $rating_content . $content; $activity_id = groups_record_activity(array('user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'type' => 'review', 'item_id' => $group_id)); $this->add_rating(array('score' => $rating, 'activity_id' => $activity_id, 'group_id' => $group_id)); groups_update_groupmeta($group_id, 'last_activity', gmdate("Y-m-d H:i:s")); do_action('bpgr_posted_review', $args, $activity_id); return $activity_id; }
/** * Handle the loading of a user's Groups > Invites page. */ function groups_screen_group_invites() { $group_id = (int) bp_action_variable(1); if (bp_is_action_variable('accept') && is_numeric($group_id)) { // Check the nonce. if (!check_admin_referer('groups_accept_invite')) { return false; } if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite accepted', 'buddypress')); // Record this in activity streams. $group = groups_get_group(array('group_id' => $group_id)); groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id)); } if (isset($_GET['redirect_to'])) { $redirect_to = urldecode($_GET['redirect_to']); } else { $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } bp_core_redirect($redirect_to); } elseif (bp_is_action_variable('reject') && is_numeric($group_id)) { // Check the nonce. if (!check_admin_referer('groups_reject_invite')) { return false; } if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite rejected', 'buddypress')); } if (isset($_GET['redirect_to'])) { $redirect_to = urldecode($_GET['redirect_to']); } else { $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } bp_core_redirect($redirect_to); } /** * Fires before the loading of a users Groups > Invites template. * * @since 1.0.0 * * @param int $group_id ID of the group being displayed */ do_action('groups_screen_group_invites', $group_id); /** * Filters the template to load for a users Groups > Invites page. * * @since 1.0.0 * * @param string $value Path to a users Groups > Invites page template. */ bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home')); }
function groups_left_group($group_id, $user_id = 0) { global $bp; if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } // Record this in activity streams groups_record_activity(array('type' => 'left_group', 'item_id' => $group_id, 'user_id' => $user_id)); // Modify group meta groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time()); return true; }
function groups_screen_group_invites() { $group_id = (int) bp_action_variable(1); if (bp_is_action_variable('accept') && is_numeric($group_id)) { // Check the nonce if (!check_admin_referer('groups_accept_invite')) { return false; } if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite accepted', 'buddypress')); // Record this in activity streams $group = groups_get_group(array('group_id' => $group_id)); groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id)); } if (isset($_GET['redirect_to'])) { $redirect_to = urldecode($_GET['redirect_to']); } else { $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } bp_core_redirect($redirect_to); } else { if (bp_is_action_variable('reject') && is_numeric($group_id)) { // Check the nonce if (!check_admin_referer('groups_reject_invite')) { return false; } if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite rejected', 'buddypress')); } if (isset($_GET['redirect_to'])) { $redirect_to = urldecode($_GET['redirect_to']); } else { $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } bp_core_redirect($redirect_to); } } do_action('groups_screen_group_invites', $group_id); bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home')); }
function groups_screen_group_invites() { $group_id = (int) bp_action_variable(1); if (bp_is_action_variable('accept') && is_numeric($group_id)) { // Check the nonce if (!check_admin_referer('groups_accept_invite')) { return false; } if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite accepted', 'buddypress')); // Record this in activity streams $group = new BP_Groups_Group($group_id); groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_accepted_invite_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink(bp_loggedin_user_id()), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), bp_loggedin_user_id(), &$group)), 'type' => 'joined_group', 'item_id' => $group->id)); } bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } else { if (bp_is_action_variable('reject') && is_numeric($group_id)) { // Check the nonce if (!check_admin_referer('groups_reject_invite')) { return false; } if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) { bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error'); } else { bp_core_add_message(__('Group invite rejected', 'buddypress')); } bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()); } } // Remove notifications bp_core_delete_notifications_by_type(bp_loggedin_user_id(), 'groups', 'group_invite'); do_action('groups_screen_group_invites', $group_id); bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home')); }
function bp_groupblogs_fetch_group_feeds($group_id = false) { global $bp; include_once ABSPATH . 'wp-includes/rss.php'; if (empty($group_id)) { $group_id = $bp->groups->current_group->id; } if ($group_id == $bp->groups->current_group->id) { $group = $bp->groups->current_group; } else { $group = new BP_Groups_Group($group_id); } if (!$group) { return false; } $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds'); $group_blogs = explode(";", $group_blogs[0]); /* Set the visibility */ $hide_sitewide = 'public' != $group->status ? true : false; foreach ((array) $group_blogs as $feed_url) { $rss = fetch_feed(trim($feed_url)); if (!is_wp_error($rss)) { foreach ($rss->get_items(0, 10) as $item) { $key = $item->get_date('U'); $items[$key]['title'] = $item->get_title(); $items[$key]['subtitle'] = $item->get_title(); //$items[$key]['author'] = $item->get_author()->get_name(); $items[$key]['blogname'] = $item->get_feed()->get_title(); $items[$key]['link'] = $item->get_permalink(); $items[$key]['blogurl'] = $item->get_feed()->get_link(); $items[$key]['description'] = $item->get_description(); $items[$key]['source'] = $item->get_source(); $items[$key]['copyright'] = $item->get_copyright(); } } } if ($items) { ksort($items); $items = array_reverse($items, true); } else { return false; } /* Record found blog posts in activity streams */ foreach ((array) $items as $post_date => $post) { //var_dump($post); if (substr($post['blogname'], 0, 7) == "Twitter") { $activity_action = sprintf(__('%s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">Tweet</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>'); } else { $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>'); } $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>'; $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group); /* Fetch an existing activity_id if one exists. */ if (function_exists('bp_activity_get_activity_id')) { $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => $bp->groups->id, 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']))); } /* Record or update in activity streams. */ groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $item->get_link(), 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']), 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide)); } return $items; }
function groups_accept_membership_request( $membership_id, $user_id = false, $group_id = false ) { global $bp; if ( $user_id && $group_id ) $membership = new BP_Groups_Member( $user_id, $group_id ); else $membership = new BP_Groups_Member( false, false, $membership_id ); $membership->accept_request(); if ( !$membership->save() ) return false; /* Check if the user has an outstanding invite, if so delete it. */ if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) ) groups_delete_invite( $membership->user_id, $membership->group_id ); /* Modify group member count */ groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 ); /* Record this in activity streams */ $group = new BP_Groups_Group( $membership->group_id ); groups_record_activity( array( 'action' => apply_filters( 'groups_activity_membership_accepted_action', sprintf( __( '%s joined the group %s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ), 'type' => 'joined_group', 'item_id' => $membership->group_id, 'user_id' => $membership->user_id ) ); /* Send a notification to the user. */ require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' ); groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, true ); do_action( 'groups_membership_accepted', $membership->user_id, $membership->group_id ); return true; }
function bp_checkins_groups_post_update($args = '') { global $bp; $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id, 'group_id' => 0, 'type' => 'checkin', 'place_id' => false, 'place_name' => false, 'comment_id' => false, 'recorded_time' => bp_core_current_time()); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($group_id) && !empty($bp->groups->current_group->id)) { $group_id = $bp->groups->current_group->id; } if ($type == "checkin" && (empty($content) || !strlen(trim($content)))) { return false; } if (empty($user_id) || empty($group_id)) { return false; } $bp->groups->current_group = new BP_Groups_Group($group_id); // Be sure the user is a member of the group before posting. if (!is_super_admin() && !groups_is_user_member($user_id, $group_id)) { return false; } $from_user_link = bp_core_get_userlink($user_id); if ($type == 'checkin') { $activity_action = sprintf(__('%1$s added a checkin in the group %2$s', 'bp-checkins'), $from_user_link, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $activity_content = $content; $primary_link = bp_core_get_userlink($user_id, false, true); $checkin_type = 'activity_checkin'; $item_id = $group_id; $secondary_item_id = false; } else { if ($type == 'new_place' && !empty($place_id)) { $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>'; $activity_action = sprintf(__('%1$s added a new place %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $primary_link = bp_core_get_userlink($user_id, false, true); $checkin_type = 'new_place'; $item_id = $group_id; $activity_content = $content; $secondary_item_id = $place_id; } else { if ($type == 'place_checkin' && !empty($place_id)) { $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>'; $activity_action = sprintf(__('%1$s checked-in %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $primary_link = bp_core_get_userlink($user_id, false, true); $checkin_type = 'place_checkin'; $item_id = $group_id; $activity_content = false; $secondary_item_id = $place_id; } else { if ($type == 'place_comment' && !empty($place_id) && !empty($comment_id)) { $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>'; $activity_action = sprintf(__('%1$s added a comment on %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $primary_link = bp_core_get_userlink($user_id, false, true); $checkin_type = 'place_comment'; $activity_content = $content; $item_id = $group_id; $secondary_item_id = $place_id; } else { if ($type == 'place_checkin_comment' && !empty($place_id) && !empty($comment_id)) { $place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>'; $activity_action = sprintf(__('%1$s checked-in and added a comment on %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $primary_link = bp_core_get_userlink($user_id, false, true); $checkin_type = 'place_comment'; $activity_content = $content; $item_id = $group_id; $secondary_item_id = $place_id; } } } } } $activity_id = groups_record_activity(array('user_id' => $user_id, 'component' => 'groups', 'action' => apply_filters('groups_activity_new_update_action', $activity_action), 'content' => apply_filters('groups_activity_new_update_content', $activity_content), 'type' => $checkin_type, 'item_id' => $group_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time)); if ($type == 'checkin') { groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time()); } if ($checkin_type == 'place_comment') { update_comment_meta($comment_id, 'group_place_activity_id', $activity_id); } do_action('bp_groups_posted_checkin', $content, $user_id, $group_id, $activity_id); return $activity_id; }
/** * Update an existing group forum post. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @since BuddyPress (1.1.0) * * @param int $post_id The post ID of the existing forum post. * @param string $post_text The text for the forum post. * @param int $topic_id The topic ID of the existing forum topic. * @param mixed $page The page number where the new forum post should reside. * Optional. * @return mixed The forum post ID on success. Boolean false on failure. */ function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false) { $bp = buddypress(); $post_text = apply_filters('group_forum_post_text_before_save', $post_text); $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id); $post = bp_forums_get_post($post_id); $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id)); if (empty($post_id)) { return false; } $topic = bp_forums_get_topic_details($topic_id); $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>'); $activity_content = bp_create_excerpt($post_text); $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/'; if (!empty($page)) { $primary_link .= "?topic_page=" . $page; } // Get the corresponding activity item if (bp_is_active('activity')) { $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id)); } // Update the entry in activity streams groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time)); do_action_ref_array('groups_update_group_forum_post', array($post, &$topic)); return $post_id; }
function bp_ning_import_get_discussions() { global $wpdb; $ning_id_array = get_option('bp_ning_user_array'); // Get list of Ning groups for cross reference $groups = bp_ning_import_prepare_json('groups'); $ning_group_id_array = get_option('bp_ning_group_array', array()); $discussions = bp_ning_import_prepare_json('discussions'); //delete_option('bp_ning_discussions_imported'); $imported = get_option('bp_ning_discussions_imported', array()); $counter = 0; foreach ((array) $discussions as $discussion_key => $discussion) { unset($topic_id); if (isset($imported[$discussion->id])) { continue; } if ($counter >= 10) { update_option('bp_ning_discussions_imported', $imported); printf(__('%d out of %d discussions done.'), count($imported), count($discussions)); return false; } $slug = sanitize_title(esc_attr($discussion->category)); $ning_group_creator_id = $discussion->contributorName; $creator_id = $ning_id_array[$ning_group_creator_id]; if (!$creator_id) { $what++; continue; } $ndate = strtotime($discussion->createdDate); $date_created = date("Y-m-d H:i:s", $ndate); if (isset($discussion->category)) { $ning_group_id = $discussion->category; $group_id = $ning_group_id_array[$ning_group_id]; } else { if (isset($discussion->groupId)) { $ngroup_id = $discussion->groupId; $group_id = $ning_group_id_array[$ngroup_id]; } else { continue; // todo fix me! } } $group = new BP_Groups_Group($group_id); $args = array('topic_title' => $discussion->title, 'topic_slug' => groups_check_slug(sanitize_title(esc_attr($discussion->title))), 'topic_text' => $discussion->description, 'topic_poster' => $creator_id, 'topic_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_last_poster' => $creator_id, 'topic_last_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_start_time' => $date_created, 'topic_time' => $date_created, 'forum_id' => groups_get_groupmeta($group_id, 'forum_id')); $query = "SELECT `topic_id` FROM wp_bb_topics WHERE topic_title = '%s' AND topic_start_time = '%s' LIMIT 1"; $q = $wpdb->prepare($query, $args['topic_title'], $args['topic_start_time']); $topic_exists = $wpdb->get_results($q); if (isset($topic_exists[0])) { echo "<em>- Topic {$discussion->title} already exists</em><br />"; $imported[$discussion->id] = true; continue; } if (!$args['forum_id']) { echo "No forum id - skipping"; continue; } if (!($topic_id = bp_forums_new_topic($args))) { // TODO: WTF? return false; echo "<h2>Refresh to import more discussions</h2>"; die; } else { bp_ning_import_process_inline_images_new('discussions', $topic_id, 'topic'); echo "<strong>- Created topic: {$discussion->title}</strong><br />"; } $activity_content = bp_create_excerpt($discussion->description); $skip_activity = get_option('bp_ning_skip_forum_activity'); if (!$skip_activity) { $topic = bp_forums_get_topic_details($topic_id); // Activity item $activity_action = sprintf(__('%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_html($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_html($group->name) . '</a>'); groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_topic_action', $activity_action, $discussion->description, $topic), 'content' => apply_filters('groups_activity_new_forum_topic_content', $activity_content, $discussion->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'), 'type' => 'new_forum_topic', 'item_id' => $group_id, 'secondary_item_id' => $topic->topic_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0)); do_action('groups_new_forum_topic', $group_id, $topic); } // Now check for comments if (isset($discussion->comments)) { foreach ($discussion->comments as $reply) { $ning_group_creator_id = $reply->contributorName; $creator_id = $ning_id_array[$ning_group_creator_id]; $ndate = strtotime($reply->createdDate); $date_created = date("Y-m-d H:i:s", $ndate); $args = array('topic_id' => $topic_id, 'post_text' => $reply->description, 'post_time' => $date_created, 'poster_id' => $creator_id, 'poster_ip' => '192.168.1.1'); $query = "SELECT * FROM wp_bb_posts WHERE topic_id = '%s' AND post_text = '%s'"; $q = $wpdb->prepare($query, $args['topic_id'], $args['post_text']); $post_exists = $wpdb->get_results($q); if ($post_exists) { continue; } $post_id = bp_forums_insert_post($args); if ($post_id) { bp_ning_import_process_inline_images_new('discussions', $post_id, 'topic_reply'); $import_summary = esc_html(bp_create_excerpt($reply->description, 100, array('html' => false))); echo "<em>- Imported forum post: {$import_summary}</em><br />"; } if (!groups_is_user_member($creator_id, $group_id)) { if (!$bp->groups->current_group) { $bp->groups->current_group = new BP_Groups_Group($group_id); } $new_member = new BP_Groups_Member(); $new_member->group_id = $group_id; $new_member->user_id = $creator_id; $new_member->inviter_id = 0; $new_member->is_admin = 0; $new_member->user_title = ''; $new_member->date_modified = $date_created; $new_member->is_confirmed = 1; $new_member->save(); groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1); groups_update_groupmeta($group_id, 'last_activity', $date_created); do_action('groups_join_group', $group_id, $creator_id); } if ($skip_activity) { continue; } // Activity item $topic = bp_forums_get_topic_details($topic_id); $activity_action = sprintf(__('%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'); $activity_content = bp_create_excerpt($reply->description); $primary_link = bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'; //if ( $page ) // $primary_link .= "?topic_page=" . $page; //echo $primary_link; die(); groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_post_action', $activity_action, $post_id, $reply->description, $topic), 'content' => apply_filters('groups_activity_new_forum_post_content', $activity_content, $post_id, $reply->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}"), 'type' => 'new_forum_post', 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0)); do_action('groups_new_forum_topic_post', $group_id, $post_id); } } $imported[$discussion->id] = true; $counter++; } update_option('bp_ning_discussions_imported', $imported); return true; }
function bp_group_management_join_group($group_id, $user_id = false) { global $bp; if (!$user_id) { $user_id = $bp->loggedin_user->id; } /* Check if the user has an outstanding invite, is so delete it. */ if (groups_check_user_has_invite($user_id, $group_id)) { groups_delete_invite($user_id, $group_id); } /* Check if the user has an outstanding request, is so delete it. */ if (groups_check_for_membership_request($user_id, $group_id)) { groups_delete_membership_request($user_id, $group_id); } /* User is already a member, just return true */ if (groups_is_user_member($user_id, $group_id)) { return true; } if (!$bp->groups->current_group) { $bp->groups->current_group = new BP_Groups_Group($group_id); } $new_member = new BP_Groups_Member(); $new_member->group_id = $group_id; $new_member->user_id = $user_id; $new_member->inviter_id = 0; $new_member->is_admin = 0; $new_member->user_title = ''; $new_member->date_modified = gmdate("Y-m-d H:i:s"); $new_member->is_confirmed = 1; if (!$new_member->save()) { return false; } /* Record this in activity streams */ groups_record_activity(array('user_id' => $user_id, 'action' => apply_filters('groups_activity_joined_group', sprintf(__('%s joined the group %s', 'bp-group-management'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_html($bp->groups->current_group->name) . '</a>')), 'type' => 'joined_group', 'item_id' => $group_id)); /* Modify group meta */ groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1); groups_update_groupmeta($group_id, 'last_activity', gmdate("Y-m-d H:i:s")); do_action('groups_join_group', $group_id, $user_id); return true; }
/** * Save or update a new event * @version 2.0 */ function save_event($post_id, $post = '') { // Don't do anything if it's not an event if ('event' != $post->post_type) { return; } // Verify the nonce before proceeding. if (!isset($_POST['event-details-box']) || !wp_verify_nonce($_POST['event-details-box'], basename(__FILE__))) { return $post_id; } /* ----------------------------------- SAVE EVENT TIME ------------------------------------*/ // Retrieve the event time $event_time = date('Y-m-d H:i:s', strtotime($_POST['event-time'])); $prior_time = $post->post_date; // Update the post object $post->post_date = $event_time; remove_action('save_post', array($this, 'save_event')); wp_update_post($post); add_action('save_post', array($this, 'save_event'), 10, 2); /* ----------------------------------- SAVE META INFORMATION ------------------------------------ */ // Define the meta to look for $meta = array('event_duration' => $_POST['event-duration'], 'event_capacity' => $_POST['event-capacity'], 'event_rsvp' => $_POST['event-rsvp'], 'event_role' => $_POST['event-role']); // Loop through each meta, saving it to the database foreach ($meta as $meta_key => $new_meta_value) { // Get the meta value of the custom field key. $meta_value = get_post_meta($post_id, $meta_key, true); // If there is no new meta value but an old value exists, delete it. if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) { delete_post_meta($post_id, $meta_key, $meta_value); } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) { add_post_meta($post_id, $meta_key, $new_meta_value, true); } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $new_meta_value && $new_meta_value != $meta_value) { update_post_meta($post_id, $meta_key, $new_meta_value); } } // Delete the RSVP meta if the date has changed if ($event_time != $prior_time) { delete_post_meta($post_id, 'event_rsvps'); } /* ----------------------------------- BUDDYPRESS NOTIFICATION ------------------------------------ */ // Get event data global $bp, $wpdb; if (!$user_id) { $user_id = $post->post_author; } // Figure out which calendars this event belongs to $calendars = wp_get_post_terms($post_id, 'calendar'); $group_slugs = array(); // For each calendar, check if it's a group calendar foreach ($calendars as $calendar) { if (is_group_calendar($calendar->term_id)) { $groups[] = $calendar; } } // If this event does not belong to a group, we can stop here if (empty($groups)) { return $post_id; } // Only register notifications for future or published events if (!in_array($post->post_status, array('publish', 'future'))) { return $post_id; } // Loop through each group, adding an activity entry for each one foreach ($groups as $group) { // Get the group data $group_id = groups_get_id($group->slug); $group_name = $group->name; // Configure the activity entry $post_permalink = get_permalink($post_id); $activity_action = sprintf('%1$s added the event %2$s to the %3$s.', bp_core_get_userlink($post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', $group_name . ' <a href="' . SITEURL . '/calendar/' . $group->slug . '">group calendar</a>'); $activity_content = $post->post_content; // Check for existing entry $activity_id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $bp->groups->id, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id)); // Record the entry groups_record_activity(array('id' => $activity_id, 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post_permalink, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id)); // Update the group's last activity meta groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time()); // Maybe notify every group member if ($_POST['event-rsvp']) { if (bp_group_has_members($args = array('group_id' => $group_id, 'exclude_admins_mods' => false, 'per_page' => 99999))) { while (bp_members()) { bp_the_member(); // Remove any existing notifications ( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) bp_notifications_delete_notifications_by_item_id(bp_get_group_member_id(), $group_id, $bp->groups->id, 'new_calendar_event', $post_id); // Send a notification ( itemid , groupid , component, action , secondary ) bp_notifications_add_notification(array('user_id' => bp_get_group_member_id(), 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_calendar_event')); } } } } }
function bp_cover_group_handle_upload($activity_id) { global $bp, $wpdb; $group_id = bp_get_current_group_id(); $activity_table = $wpdb->prefix . "bp_activity"; $activity_meta_table = $wpdb->prefix . "bp_activity_meta"; $sql = "SELECT COUNT(*) as photo_count FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.item_id = %d AND meta_key = 'all_bp_cover_group'"; $sql = $wpdb->prepare($sql, $group_id); $cnt = $wpdb->get_var($sql); $max_cnt = bp_cover_get_max_total(); if ($cnt < $max_cnt) { if ($_POST['encodedimg']) { $file = $_POST['imgsize']; $max_upload_size = bp_cover_get_max_media_size(); if ($max_upload_size > $file) { $group_id = $bp->groups->current_group->id; $imgresponse = array(); $uploaddir = wp_upload_dir(); /* let's decode the base64 encoded image sent */ $img = $_POST['encodedimg']; $img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $imgname = wp_unique_filename($uploaddir['path'], $_POST['imgname']); $filepath = $uploaddir['path'] . '/' . $imgname; $fileurl = $uploaddir['url'] . '/' . $imgname; /* now we write the image in dir */ $success = file_put_contents($filepath, $data); if ($success) { $imgresponse[0] = "1"; $imgresponse[1] = $fileurl; $size = @getimagesize($filepath); $attachment = array('post_mime_type' => $_POST['imgtype'], 'guid' => $fileurl, 'post_title' => $imgname); require_once ABSPATH . 'wp-admin/includes/image.php'; $attachment_id = wp_insert_attachment($attachment, $filepath); $attach_data = wp_generate_attachment_metadata($attachment_id, $filepath); wp_update_attachment_metadata($attachment_id, $attach_data); groups_update_groupmeta($group_id, 'bp_cover_group', $fileurl); groups_update_groupmeta($group_id, 'bp_cover_group_position', 0); $group = groups_get_group(array("group_id" => $group_id)); $activity_id = groups_record_activity(array('action' => sprintf(__('%s uploaded a new cover picture to the group %s', 'bp-cover'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), 'type' => 'cover_added', 'item_id' => $group_id, 'content' => bp_cover_group_get_image_scr(), 'item_id' => $group_id)); bp_activity_update_meta($activity_id, 'all_bp_cover_group', $attachment_id); update_post_meta($attachment_id, 'bp_cover_group_thumb', $imgresponse[2]); } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size)); } } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('Max total images allowed %d in a cover gallery', 'bp-cover'), $max_cnt); } /* if everything is ok, we send back url to thumbnail and to full image */ echo json_encode($imgresponse); die; }
/** * activity_for_schedule( $schedule_count, $type = "add" ) * * Function generates activity updates on schedule actions * @param Int $schedule_count, nr of added schedules * @param String $type, the type of action: add - default, on schedule creations */ function activity_for_schedule($schedule_count, $type = "add") { global $bp; $activity_action = sprintf(__('%s updated %s Courseware schedule.', 'bpsp'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . attribute_escape($bp->groups->current_group->name) . '</a>'); $primary_link = bp_get_group_permalink($bp->groups->current_group) . 'courseware/schedules/'; groups_record_activity(array('action' => apply_filters('courseware_schedule_activity_action', $activity_action), 'primary_link' => apply_filters('courseware_schedule_activity_primary_link', $primary_link), 'type' => "schedule_{$type}", 'item_id' => $bp->groups->current_group->id)); }
function groups_accept_membership_request($membership_id, $user_id = 0, $group_id = 0) { if (!empty($user_id) && !empty($group_id)) { $membership = new BP_Groups_Member($user_id, $group_id); } else { $membership = new BP_Groups_Member(false, false, $membership_id); } $membership->accept_request(); if (!$membership->save()) { return false; } // Check if the user has an outstanding invite, if so delete it. if (groups_check_user_has_invite($membership->user_id, $membership->group_id)) { groups_delete_invite($membership->user_id, $membership->group_id); } // Record this in activity streams $group = groups_get_group(array('group_id' => $membership->group_id)); groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_membership_accepted_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink($membership->user_id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), $membership->user_id, &$group)), 'type' => 'joined_group', 'item_id' => $membership->group_id, 'user_id' => $membership->user_id)); // Send a notification to the user. groups_notification_membership_request_completed($membership->user_id, $membership->group_id, true); do_action('groups_membership_accepted', $membership->user_id, $membership->group_id); return true; }
/** * Create a wall activity for this user after posting an answer. * * @param CMA_Thread $instance * @param CMA_Answer $answer */ static function answer_posted_activity(CMA_Thread $instance, CMA_Answer $answer) { if (!$instance->isPublished()) { return; } else { if (!$answer->isApproved() or $answer->isPrivate()) { return; } } $post = $instance->getPost(); $user_id = $answer->getAuthorId(); $permalink = $answer->getPermalink(); $action = sprintf(CMA::__('%s answered to the question "%s"'), bp_core_get_userlink($user_id), sprintf('<a href="%s">%s</a>', esc_attr($permalink), esc_html($instance->getTitle()))); $content = CMA_Thread::lightContent($answer->getContent()); if (function_exists('bp_activity_add')) { bp_activity_add(array('action' => $action, 'content' => $content, 'component' => self::COMPONENT, 'type' => 'answer_posted', 'primary_link' => $permalink, 'user_id' => $user_id, 'item_id' => $answer->getId())); } if ($category = $instance->getCategory()) { $groups = self::getRelatedGroups(array($category->getId(), $category->getParentId())); if ($groups) { foreach ($groups as $groupId) { if (function_exists('groups_record_activity')) { groups_record_activity(array('action' => $action, 'content' => $content, 'type' => 'new_groupblog_post', 'primary_link' => $permalink, 'item_id' => $groupId, 'secondary_item_id' => $answer->getAuthorId(), 'hide_sitewide' => 0)); } } } } }
private function _construct_unique_rsvp_activity($event_id, $user_id, $rsvp) { $group_id = $this->_is_group_event($event_id); if ($this->_data->get_option('bp-activity_autoupdate-user_rsvp_group_only') && !$group_id) { return false; } $event = new Eab_EventModel(get_post($event_id)); $user_link = bp_core_get_userlink($user_id); $update = false; switch ($rsvp) { case Eab_EventModel::BOOKING_YES: $update = sprintf(__('%s will be attending <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; case Eab_EventModel::BOOKING_MAYBE: $update = sprintf(__('%s will maybe attend <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; case Eab_EventModel::BOOKING_NO: $update = sprintf(__('%s won\'t be attending <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; } if (!$update) { return false; } $raw_activity = array('user_id' => $user_id, 'action' => $update, 'type' => 'event_rsvp', 'item_id' => $event->get_id()); if ($this->_data->get_option('bp-activity_autoupdate-user_rsvp_group_post') && $group_id) { global $bp; $group_activity = $raw_activity; $group_activity['component'] = $bp->groups->id; $group_activity['item_id'] = $group_id; $group_activity['secondary_item_id'] = $event->get_id(); $existing = bp_activity_get(array("filter" => array('user_id' => $user_id, "object" => $bp->groups->id, "action" => 'event_rsvp', 'primary_id' => $group_id, 'secondary_id' => $event->get_id()))); if (isset($existing['activities']) && !empty($existing['activities'])) { $old = reset($existing['activities']); if (is_object($old) && isset($old->id)) { $group_activity['id'] = $old->id; } } // Add group activity update groups_record_activity($group_activity); } else { $activity = $raw_activity; $activity['component'] = 'eab_events'; $existing = bp_activity_get(array("filter" => array('user_id' => $user_id, "object" => 'eab_events', "action" => 'event_rsvp', 'primary_id' => $event->get_id()))); if (isset($existing['activities']) && !empty($existing['activities'])) { $old = reset($existing['activities']); if (is_object($old) && isset($old->id)) { $activity['id'] = $old->id; } } // Add site/user activity update bp_activity_add($activity); } }
function groups_accept_membership_request($membership_id) { global $bp; /* Check the nonce first. */ if (!check_admin_referer('groups_accept_membership_request')) { return false; } $membership = new BP_Groups_Member(false, false, $membership_id); $membership->accept_request(); if (!$membership->save()) { return false; } /* Modify group member count */ groups_update_groupmeta($membership->group_id, 'total_member_count', (int) groups_get_groupmeta($membership->group_id, 'total_member_count') + 1); /* Record this in activity streams */ groups_record_activity(array('item_id' => $membership->group_id, 'component_name' => $bp->groups->slug, 'component_action' => 'joined_group', 'is_private' => 0)); /* Send a notification to the user. */ require_once BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php'; groups_notification_membership_request_completed($membership->user_id, $membership->group_id, true); do_action('groups_membership_accepted', $membership->user_id, $membership->group_id); return true; }
/** * Add an activity item when a group's details are updated. * * @since 2.2.0 * * @param int $group_id ID of the group. * @param BP_Groups_Group $old_group Group object before the details had been changed. * @param bool $notify_members True if the admin has opted to notify group members, otherwise false. * @return int|bool The ID of the activity on success. False on error. */ function bp_groups_group_details_updated_add_activity($group_id, $old_group, $notify_members) { // Bail if Activity is not active. if (!bp_is_active('activity')) { return false; } if (!isset($old_group->name) || !isset($old_group->description)) { return false; } // If the admin has opted not to notify members, don't post an activity item either. if (empty($notify_members)) { return; } $group = groups_get_group(array('group_id' => $group_id)); /* * Store the changed data, which will be used to generate the activity * action. Since we haven't yet created the activity item, we store the * old group data in groupmeta, keyed by the timestamp that we'll put * on the activity item. */ $changed = array(); if ($group->name !== $old_group->name) { $changed['name'] = array('old' => $old_group->name, 'new' => $group->name); } if ($group->description !== $old_group->description) { $changed['description'] = array('old' => $old_group->description, 'new' => $group->description); } // If there are no changes, don't post an activity item. if (empty($changed)) { return; } $time = bp_core_current_time(); groups_update_groupmeta($group_id, 'updated_details_' . $time, $changed); // Record in activity streams. return groups_record_activity(array('type' => 'group_details_updated', 'item_id' => $group_id, 'user_id' => bp_loggedin_user_id(), 'recorded_time' => $time)); }
/** * * @since 0.0.5 * @access public * @static * @param $args * @return mixed */ public static function add_activity($args) { $defaults = array('id' => NULL, 'user' => false, 'user_id' => false, 'action' => '', 'content' => '', 'primary_link' => '', 'type' => RW_Group_Blogs_Core::$activity_type, 'item_id' => '', 'secondary_item_id' => '', 'recorded_time' => gmdate("Y-m-d H:i:s"), 'hide_sitewide' => true); $args = wp_parse_args($args, $defaults); $userdata = get_user_by('login', $args['user']); if (groups_is_user_member($userdata->ID, $args['item_id'])) { if ($args['user_id'] !== false) { $args['user_id'] = $userdata->ID; } // Add new record $back = groups_record_activity(array('id' => $args['id'], 'user_id' => $args['user_id'], 'action' => $args['action'], 'content' => $args['content'], 'primary_link' => $args['primary_link'], 'type' => $args['type'], 'item_id' => $args['item_id'], 'secondary_item_id' => $args['secondary_item_id'], 'recorded_time' => $args['recorded_time'], 'hide_sitewide' => $args['hide_sitewide'])); if ($back === false) { $ret = array('errors' => 406, 'message' => 'Activity not created'); } else { $ret = array('message' => "ok"); } } else { $ret = array('errors' => 403, 'message' => 'Activity not created'); } return $ret; }
/** * Catch and process group creation form submissions. */ function groups_action_create_group() { global $bp; // If we're not at domain.org/groups/create/ then return false if (!bp_is_groups_component() || !bp_is_current_action('create')) { return false; } if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug())); } // Make sure creation steps are in the right order groups_action_sort_creation_steps(); // If no current step is set, reset everything so we can start a fresh group creation $bp->groups->current_create_step = bp_action_variable(1); if (!bp_get_groups_current_create_step()) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH); setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH); $reset_steps = true; $keys = array_keys($bp->groups->group_creation_steps); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/'); } // If this is a creation step that is not recognized, just redirect them back to the first screen if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) { bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } // Fetch the currently completed steps variable if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) { $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps']))); } // Set the ID of the new group, if it has already been created in a previous step if (isset($_COOKIE['bp_new_group_id'])) { $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id)); // Only allow the group creator to continue to edit the new group if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) { bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } } // If the save, upload or skip button is hit, lets calculate what we need to save if (isset($_POST['save'])) { // Check the nonce check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step()); if ('group-details' == bp_get_groups_current_create_step()) { if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) { bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0; if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } } if ('group-settings' == bp_get_groups_current_create_step()) { $group_status = 'public'; $group_enable_forum = 1; if (!isset($_POST['group-show-forum'])) { $group_enable_forum = 0; } else { // Create the forum if enable_forum = 1 if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) { groups_new_group_forum(); } } if ('private' == $_POST['group-status']) { $group_status = 'private'; } else { if ('hidden' == $_POST['group-status']) { $group_status = 'hidden'; } } if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } // Set the invite status // Checked against a whitelist for security $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins')); $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members'; groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status); } if ('group-invites' === bp_get_groups_current_create_step()) { if (!empty($_POST['friends'])) { foreach ((array) $_POST['friends'] as $friend) { groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id)); } } groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id); } do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step()); do_action('groups_create_group_step_complete'); // Mostly for clearing cache on a generic action name /** * Once we have successfully saved the details for this step of the creation process * we need to add the current step to the array of completed steps, then update the cookies * holding the information */ $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array(); if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) { $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step(); } // Reset cookie info setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH); setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH); // If we have completed all steps and hit done on the final step we // can redirect to the completed group $keys = array_keys($bp->groups->group_creation_steps); if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); // Once we compelete all steps, record the group creation in the activity stream. groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id)); do_action('groups_group_create_complete', $bp->groups->new_group_id); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group)); } else { /** * Since we don't know what the next step is going to be (any plugin can insert steps) * we need to loop the step array and fetch the next step that way. */ foreach ($keys as $key) { if ($key == bp_get_groups_current_create_step()) { $next = 1; continue; } if (isset($next)) { $next_step = $key; break; } } bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/'); } } // Remove invitations if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) { if (!check_admin_referer('groups_invite_uninvite_user')) { return false; } $message = __('Invite successfully removed', 'buddypress'); $error = false; if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) { $message = __('There was an error removing the invite', 'buddypress'); $error = 'error'; } bp_core_add_message($message, $error); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/'); } // Group avatar is handled separately if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) { if (!isset($bp->avatar_admin)) { $bp->avatar_admin = new stdClass(); } if (!empty($_FILES) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead // Pass the file to the avatar upload handler if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) { $bp->avatar_admin->step = 'crop-image'; // Make sure we include the jQuery jCrop file for image cropping add_action('wp_print_scripts', 'bp_core_add_jquery_cropper'); } } // If the image cropping is done, crop the image and save a full/thumb version if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) { bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error'); } else { bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress')); } } } bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create')); }
/** * Add an activity stream item when a member joins a group * * @since BuddyPress (1.9.0) * @param int $user_id * @param int $group_id */ function bp_groups_membership_accepted_add_activity($user_id, $group_id) { // Bail if Activity is not active if (!bp_is_active('activity')) { return false; } // Get the group so we can get it's name $group = groups_get_group(array('group_id' => $group_id)); // Record in activity streams groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_membership_accepted_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), $user_id, &$group)), 'type' => 'joined_group', 'item_id' => $group_id, 'user_id' => $user_id)); }
/** * Function to fetch group feeds and save RSS entries as BP activity items. * * @param int $group_id The group ID. */ function bp_groupblogs_fetch_group_feeds($group_id = false) { if (empty($group_id)) { $group_id = bp_get_current_group_id(); } if ($group_id == bp_get_current_group_id()) { $group = groups_get_current_group(); } else { $group = new BP_Groups_Group($group_id); } if (!$group) { return false; } $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds'); $items = array(); foreach ((array) $group_blogs as $feed_url) { $feed_url = trim($feed_url); if (empty($feed_url)) { continue; } // Make sure the feed is accessible $test = wp_remote_get($feed_url); if (is_wp_error($test)) { continue; } try { $rss = new SimpleXmlElement($test['body']); } catch (Exception $e) { continue; } $rss = fetch_feed(trim($feed_url)); if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity(10); $rss_items = $rss->get_items(0, $maxitems); foreach ($rss_items as $item) { $key = $item->get_date('U'); $items[$key]['title'] = $item->get_title(); $items[$key]['subtitle'] = $item->get_title(); //$items[$key]['author'] = $item->get_author()->get_name(); $items[$key]['blogname'] = $item->get_feed()->get_title(); $items[$key]['link'] = $item->get_permalink(); $items[$key]['blogurl'] = $item->get_feed()->get_link(); $items[$key]['description'] = $item->get_description(); $items[$key]['source'] = $item->get_source(); $items[$key]['copyright'] = $item->get_copyright(); $items[$key]['primary_link'] = $item->get_link(); $items[$key]['guid'] = $item->get_id(); $items[$key]['feedurl'] = $feed_url; } } } if (!empty($items)) { ksort($items); $items = array_reverse($items, true); } else { return false; } /* Set the visibility */ $hide_sitewide = 'public' != $group->status ? true : false; /* Record found blog posts in activity streams */ foreach ((array) $items as $post_date => $post) { $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . esc_attr($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'); $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>'; $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group); /* Fetch an existing activity_id if one exists. */ // backpat $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']))); // new method if (empty($id)) { $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_guid', 'value' => $post['guid'])))); // we've found an existing entry if (!empty($existing['activities'])) { $id = (int) $existing['activities'][0]->id; } } /* Record or update in activity streams. */ // Skip if it already exists if (empty($id)) { $aid = groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post['primary_link'], 'type' => 'exb', 'item_id' => $group_id, 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide)); // save rss guid as activity meta bp_activity_update_meta($aid, 'exb_guid', $post['guid']); bp_activity_update_meta($aid, 'exb_feedurl', $post['feedurl']); } } return $items; }
/** * Post an Activity status update affiliated with a group. * * @todo Should bail out when the Activity component is not active. * * @param array { * Array of arguments. * @type string $content The content of the update. * @type int $user_id Optional. ID of the user posting the update. Default: * ID of the logged-in user. * @type int $group_id Optional. ID of the group to be affiliated with the * update. Default: ID of the current group. * } * @return int */ function groups_post_update($args = '') { global $bp; $defaults = array('content' => false, 'user_id' => bp_loggedin_user_id(), 'group_id' => 0); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($group_id) && !empty($bp->groups->current_group->id)) { $group_id = $bp->groups->current_group->id; } if (empty($content) || !strlen(trim($content)) || empty($user_id) || empty($group_id)) { return false; } $bp->groups->current_group = groups_get_group(array('group_id' => $group_id)); // Be sure the user is a member of the group before posting. if (!bp_current_user_can('bp_moderate') && !groups_is_user_member($user_id, $group_id)) { return false; } // Record this in activity streams $activity_action = sprintf(__('%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $activity_content = $content; $activity_id = groups_record_activity(array('user_id' => $user_id, 'action' => apply_filters('groups_activity_new_update_action', $activity_action), 'content' => apply_filters('groups_activity_new_update_content', $activity_content), 'type' => 'activity_update', 'item_id' => $group_id)); groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time()); do_action('bp_groups_posted_update', $content, $user_id, $group_id, $activity_id); return $activity_id; }
/** * Update an existing group forum post. * * Uses the bundled version of bbPress packaged with BuddyPress. * * @since BuddyPress (1.1.0) * * @param int $post_id The post ID of the existing forum post. * @param string $post_text The text for the forum post. * @param int $topic_id The topic ID of the existing forum topic. * @param mixed $page The page number where the new forum post should reside. Optional. * * @return mixed The forum post ID on success. Boolean false on failure. */ function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false) { $bp = buddypress(); /** This filter is documented in bp-groups/bp-groups-forums.php */ $post_text = apply_filters('group_forum_post_text_before_save', $post_text); /** This filter is documented in bp-groups/bp-groups-forums.php */ $topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id); $post = bp_forums_get_post($post_id); $post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id)); if (empty($post_id)) { return false; } $topic = bp_forums_get_topic_details($topic_id); $activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>'); $activity_content = bp_create_excerpt($post_text); $primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/'; if (!empty($page)) { $primary_link .= "?topic_page=" . $page; } // Get the corresponding activity item if (bp_is_active('activity')) { $id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id)); } /** This filter is documented in bp-groups/bp-groups-forums.php */ $action = apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)); /** This filter is documented in bp-groups/bp-groups-forums.php */ $content = apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)); /** This filter is documented in bp-groups/bp-groups-forums.php */ $filtered_primary_link = apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id); groups_record_activity(array('id' => $id, 'action' => $action, 'content' => $content, 'primary_link' => $filtered_primary_link, 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time)); /** * Fires after the update of a group forum post. * * @since BuddyPress (1.1.0) * * @param object $post Object holding current post being updated. * @param object $topic Object holding current topic details. Passed by reference. */ do_action_ref_array('groups_update_group_forum_post', array($post, &$topic)); return $post_id; }
function bp_gtm_group_activity($args = '') { global $bp; $bp_gtm = get_option('bp_gtm'); if ($bp_gtm['display_activity'] == 'off') { return false; } $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id, 'group_id' => $bp->groups->current_group->id, 'elem_id' => false, 'elem_type' => 'task', 'elem_name' => false); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $bp->groups->current_group = new BP_Groups_Group($group_id); /* Be sure the user is a member of the group before posting. */ if (!is_super_admin() && !groups_is_user_member($user_id, $group_id)) { return false; } if ($elem_type == 'project') { $activity_action = sprintf(__('%s created the project - %s', 'bp_gtm'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/projects/view/' . $elem_id . '">' . bp_gtm_get_el_name_by_id($elem_id, $elem_type) . '</a>'); $activity_type = 'created_project'; } elseif ($elem_type == 'task') { $activity_action = sprintf(__('%s created the task - %s', 'bp_gtm'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/tasks/view/' . $elem_id . '">' . bp_gtm_get_el_name_by_id($elem_id, $elem_type) . '</a>'); $activity_type = 'created_task'; } else { if ($bp_gtm['display_activity_discuss'] == 'off') { return false; } // $elem_type = 'discuss_tasks_' . $_POST['task_id']; $discuss = explode('_', $elem_type); if ($discuss[1] == 'tasks') { $activity_action = sprintf(__('%s posted a comment to the task %s', 'bp_gtm'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/' . $discuss[1] . '/view/' . $discuss[2] . '#post-' . $elem_id . '">' . bp_gtm_get_el_name_by_id($discuss[2], $discuss[1]) . '</a>'); } elseif ($discuss[1] == 'projects') { $activity_action = sprintf(__('%s posted a comment to the project %s', 'bp_gtm'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/' . $discuss[1] . '/view/' . $discuss[2] . '#post-' . $elem_id . '">' . bp_gtm_get_el_name_by_id($discuss[2], $discuss[1]) . '</a>'); } $activity_type = 'created_discuss'; } $hide_sitewide = $bp->groups->current_group->status != 'private' || $bp->groups->current_group->status != 'hidden' ? TRUE : FALSE; /* Record this in activity streams */ $activity_id = groups_record_activity(array('user_id' => $user_id, 'action' => apply_filters('bp_gtm_activity_new_elem_action', $activity_action), 'content' => apply_filters('bp_gtm_activity_new_elem_content', $activity_content), 'type' => $activity_type, 'component' => $bp->groups->id, 'item_id' => $group_id, 'secondary_item_id' => $elem_id, 'hide_sitewide' => $hide_sitewide)); /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */ require_once BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php'; groups_update_groupmeta($group_id, 'last_activity', gmdate("Y-m-d H:i:s")); do_action('bp_groups_posted_update', $content, $user_id, $group_id, $activity_id); return $activity_id; }
/** * 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; }
function bpdd_import_groups_members($groups = false) { $members = array(); if (!$groups) { $groups = bpdd_get_random_groups_ids(0); } $new_member = new BP_Groups_Member(); foreach ($groups as $group_id) { $user_ids = bpdd_get_random_users_ids(rand(2, 15)); foreach ($user_ids as $user_id) { if (groups_is_user_member($user_id, $group_id)) { continue; } $time = bpdd_get_random_date(25, 1); $new_member->id = false; $new_member->group_id = $group_id; $new_member->user_id = $user_id; $new_member->inviter_id = 0; $new_member->is_admin = 0; $new_member->user_title = ''; $new_member->date_modified = $time; $new_member->is_confirmed = 1; // save data - finally if ($new_member->save()) { $group = new BP_Groups_Group($group_id); // record this in activity streams $activity_id[] = groups_record_activity(array('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>')), 'type' => 'joined_group', 'item_id' => $group_id, 'user_id' => $user_id, 'recorded_time' => $time)); // modify group meta groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1); groups_update_groupmeta($group_id, 'last_activity', $time); do_action('groups_join_group', $group_id, $user_id); // I need to know how many users were added to display in report after the import $members[] = $group_id; } } } return $members; }
/** * Post an Activity status update affiliated with a group. * * @todo Should bail out when the Activity component is not active. * * @param array|string $args { * Array of arguments. * @type string $content The content of the update. * @type int $user_id Optional. ID of the user posting the update. Default: * ID of the logged-in user. * @type int $group_id Optional. ID of the group to be affiliated with the * update. Default: ID of the current group. * } * @return int */ function groups_post_update($args = '') { $bp = buddypress(); $defaults = array('content' => false, 'user_id' => bp_loggedin_user_id(), 'group_id' => 0); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($group_id) && !empty($bp->groups->current_group->id)) { $group_id = $bp->groups->current_group->id; } if (empty($content) || !strlen(trim($content)) || empty($user_id) || empty($group_id)) { return false; } $bp->groups->current_group = groups_get_group(array('group_id' => $group_id)); // Be sure the user is a member of the group before posting. if (!bp_current_user_can('bp_moderate') && !groups_is_user_member($user_id, $group_id)) { return false; } // Record this in activity streams $activity_action = sprintf(__('%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>'); $activity_content = $content; /** * Filters the action for the new group activity update. * * @since 1.2.0 * * @param string $activity_action The new group activity update. */ $action = apply_filters('groups_activity_new_update_action', $activity_action); /** * Filters the content for the new group activity update. * * @since 1.2.0 * * @param string $activity_content The content of the update. */ $content_filtered = apply_filters('groups_activity_new_update_content', $activity_content); $activity_id = groups_record_activity(array('user_id' => $user_id, 'action' => $action, 'content' => $content_filtered, 'type' => 'activity_update', 'item_id' => $group_id)); groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time()); /** * Fires after posting of an Activity status update affiliated with a group. * * @since 1.2.0 * * @param string $content The content of the update. * @param int $user_id ID of the user posting the update. * @param int $group_id ID of the group being posted to. * @param bool $activity_id Whether or not the activity recording succeeded. */ do_action('bp_groups_posted_update', $content, $user_id, $group_id, $activity_id); return $activity_id; }
/** * * @since 0.0.1 * @access public * @static * @param bool $group_id * @return bool */ function fetch_group_feeds($group_id = false) { global $bp; include_once ABSPATH . 'wp-includes/rss.php'; if (empty($group_id)) { $group_id = $bp->groups->current_group->id; } if ($group_id == $bp->groups->current_group->id) { $group = $bp->groups->current_group; } else { $group = new BP_Groups_Group($group_id); } if (!$group) { return false; } $group_blogs = groups_get_groupmeta($group_id, 'rw-group-blogs-feeds'); /* Set the visibility */ $hide_sitewide = 'public' != $group->status ? true : false; foreach ((array) $group_blogs as $feed_url) { $rss = fetch_feed(trim($feed_url)); if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity(10); $rss_items = $rss->get_items(0, $maxitems); foreach ($rss_items as $item) { $key = $item->get_date('U'); $items[$key]['title'] = $item->get_title(); $items[$key]['subtitle'] = $item->get_title(); //$items[$key]['author'] = $item->get_author()->get_name(); $items[$key]['blogname'] = $item->get_feed()->get_title(); $items[$key]['link'] = $item->get_permalink(); $items[$key]['blogurl'] = $item->get_feed()->get_link(); $items[$key]['description'] = $item->get_description(); $items[$key]['source'] = $item->get_source(); $items[$key]['copyright'] = $item->get_copyright(); } } } if ($items) { ksort($items); $items = array_reverse($items, true); } else { return false; } /* Record found blog posts in activity streams */ foreach ((array) $items as $post_date => $post) { $activity_action = sprintf(__('Blog: %s from %s in the group %s', RW_Group_Blogs::$textdomain), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>'); $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>'; $activity_content = apply_filters('rw_group_blogs_activity_content', $activity_content, $post, $group); $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => $bp->groups->id, 'type' => RW_Group_Blogs_Core::$activity_type, 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']))); if ($id == NULL) { // Add new record groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $item->get_link(), 'type' => RW_Group_Blogs_Core::$activity_type, 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']), 'recorded_time' => gmdate("Y-m-d H:i:s"), 'hide_sitewide' => $hide_sitewide)); } } return $items; }