本文整理汇总了PHP中groups_join_group函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_join_group函数的具体用法?PHP groups_join_group怎么用?PHP groups_join_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_join_group函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$users = array(array('aardvark', 'Bob Smith'), array('alpaca red', 'William Quinn'), array('cat', 'Lauren Curtis'), array('caterpillar', 'Eldon Burrows'), array('dog green', 'Reece Thornton'), array('pig', 'Joshua Barton'), array('rabbit blue', 'Amber Hooper'), array('smith', 'Robert Bar'), array('snake', 'Eleanor Moore'), array('xylo', 'Silver McFadden'), array('zoom', 'Lisa Smithy'));
$factory = new BP_UnitTest_Factory();
// Create some dummy users.
foreach ($users as $user_index => $user) {
$new_user = $factory->user->create(array('display_name' => $user[1], 'user_login' => $user[0], 'user_email' => "test-{$user_index}@example.com"));
self::$user_ids[$user[0]] = $new_user;
}
self::$group_slugs['hidden'] = 'the-maw';
self::$group_slugs['public'] = 'the-great-journey';
self::$group_slugs['private'] = 'tsavo-highway';
// Create dummy groups.
self::$group_ids['hidden'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['hidden'], 'status' => 'hidden'));
self::$group_ids['public'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['public'], 'status' => 'public'));
self::$group_ids['private'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['private'], 'status' => 'private'));
// Add dummy users to dummy hidden groups.
groups_join_group(self::$group_ids['hidden'], self::$user_ids['pig']);
groups_join_group(self::$group_ids['hidden'], self::$user_ids['alpaca red']);
// Add dummy users to dummy public groups.
groups_join_group(self::$group_ids['public'], self::$user_ids['aardvark']);
groups_join_group(self::$group_ids['public'], self::$user_ids['alpaca red']);
groups_join_group(self::$group_ids['public'], self::$user_ids['cat']);
groups_join_group(self::$group_ids['public'], self::$user_ids['smith']);
// Add dummy users to dummy private groups.
groups_join_group(self::$group_ids['private'], self::$user_ids['cat']);
groups_join_group(self::$group_ids['private'], self::$user_ids['caterpillar']);
self::commit_transaction();
}
示例2: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
$user = elgg_get_logged_in_user_entity();
$group = get_entity($params->guid);
// join or request
$join = false;
if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
// anyone can join public groups and admins can join any group
$join = true;
} else {
if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
// user has invite to closed group
$join = true;
}
}
if ($join) {
if (groups_join_group($group, $user)) {
$msg = elgg_echo("groups:joined");
} else {
throw new GraphException(elgg_echo("groups:cantjoin"));
}
} else {
if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) {
throw new GraphException(elgg_echo("groups:joinrequestnotmade"));
}
$owner = $group->getOwnerEntity();
$url = elgg_normalize_url("groups/requests/{$group->guid}");
$subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
$body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
// Notify group owner
notify_user($owner->guid, $user->getGUID(), $subject, $body);
$msg = elgg_echo("groups:joinrequestmade");
}
return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid)));
}
示例3: bp_forums_directory_forums_setup
/**
* Load the Forums directory.
*/
function bp_forums_directory_forums_setup()
{
// Get BuddyPress once
$bp = buddypress();
if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) {
if (!bp_forums_has_directory()) {
return false;
}
if (!bp_forums_is_installed_correctly()) {
bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error');
bp_core_redirect(bp_get_root_domain());
}
bp_update_is_directory(true, 'forums');
do_action('bbpress_init');
// Check to see if the user has posted a new topic from the forums page.
if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
check_admin_referer('bp_forums_new_topic');
$bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id']));
if (!empty($bp->groups->current_group->id)) {
// Auto join this user if they are not yet a member of this group
if (!bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
groups_join_group($bp->groups->current_group->id);
}
$error_message = '';
$forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
if (!empty($forum_id)) {
if (empty($_POST['topic_title'])) {
$error_message = __('Please provide a title for your forum topic.', 'buddypress');
} else {
if (empty($_POST['topic_text'])) {
$error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
}
}
if ($error_message) {
bp_core_add_message($error_message, 'error');
$redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
} else {
if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
$redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
} else {
bp_core_add_message(__('The topic was created successfully', 'buddypress'));
$redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
}
}
bp_core_redirect($redirect);
} else {
bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
}
} else {
bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
}
}
do_action('bp_forums_directory_forums_setup');
bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index'));
}
}
示例4: group_join
/**
* Web service for joining a group
*
* @param string $username username of author
* @param string $groupid GUID of the group
*
* @return bool
*/
function group_join($username, $groupid)
{
$user = get_user_by_username($username);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$group = get_entity($groupid);
$return['success'] = false;
if ($user instanceof ElggUser && $group instanceof ElggGroup) {
// join or request
$join = false;
if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
// anyone can join public groups and admins can join any group
$join = true;
} else {
if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
// user has invite to closed group
$join = true;
}
}
if ($join) {
if (groups_join_group($group, $user)) {
$return['success'] = true;
$return['message'] = elgg_echo("groups:joined");
} else {
$return['message'] = elgg_echo("groups:cantjoin");
}
} else {
add_entity_relationship($user->guid, 'membership_request', $group->guid);
// Notify group owner
$url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}";
$subject = elgg_echo('groups:request:subject', array($user->name, $group->name));
$body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url));
if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
$return['success'] = true;
$return['message'] = elgg_echo("groups:joinrequestmade");
} else {
$return['message'] = elgg_echo("groups:joinrequestnotmade");
}
}
} else {
$return['message'] = elgg_echo("groups:cantjoin");
}
return $return;
}
示例5: bp_forums_directory_forums_setup
function bp_forums_directory_forums_setup() {
global $bp;
if ( $bp->current_component == $bp->forums->slug ) {
if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
return false;
if ( !bp_forums_is_installed_correctly() ) {
bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
bp_core_redirect( $bp->root_domain );
}
$bp->is_directory = true;
do_action( 'bbpress_init' );
/* Check to see if the user has posted a new topic from the forums page. */
if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
/* Check the nonce */
check_admin_referer( 'bp_forums_new_topic' );
if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
/* Auto join this user if they are not yet a member of this group */
if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
else
bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
} else {
bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
}
}
}
do_action( 'bp_forums_directory_forums_setup' );
bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
}
}
示例6: bp_group_reviews_extension
function bp_group_reviews_extension()
{
global $bp;
$this->group_id = BP_Groups_Group::group_exists($bp->current_item);
$this->name = __('Reviews', 'bpgr');
$this->slug = $bp->group_reviews->slug;
$this->nav_item_position = 22;
$this->enable_create_step = false;
$this->enable_nav_item = BP_Group_Reviews::current_group_is_available();
$this->enable_edit_item = false;
if (isset($_POST['review_submit'])) {
check_admin_referer('review_submit');
$has_posted = '';
if (empty($_POST['review_content']) || !(int) $_POST['rating']) {
// Something has gone wrong. Save the user's submitted data to reinsert into the post box after redirect
$cookie_data = array('review_content' => $_POST['review_content'], 'rating' => $_POST['rating']);
$cookie = json_encode($cookie_data);
setcookie('bpgr-data', $cookie, time() + 60 * 60 * 24, COOKIEPATH);
bp_core_add_message(__("Please make sure you fill in the review, and don't forget to provide a rating!", 'bpgr'), 'error');
} else {
/* Auto join this user if they are not yet a member of this group */
if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) {
groups_join_group($bp->groups->current_group->id, $bp->loggedin_user->id);
}
if ($rating_id = $this->post_review(array('content' => $_POST['review_content'], 'rating' => (int) $_POST['rating']))) {
bp_core_add_message("Your review was posted successfully!");
$has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review');
if (!in_array((int) $bp->loggedin_user->id, (array) $has_posted)) {
$has_posted[] = (int) $bp->loggedin_user->id;
}
groups_update_groupmeta($bp->groups->current_group->id, 'posted_review', $has_posted);
if ((int) $_POST['rating'] < 0) {
$_POST['rating'] = 1;
}
if ((int) $_POST['rating'] > 5) {
$_POST['rating'] = 5;
}
} else {
bp_core_add_message("There was a problem posting your review, please try again.", 'error');
}
}
bp_core_redirect(apply_filters('bpgr_after_post_redirect', trailingslashit(bp_get_group_permalink($bp->groups->current_group) . $this->slug, $has_posted)));
}
}
示例7: test_groups_join_group_cleanup_requests
/**
* @group groups_join_group
* @group group_membership
*/
public function test_groups_join_group_cleanup_requests()
{
$u1 = $this->factory->user->create();
$g = $this->factory->group->create();
self::create_group_membership_request($u1, $g);
groups_join_group($g, $u1);
// Upon joining the group, outstanding requests should be cleaned up.
$this->assertEquals(null, groups_check_for_membership_request($u1, $g));
}
示例8: group_join_group
/**
* @param $guid
* @return mixed
* @throws InvalidParameterException
*/
function group_join_group($guid)
{
global $CONFIG;
$user = elgg_get_logged_in_user_entity();
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
/* @var ElggGroup $group */
$group = get_entity($guid);
if (!$group instanceof ElggGroup) {
$return['joined'] = false;
$return['message'] = 'Group Not Found';
exit;
}
// access bypass for getting invisible group
$ia = elgg_set_ignore_access(true);
elgg_set_ignore_access($ia);
if ($user && $group instanceof ElggGroup) {
// join or request
$join = false;
if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
// anyone can join public groups and admins can join any group
$join = true;
} else {
if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
// user has invite to closed group
$join = true;
}
}
if ($join) {
if (groups_join_group($group, $user)) {
$return['member'] = 'joined';
$return['message'] = 'joined';
} else {
$isMember = isMemberOf($group, $user);
if ($isMember) {
$return['member'] = 'joined';
$return['message'] = 'isMemberOf';
} else {
$return['member'] = 'cantjoin';
$return['message'] = 'cantjoin';
}
}
} else {
add_entity_relationship($user->guid, 'membership_request', $group->guid);
$owner = $group->getOwnerEntity();
$url = "{$CONFIG->url}groups/requests/{$group->guid}";
$subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
$body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
// Notify group owner
if (notify_user($owner->guid, $user->getGUID(), $subject, $body)) {
$return['member'] = 'cantjoin';
$return['message'] = 'joinrequestmade';
} else {
$return['member'] = 'cantjoin';
$return['message'] = 'joinrequestnotmade';
}
}
} else {
$isMember = isMemberOf($group, $user);
if ($isMember) {
$return['member'] = 'joined';
$return['message'] = 'isMemberOf';
} else {
$return['member'] = 'cantjoin';
$return['message'] = 'cantjoin';
}
}
return $return;
}
示例9: bp_course_add_user_to_course
function bp_course_add_user_to_course($user_id, $course_id)
{
$duration = get_post_meta($course_id, 'vibe_duration', true);
$course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
$t = time() + $duration * $course_duration_parameter;
update_post_meta($course_id, $user_id, 0);
update_user_meta($user_id, 'course_status' . $course_id, 1);
update_user_meta($user_id, $course_id, $t);
$group_id = get_post_meta($course_id, 'vibe_group', true);
if (isset($group_id) && $group_id != '') {
groups_join_group($group_id, $user_id);
} else {
$group_id = '';
}
do_action('wplms_course_subscribed', $course, $user_id, $group_id);
}
示例10: wplms_edd_completed_purchase
function wplms_edd_completed_purchase($payment_id, $new_status, $old_status)
{
if ($old_status == 'publish' || $old_status == 'complete') {
return;
}
// Make sure that payments are only completed once
// Make sure the payment completion is only processed when new status is complete
if ($new_status != 'publish' && $new_status != 'complete') {
return;
}
$user_id = get_current_user_id();
$cart_items = edd_get_payment_meta_cart_details($payment_id);
foreach ($cart_items as $key => $cart_item) {
$item_id = isset($cart_item['id']) ? $cart_item['id'] : $cart_item;
if (is_numeric($item_id) && get_post_type($item_id) == 'download') {
$courses = vibe_sanitize(get_post_meta($item_id, 'vibe_courses', false));
$subscribed = get_post_meta($product_id, 'vibe_subscription', true);
if (vibe_validate($subscribed)) {
$duration = get_post_meta($product_id, 'vibe_duration', true);
$product_duration_parameter = apply_filters('vibe_product_duration_parameter', 86400);
// Product duration for subscription based
$t = time() + $duration * $product_duration_parameter;
foreach ($courses as $course) {
update_post_meta($course, $user_id, 0);
update_user_meta($user_id, $course, $t);
$group_id = get_post_meta($course, 'vibe_group', true);
if (isset($group_id) && $group_id != '') {
groups_join_group($group_id, $user_id);
}
bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
}
} else {
if (isset($courses) && is_array($courses)) {
foreach ($courses as $course) {
$duration = get_post_meta($course, 'vibe_duration', true);
$course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
// Course duration for subscription based
$t = time() + $duration * $course_duration_parameter;
update_post_meta($course, $user_id, 0);
update_user_meta($user_id, $course, $t);
$group_id = get_post_meta($course, 'vibe_group', true);
if (isset($group_id) && $group_id != '') {
groups_join_group($group_id, $user_id);
}
bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
}
}
}
}
}
}
示例11: bp_groups_admin_load
//.........这里部分代码省略.........
*
* @since 1.0.2
*
* @param array $value Array of allowed group statuses.
*/
$allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
$status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
/**
* Filters the allowed invite status values for the group.
*
* @since 1.5.0
*
* @param array $value Array of allowed invite statuses.
*/
$allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
$invite_status = in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
if (!groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status)) {
$error = $group_id;
}
// Process new members
$user_names = array();
if (!empty($_POST['bp-groups-new-members'])) {
$user_names = array_merge($user_names, explode(',', $_POST['bp-groups-new-members']));
}
if (!empty($user_names)) {
foreach (array_values($user_names) as $user_name) {
$un = trim($user_name);
// Make sure the user exists before attempting
// to add to the group
$user = get_user_by('slug', $un);
if (empty($user)) {
$error_new[] = $un;
} else {
if (!groups_join_group($group_id, $user->ID)) {
$error_new[] = $un;
} else {
$success_new[] = $un;
}
}
}
}
// Process member role changes
if (!empty($_POST['bp-groups-role']) && !empty($_POST['bp-groups-existing-role'])) {
// Before processing anything, make sure you're not
// attempting to remove the all user admins
$admin_count = 0;
foreach ((array) $_POST['bp-groups-role'] as $new_role) {
if ('admin' == $new_role) {
$admin_count++;
break;
}
}
if (!$admin_count) {
$redirect_to = add_query_arg('no_admins', 1, $redirect_to);
$error = $group_id;
} else {
// Process only those users who have had their roles changed
foreach ((array) $_POST['bp-groups-role'] as $user_id => $new_role) {
$existing_role = isset($_POST['bp-groups-existing-role'][$user_id]) ? $_POST['bp-groups-existing-role'][$user_id] : '';
if ($existing_role != $new_role) {
switch ($new_role) {
case 'mod':
// Admin to mod is a demotion. Demote to
// member, then fall through
if ('admin' == $existing_role) {
groups_demote_member($user_id, $group_id);
示例12: bp_dtheme_ajax_joinleave_group
function bp_dtheme_ajax_joinleave_group()
{
global $bp;
if (groups_is_user_banned($bp->loggedin_user->id, $_POST['gid'])) {
return false;
}
if (!($group = new BP_Groups_Group($_POST['gid'], false, false))) {
return false;
}
if (!groups_is_user_member($bp->loggedin_user->id, $group->id)) {
if ('public' == $group->status) {
check_ajax_referer('groups_join_group');
if (!groups_join_group($group->id)) {
_e('Error joining group', 'buddypress');
} else {
echo '<a id="group-' . esc_attr($group->id) . '" class="leave-group" rel="leave" title="' . __('Leave Group', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'leave-group', 'groups_leave_group') . '">' . __('Leave Group', 'buddypress') . '</a>';
}
} else {
if ('private' == $group->status) {
check_ajax_referer('groups_request_membership');
if (!groups_send_membership_request($bp->loggedin_user->id, $group->id)) {
_e('Error requesting membership', 'buddypress');
} else {
echo '<a id="group-' . esc_attr($group->id) . '" class="membership-requested" rel="membership-requested" title="' . __('Membership Requested', 'buddypress') . '" href="' . bp_get_group_permalink($group) . '">' . __('Membership Requested', 'buddypress') . '</a>';
}
}
}
} else {
check_ajax_referer('groups_leave_group');
if (!groups_leave_group($group->id)) {
_e('Error leaving group', 'buddypress');
} else {
if ('public' == $group->status) {
echo '<a id="group-' . esc_attr($group->id) . '" class="join-group" rel="join" title="' . __('Join Group', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'join', 'groups_join_group') . '">' . __('Join Group', 'buddypress') . '</a>';
} else {
if ('private' == $group->status) {
echo '<a id="group-' . esc_attr($group->id) . '" class="request-membership" rel="join" title="' . __('Request Membership', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'request-membership', 'groups_send_membership_request') . '">' . __('Request Membership', 'buddypress') . '</a>';
}
}
}
}
}
示例13: bp_legacy_theme_ajax_joinleave_group
/**
* Join or leave a group when clicking the "join/leave" button via a POST request.
*
* @return string HTML
* @since BuddyPress (1.2)
*/
function bp_legacy_theme_ajax_joinleave_group()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Cast gid as integer
$group_id = (int) $_POST['gid'];
if (groups_is_user_banned(bp_loggedin_user_id(), $group_id)) {
return;
}
if (!($group = groups_get_group(array('group_id' => $group_id)))) {
return;
}
if (!groups_is_user_member(bp_loggedin_user_id(), $group->id)) {
if ('public' == $group->status) {
check_ajax_referer('groups_join_group');
if (!groups_join_group($group->id)) {
_e('Error joining group', 'buddypress');
} else {
echo '<a id="group-' . esc_attr($group->id) . '" class="leave-group" rel="leave" title="' . __('Leave Group', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'leave-group', 'groups_leave_group') . '">' . __('Leave Group', 'buddypress') . '</a>';
}
} elseif ('private' == $group->status) {
// If the user has already been invited, then this is
// an Accept Invitation button
if (groups_check_user_has_invite(bp_loggedin_user_id(), $group->id)) {
check_ajax_referer('groups_accept_invite');
if (!groups_accept_invite(bp_loggedin_user_id(), $group->id)) {
_e('Error requesting membership', 'buddypress');
} else {
echo '<a id="group-' . esc_attr($group->id) . '" class="leave-group" rel="leave" title="' . __('Leave Group', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'leave-group', 'groups_leave_group') . '">' . __('Leave Group', 'buddypress') . '</a>';
}
// Otherwise, it's a Request Membership button
} else {
check_ajax_referer('groups_request_membership');
if (!groups_send_membership_request(bp_loggedin_user_id(), $group->id)) {
_e('Error requesting membership', 'buddypress');
} else {
echo '<a id="group-' . esc_attr($group->id) . '" class="membership-requested" rel="membership-requested" title="' . __('Membership Requested', 'buddypress') . '" href="' . bp_get_group_permalink($group) . '">' . __('Membership Requested', 'buddypress') . '</a>';
}
}
}
} else {
check_ajax_referer('groups_leave_group');
if (!groups_leave_group($group->id)) {
_e('Error leaving group', 'buddypress');
} elseif ('public' == $group->status) {
echo '<a id="group-' . esc_attr($group->id) . '" class="join-group" rel="join" title="' . __('Join Group', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'join', 'groups_join_group') . '">' . __('Join Group', 'buddypress') . '</a>';
} elseif ('private' == $group->status) {
echo '<a id="group-' . esc_attr($group->id) . '" class="request-membership" rel="join" title="' . __('Request Membership', 'buddypress') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'request-membership', 'groups_send_membership_request') . '">' . __('Request Membership', 'buddypress') . '</a>';
}
}
exit;
}
示例14: groups_screen_group_forum
/**
* This screen function handles actions related to group forums.
*/
function groups_screen_group_forum()
{
if (!bp_is_active('forums') || !bp_forums_is_installed_correctly()) {
return false;
}
if (bp_action_variable(0) && !bp_is_action_variable('topic', 0)) {
bp_do_404();
return;
}
$bp = buddypress();
if (!$bp->groups->current_group->user_has_access) {
bp_core_no_access();
return;
}
if (!bp_is_single_item()) {
return false;
}
// Fetch the details we need.
$topic_slug = (string) bp_action_variable(1);
$topic_id = bp_forums_get_topic_id_from_slug($topic_slug);
$forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
$user_is_banned = false;
if (!bp_current_user_can('bp_moderate') && groups_is_user_banned(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
$user_is_banned = true;
}
if (!empty($topic_slug) && !empty($topic_id)) {
// Posting a reply.
if (!$user_is_banned && !bp_action_variable(2) && isset($_POST['submit_reply'])) {
// Check the nonce.
check_admin_referer('bp_forums_new_reply');
// Auto join this user if they are not yet a member of this group.
if (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
}
$topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
// Don't allow reply flooding.
if (bp_forums_reply_exists($_POST['reply_text'], $topic_id, bp_loggedin_user_id())) {
bp_core_add_message(__('It looks like you\'ve already said that!', 'buddypress'), 'error');
} else {
if (!($post_id = groups_new_group_forum_post($_POST['reply_text'], $topic_id, $topic_page))) {
bp_core_add_message(__('There was an error when replying to that topic', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Your reply was posted successfully', 'buddypress'));
}
}
$query_vars = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
$redirect = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
if (!empty($post_id)) {
$redirect .= '#post-' . $post_id;
}
bp_core_redirect($redirect);
} elseif (bp_is_action_variable('stick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
// Check the nonce.
check_admin_referer('bp_forums_stick_topic');
if (!bp_forums_sticky_topic(array('topic_id' => $topic_id))) {
bp_core_add_message(__('There was an error when making that topic a sticky', 'buddypress'), 'error');
} else {
bp_core_add_message(__('The topic was made sticky successfully', 'buddypress'));
}
/**
* Fires after a group forum topic has been stickied.
*
* @since 1.1.0
*
* @param int $topic_id ID of the topic being stickied.
*/
do_action('groups_stick_forum_topic', $topic_id);
bp_core_redirect(wp_get_referer());
} elseif (bp_is_action_variable('unstick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
// Check the nonce.
check_admin_referer('bp_forums_unstick_topic');
if (!bp_forums_sticky_topic(array('topic_id' => $topic_id, 'mode' => 'unstick'))) {
bp_core_add_message(__('There was an error when unsticking that topic', 'buddypress'), 'error');
} else {
bp_core_add_message(__('The topic was unstuck successfully', 'buddypress'));
}
/**
* Fires after a group forum topic has been un-stickied.
*
* @since 1.1.0
*
* @param int $topic_id ID of the topic being un-stickied.
*/
do_action('groups_unstick_forum_topic', $topic_id);
bp_core_redirect(wp_get_referer());
} elseif (bp_is_action_variable('close', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
// Check the nonce.
check_admin_referer('bp_forums_close_topic');
if (!bp_forums_openclose_topic(array('topic_id' => $topic_id))) {
bp_core_add_message(__('There was an error when closing that topic', 'buddypress'), 'error');
} else {
bp_core_add_message(__('The topic was closed successfully', 'buddypress'));
}
/**
* Fires after a group forum topic has been closed.
*
* @since 1.1.0
//.........这里部分代码省略.........
示例15: test_bp_has_activities_hidden_group_home_scope
/**
* @ticket BP6169
* @group bp_has_activities
*/
public function test_bp_has_activities_hidden_group_home_scope()
{
global $activities_template;
$bp = buddypress();
$reset_current_group = $bp->groups->current_group;
$reset_current_action = $bp->current_action;
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$u3 = $this->factory->user->create();
$this->set_current_user($u1);
$g = $this->factory->group->create(array('status' => 'hidden'));
groups_join_group($g, $u2);
groups_join_group($g, $u3);
$a1 = $this->factory->activity->create(array('component' => $bp->groups->id, 'item_id' => $g, 'type' => 'activity_update', 'user_id' => $u2, 'content' => 'foo bar'));
$a2 = $this->factory->activity->create(array('component' => $bp->groups->id, 'item_id' => $g, 'type' => 'activity_update', 'user_id' => $u3, 'content' => 'bar foo'));
$bp->groups->current_group = groups_get_group(array('group_id' => $g, 'populate_extras' => true));
// On group's home the scope is set to 'home'
$bp->current_action = 'home';
bp_has_activities(array('action' => 'activity_update'));
$this->assertEqualSets(array($a1, $a2), wp_list_pluck($activities_template->activities, 'id'));
// clean up!
$activities_template = null;
$bp->groups->current_group = $reset_current_group;
$bp->current_action = $reset_current_action;
}