Пример #1
0
 public function test_groups_is_user_banned_should_return_true_for_banned_member()
 {
     $this->add_user_to_group(self::$user, self::$groups[1]);
     $m = new BP_Groups_Member(self::$user, self::$groups[1]);
     $m->ban();
     $this->assertNotEmpty(groups_is_user_banned(self::$user, self::$groups[1]));
 }
/**
 * Get a user's membership status in multiple groups. The group ids should be in provided as post arguments ('grpids').
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_get_joinleave_group_status()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    error_log("og joileavegroup " . groups_get_id("students"));
    $myretval = array();
    // Cast gid as integer
    $my_group_ids = $_POST['grpids'];
    error_log("og group status:" . print_r($my_group_ids, true));
    for ($myidx = 0; $myidx < count($my_group_ids); $myidx++) {
        $group_id = (int) $my_group_ids[$myidx];
        //$_POST['gid'];
        error_log("og group id:" . $group_id . " ");
        $bp_loggedin_user_id = bp_loggedin_user_id();
        if (groups_is_user_banned($bp_loggedin_user_id, $group_id)) {
            $myretval[$my_group_ids[$myidx]] = "";
        } else {
            if ($group = groups_get_group(array('group_id' => $group_id, 'populate_extras' => true))) {
                //return;
                //$htmlstrtoreturn = bp_legacy_theme_ajax_get_user_joinleave_group_status($group, $bp_loggedin_user_id);
                $htmlstrtoreturn = bp_legacy_theme_ajax_get_user_joinleave_group_status($group);
                $myretval[$my_group_ids[$myidx]] = $htmlstrtoreturn;
            }
        }
    }
    echo json_encode($myretval);
    exit;
}
Пример #3
0
/**
 * Get a list of friends that a user can invite into this group.
 *
 * Excludes friends that are already in the group, and banned friends if the
 * user is not a group admin.
 *
 * @since BuddyPress (1.0.0)
 *
 * @param int $user_id User ID whose friends to see can be invited. Default:
 *        ID of the logged-in user.
 * @param int $group_id Group to check possible invitations against.
 * @return mixed False if no friends, array of users if friends.
 */
function friends_get_friends_invite_list($user_id = 0, $group_id = 0)
{
    // Default to logged in user id
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // Only group admins can invited previously banned users
    $user_is_admin = (bool) groups_is_user_admin($user_id, $group_id);
    // Assume no friends
    $friends = array();
    // Default args
    $args = apply_filters('bp_friends_pre_get_invite_list', array('user_id' => $user_id, 'type' => 'alphabetical', 'per_page' => 0));
    // User has friends
    if (bp_has_members($args)) {
        /**
         * Loop through all friends and try to add them to the invitation list.
         *
         * Exclude friends that:
         *     1. are already members of the group
         *     2. are banned from this group if the current user is also not a
         *        group admin.
         */
        while (bp_members()) {
            // Load the member
            bp_the_member();
            // Get the user ID of the friend
            $friend_user_id = bp_get_member_user_id();
            // Skip friend if already in the group
            if (groups_is_user_member($friend_user_id, $group_id)) {
                continue;
            }
            // Skip friend if not group admin and user banned from group
            if (false === $user_is_admin && groups_is_user_banned($friend_user_id, $group_id)) {
                continue;
            }
            // Friend is safe, so add it to the array of possible friends
            $friends[] = array('id' => $friend_user_id, 'full_name' => bp_get_member_name());
        }
    }
    // If no friends, explicitly set to false
    if (empty($friends)) {
        $friends = false;
    }
    // Allow friends to be filtered
    return apply_filters('bp_friends_get_invite_list', $friends, $user_id, $group_id);
}
Пример #4
0
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>';
                }
            }
        }
    }
}
function bp_get_group_member_is_banned()
{
    global $members_template, $groups_template;
    return apply_filters('bp_get_group_member_is_banned', groups_is_user_banned($members_template->member->user_id, $groups_template->group->id));
}
Пример #6
0
/**
 * Check if a user is banned from a group.
 *
 * If this function is invoked inside the groups template loop, then we check
 * $groups_template->group->is_banned instead of using {@link groups_is_user_banned()}
 * and making another SQL query.
 *
 * In BuddyPress 2.1, to standardize this function, we are defaulting the
 * return value to a boolean.  In previous versions, using this function would
 * return either a string of the integer (0 or 1) or null if a result couldn't
 * be found from the database.  If the logged-in user had the 'bp_moderate'
 * capability, the return value would be boolean false.
 *
 * @since BuddyPress (1.5.0)
 *
 * @global BP_Groups_Template $groups_template Group template loop object
 * @param BP_Groups_Group $group Group to check if user is banned
 * @param int $user_id The user ID to check
 * @return bool True if user is banned.  False if user isn't banned.
 */
function bp_group_is_user_banned($group = false, $user_id = 0)
{
    global $groups_template;
    // Site admins always have access
    if (bp_current_user_can('bp_moderate')) {
        return false;
    }
    // check groups loop first
    // @see BP_Groups_Group::get_group_extras()
    if (!empty($groups_template->in_the_loop) && isset($groups_template->group->is_banned)) {
        $retval = $groups_template->group->is_banned;
        // not in loop
    } else {
        // Default to not banned
        $retval = false;
        if (empty($group)) {
            $group = $groups_template->group;
        }
        if (empty($user_id)) {
            $user_id = bp_loggedin_user_id();
        }
        if (!empty($user_id) && !empty($group->id)) {
            $retval = groups_is_user_banned($user_id, $group->id);
        }
    }
    return (bool) apply_filters('bp_group_is_user_banned', $retval);
}
/**
 * Check if a user is banned from a group.
 *
 * If this function is invoked inside the groups template loop, then we check
 * $groups_template->group->is_banned instead of using {@link groups_is_user_banned()}
 * and making another SQL query.
 *
 * In BuddyPress 2.1, to standardize this function, we are defaulting the
 * return value to a boolean.  In previous versions, using this function would
 * return either a string of the integer (0 or 1) or null if a result couldn't
 * be found from the database.  If the logged-in user had the 'bp_moderate'
 * capability, the return value would be boolean false.
 *
 * @since 1.5.0
 *
 * @global BP_Groups_Template $groups_template Group template loop object.
 *
 * @param BP_Groups_Group|bool $group   Group to check if user is banned.
 * @param int                  $user_id The user ID to check.
 * @return bool True if user is banned.  False if user isn't banned.
 */
function bp_group_is_user_banned($group = false, $user_id = 0)
{
    global $groups_template;
    // Site admins always have access.
    if (bp_current_user_can('bp_moderate')) {
        return false;
    }
    // Check groups loop first
    // @see BP_Groups_Group::get_group_extras().
    if (!empty($groups_template->in_the_loop) && isset($groups_template->group->is_banned)) {
        $retval = $groups_template->group->is_banned;
        // Not in loop.
    } else {
        // Default to not banned.
        $retval = false;
        if (empty($group)) {
            $group = $groups_template->group;
        }
        if (empty($user_id)) {
            $user_id = bp_loggedin_user_id();
        }
        if (!empty($user_id) && !empty($group->id)) {
            $retval = groups_is_user_banned($user_id, $group->id);
        }
    }
    /**
     * Filters whether current user has been banned from current group in loop.
     *
     * @since 1.5.0
     * @since 2.5.0 Added the `$group` parameter.
     *
     * @param bool   $is_invited If user has been from current group.
     * @param object $group      Group object.
     */
    return (bool) apply_filters('bp_group_is_user_banned', $retval, $group);
}
Пример #8
0
function groups_send_membership_request( $requesting_user_id, $group_id ) {
	global $bp;

	/* Prevent duplicate requests */
	if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) )
		return false;

	/* Check if the user is already a member or is banned */
	if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) )
		return false;

	$requesting_user = new BP_Groups_Member;
	$requesting_user->group_id = $group_id;
	$requesting_user->user_id = $requesting_user_id;
	$requesting_user->inviter_id = 0;
	$requesting_user->is_admin = 0;
	$requesting_user->user_title = '';
	$requesting_user->date_modified = gmdate( "Y-m-d H:i:s" );
	$requesting_user->is_confirmed = 0;
	$requesting_user->comments = $_POST['group-request-membership-comments'];

	if ( $requesting_user->save() ) {
		$admins = groups_get_group_admins( $group_id );

		require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );

		for ( $i = 0; $i < count( $admins ); $i++ ) {
			// Saved okay, now send the email notification
			groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id );
		}

		do_action( 'groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id );

		return true;
	}

	return false;
}
Пример #9
0
/**
 * This screen function handles actions related to group forums
 *
 * @package BuddyPress
 */
function groups_screen_group_forum()
{
    global $bp;
    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;
    }
    if (!$bp->groups->current_group->user_has_access) {
        bp_core_no_access();
        return;
    }
    if (bp_is_single_item()) {
        // 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;
                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'));
                }
                if (isset($_SERVER['QUERY_STRING'])) {
                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
                }
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
            } else {
                if (bp_is_action_variable('stick', 2) && (isset($bp->is_item_admin) || isset($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'));
                    }
                    do_action('groups_stick_forum_topic', $topic_id);
                    bp_core_redirect(wp_get_referer());
                } else {
                    if (bp_is_action_variable('unstick', 2) && (isset($bp->is_item_admin) || isset($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'));
                        }
                        do_action('groups_unstick_forum_topic', $topic_id);
                        bp_core_redirect(wp_get_referer());
                    } else {
                        if (bp_is_action_variable('close', 2) && (isset($bp->is_item_admin) || isset($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'));
                            }
                            do_action('groups_close_forum_topic', $topic_id);
                            bp_core_redirect(wp_get_referer());
                        } else {
                            if (bp_is_action_variable('open', 2) && (isset($bp->is_item_admin) || isset($bp->is_item_mod))) {
                                // Check the nonce
                                check_admin_referer('bp_forums_open_topic');
                                if (!bp_forums_openclose_topic(array('topic_id' => $topic_id, 'mode' => 'open'))) {
                                    bp_core_add_message(__('There was an error when opening that topic', 'buddypress'), 'error');
                                } else {
                                    bp_core_add_message(__('The topic was opened successfully', 'buddypress'));
                                }
                                do_action('groups_open_forum_topic', $topic_id);
                                bp_core_redirect(wp_get_referer());
                            } else {
                                if (empty($user_is_banned) && bp_is_action_variable('delete', 2) && !bp_action_variable(3)) {
                                    // Fetch the topic
                                    $topic = bp_forums_get_topic_details($topic_id);
                                    /* Check the logged in user can delete this topic */
                                    if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                                        bp_core_redirect(wp_get_referer());
                                    }
                                    // Check the nonce
                                    check_admin_referer('bp_forums_delete_topic');
                                    do_action('groups_before_delete_forum_topic', $topic_id);
                                    if (!groups_delete_group_forum_topic($topic_id)) {
                                        bp_core_add_message(__('There was an error deleting the topic', 'buddypress'), 'error');
                                    } else {
                                        bp_core_add_message(__('The topic was deleted successfully', 'buddypress'));
                                    }
                                    do_action('groups_delete_forum_topic', $topic_id);
                                    bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/');
                                } else {
                                    if (empty($user_is_banned) && bp_is_action_variable('edit', 2) && !bp_action_variable(3)) {
                                        // Fetch the topic
                                        $topic = bp_forums_get_topic_details($topic_id);
                                        // Check the logged in user can edit this topic
                                        if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                                            bp_core_redirect(wp_get_referer());
                                        }
                                        if (isset($_POST['save_changes'])) {
                                            // Check the nonce
                                            check_admin_referer('bp_forums_edit_topic');
                                            $topic_tags = !empty($_POST['topic_tags']) ? $_POST['topic_tags'] : false;
                                            if (!groups_update_group_forum_topic($topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags)) {
                                                bp_core_add_message(__('There was an error when editing that topic', 'buddypress'), 'error');
                                            } else {
                                                bp_core_add_message(__('The topic was edited successfully', 'buddypress'));
                                            }
                                            do_action('groups_edit_forum_topic', $topic_id);
                                            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/');
                                        }
                                        bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
                                    } else {
                                        if (empty($user_is_banned) && bp_is_action_variable('delete', 2) && ($post_id = bp_action_variable(4))) {
                                            // Fetch the post
                                            $post = bp_forums_get_post($post_id);
                                            // Check the logged in user can edit this topic
                                            if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                                                bp_core_redirect(wp_get_referer());
                                            }
                                            // Check the nonce
                                            check_admin_referer('bp_forums_delete_post');
                                            do_action('groups_before_delete_forum_post', $post_id);
                                            if (!groups_delete_group_forum_post($post_id)) {
                                                bp_core_add_message(__('There was an error deleting that post', 'buddypress'), 'error');
                                            } else {
                                                bp_core_add_message(__('The post was deleted successfully', 'buddypress'));
                                            }
                                            do_action('groups_delete_forum_post', $post_id);
                                            bp_core_redirect(wp_get_referer());
                                        } else {
                                            if (empty($user_is_banned) && bp_is_action_variable('edit', 2) && ($post_id = bp_action_variable(4))) {
                                                // Fetch the post
                                                $post = bp_forums_get_post($post_id);
                                                // Check the logged in user can edit this topic
                                                if (!$bp->is_item_admin && !$bp->is_item_mod && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                                                    bp_core_redirect(wp_get_referer());
                                                }
                                                if (isset($_POST['save_changes'])) {
                                                    // Check the nonce
                                                    check_admin_referer('bp_forums_edit_post');
                                                    $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                                                    if (!($post_id = groups_update_group_forum_post($post_id, $_POST['post_text'], $topic_id, $topic_page))) {
                                                        bp_core_add_message(__('There was an error when editing that post', 'buddypress'), 'error');
                                                    } else {
                                                        bp_core_add_message(__('The post was edited successfully', 'buddypress'));
                                                    }
                                                    if ($_SERVER['QUERY_STRING']) {
                                                        $query_vars = '?' . $_SERVER['QUERY_STRING'];
                                                    }
                                                    do_action('groups_edit_forum_post', $post_id);
                                                    bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
                                                }
                                                bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
                                            } else {
                                                if (!empty($user_is_banned)) {
                                                    bp_core_add_message(__("You have been banned from this group.", 'buddypress'));
                                                }
                                                bp_core_load_template(apply_filters('groups_template_group_forum_topic', 'groups/single/home'));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Forum topic does not exist
        } elseif (!empty($topic_slug) && empty($topic_id)) {
            bp_do_404();
            return;
        } else {
            // Posting a topic
            if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
                // Check the nonce
                check_admin_referer('bp_forums_new_topic');
                if ($user_is_banned) {
                    $error_message = __("You have been banned from this group.", 'buddypress');
                } elseif (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)) {
                    // Auto join this user if they are not yet a member of this group
                    groups_join_group($bp->groups->current_group->id, bp_loggedin_user_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 (empty($forum_id)) {
                    $error_message = __('This group does not have a forum setup yet.', 'buddypress');
                }
                if (isset($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);
            }
            do_action('groups_screen_group_forum', $topic_id, $forum_id);
            bp_core_load_template(apply_filters('groups_template_group_forum', 'groups/single/home'));
        }
    }
}
function bp_group_management_add_member_list($id)
{
    global $wpdb;
    $settings = get_option('bp_gm_settings');
    if (!($per_page = $settings['members_per_page'])) {
        $per_page = 50;
    }
    ?>

	<div class="bp-gm-add-members">
		<h3><?php 
    _e('Add members to group', 'bp-group-management');
    ?>
</h3>
		<ul>
		<?php 
    $query = "SELECT `ID` FROM {$wpdb->users}";
    if (is_multisite()) {
        $query .= " WHERE spam = 0";
    }
    $members = $wpdb->get_results($query, ARRAY_A);
    foreach ($members as $key => $m) {
        if (groups_is_user_member($m['ID'], $id)) {
            unset($members[$key]);
        }
        if (groups_is_user_banned($m['ID'], $id)) {
            unset($members[$key]);
        }
    }
    $members = array_values($members);
    if (isset($_GET['members_page'])) {
        $start = ($_GET['members_page'] - 1) * $per_page;
    } else {
        $start = 0;
    }
    //print "<pre>";
    //print_r($members);
    $pag_links = paginate_links(array('base' => add_query_arg('members_page', '%#%'), 'format' => '', 'total' => ceil(count($members) / $per_page), 'current' => isset($_GET['members_page']) ? $_GET['members_page'] : false, 'show_all' => false, 'prev_next' => true, 'prev_text' => '&larr;', 'next_text' => '&rarr;', 'mid_size' => 4, 'type' => 'list'));
    echo '<div class="tablenav"> <div class="tablenav-pages">';
    echo $pag_links;
    echo '</div></div>';
    echo '<ul>';
    for ($i = $start; $i < $start + $per_page; $i++) {
        if (empty($members[$i])) {
            break;
        }
        $addlink = "admin.php?page=bp-group-management&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . $members[$i]['ID'] . "&amp;member_action=add";
        if (isset($_GET['members_page'])) {
            $addlink .= "&amp;members_page=" . $_GET['members_page'];
        }
        $addlink = function_exists('wp_nonce_url') ? wp_nonce_url($addlink, 'bp-group-management-action_add') : $addlink;
        ?>
			<li>
				<strong><a href="<?php 
        echo $addlink;
        ?>
"><?php 
        _e('Add', 'bp-group-management');
        ?>
</a></strong> - <?php 
        echo bp_core_get_userlink($members[$i]['ID']);
        ?>
			</li>



			<?php 
    }
    echo '</ul>';
    ?>
		</ul>

			<?php 
    do_action('bp_gm_more_group_actions');
    ?>

		<div style="clear: both;"> </div>

		<a class="button" id="bp-gm-settings-link" href="admin.php?page=bp-group-management&action=settings">Plugin settings</a>
	</div>
<?php 
}
Пример #11
0
/**
 * Is the current user banned from the current group
 *
 * @since bbPress (r4632)
 *
 * @uses is_user_logged_in()
 * @uses bp_is_group()
 * @uses bbpress()
 * @uses get_current_user_id()
 * @uses bp_get_current_group_id()
 * @uses groups_is_user_admin()
 * @return bool If current user is banned from the current group
 */
function bbp_group_is_banned()
{
    // Bail if user is not logged in or not looking at a group
    if (!is_user_logged_in() || !bp_is_group()) {
        return false;
    }
    $bbp = bbpress();
    // Set the global if not set
    if (!isset($bbp->current_user->is_group_banned)) {
        $bbp->current_user->is_group_banned = groups_is_user_banned(get_current_user_id(), bp_get_current_group_id());
    }
    // Return the value
    return (bool) $bbp->current_user->is_group_banned;
}
 /**
  * Get a count of a user's friends who can be invited to a given group.
  *
  * Users can invite any of their friends except:
  *
  * - users who are already in the group
  * - users who have a pending invite to the group
  * - users who have been banned from the group
  *
  * @since 1.0.0
  * @todo Need to do a group component check before using group functions.
  *
  * @param int $user_id  ID of the user whose friends are being counted.
  * @param int $group_id ID of the group friends are being invited to.
  * @return int $invitable_count Eligible friend count.
  */
 public static function get_invitable_friend_count($user_id, $group_id)
 {
     // Setup some data we'll use below.
     $is_group_admin = groups_is_user_admin($user_id, $group_id);
     $friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id);
     $invitable_count = 0;
     for ($i = 0, $count = count($friend_ids); $i < $count; ++$i) {
         // If already a member, they cannot be invited again.
         if (groups_is_user_member((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         // If user already has invite, they cannot be added.
         if (groups_check_user_has_invite((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         // If user is not group admin and friend is banned, they cannot be invited.
         if (false === $is_group_admin && groups_is_user_banned((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         $invitable_count++;
     }
     return $invitable_count;
 }
Пример #13
0
function groups_action_join_group()
{
    global $bp;
    global $group_obj;
    if (!$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'join') {
        return false;
    }
    // user wants to join a group
    if (!groups_is_user_member($bp->loggedin_user->id, $group_obj->id) && !groups_is_user_banned($bp->loggedin_user->id, $group_obj->id)) {
        if (!groups_join_group($group_obj->id)) {
            bp_core_add_message(__('There was an error joining the group.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('You joined the group!', 'buddypress'));
        }
        bp_core_redirect(bp_get_group_permalink($group_obj));
    }
    bp_core_load_template(apply_filters('groups_template_group_home', 'groups/group-home'));
}
 /**
  * Post by email handler.
  *
  * Validate data and post on success.
  *
  * @param bool $retval True by default.
  * @param array $data {
  *     An array of arguments.
  *
  *     @type array $headers Email headers.
  *     @type string $content The email body content.
  *     @type string $subject The email subject line.
  *     @type int $user_id The user ID who sent the email.
  *     @type bool $is_html Whether the email content is HTML or not.
  *     @type int $i The email message number.
  * }
  * @param array $params Parsed paramaters from the email address querystring.
  *   See {@link BP_Reply_By_Email_Parser::get_parameters()}.
  * @return array|object Array of the parsed item on success. WP_Error object
  *  on failure.
  */
 public function post($retval, $data, $params)
 {
     global $bp;
     $comment_id = !empty($params[$this->secondary_item_id_param]) ? $params[$this->secondary_item_id_param] : false;
     $i = $data['i'];
     // this means that the current email is a BP Doc reply
     // let's proceed!
     if (!empty($comment_id)) {
         // it's important to let RBE know what's happening during the process
         // for debugging purposes
         //
         // use bp_rbe_log() to log anything you want
         // in this case, we're letting RBE know that we're in the process of
         // rendering a comment reply
         bp_rbe_log('Message #' . $i . ': this is a BP Doc comment reply');
         // get parent comment data
         $comment = get_comment($comment_id);
         // parent comment doesn't exist or was deleted
         if (empty($comment)) {
             // when a condition for posting isn't met, return a WP_Error object.
             // next, log it under the internal_rbe_log()_method
             // and optionally, prep a failure message under the failure_message_to_sender() method
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_parent_comment_deleted' );
             return new WP_Error('bp_doc_parent_comment_deleted', '', $data);
         }
         // parent comment status checks
         switch ($comment->comment_approved) {
             case 'spam':
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_parent_comment_spam' );
                 return new WP_Error('bp_doc_parent_comment_spam', '', $data);
                 break;
             case 'trash':
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_parent_comment_deleted' );
                 return new WP_Error('bp_doc_parent_comment_deleted', '', $data);
                 break;
             case '0':
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_parent_comment_unapproved' );
                 return new WP_Error('bp_doc_parent_comment_unapproved', '', $data);
                 break;
         }
         // get doc settings
         $doc_settings = get_post_meta($comment->comment_post_ID, 'bp_docs_settings', true);
         // set temporary variable
         $bp->rbe = $bp->rbe->temp = new stdClass();
         // get group ID
         // $bp->rbe->temp->group_id gets passed to BP_Reply_By_Email::set_group_id()
         $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param];
         // get user ID
         $user_id = $data['user_id'];
         // check to see if the user can post comments for the group doc in question
         //
         // bp_docs_user_can( 'post_comments', $user_id, $group_id ) doesn't work the way I want it to
         // using the doc's comment settings as a guideline
         // check the comment settings for the doc
         switch ($doc_settings['post_comments']) {
             // this means that the comment settings for the doc recently switched to 'no-one'
             case 'no-one':
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_comment_change_to_noone' );
                 return new WP_Error('bp_doc_comment_change_to_noone', '', $data);
                 break;
                 // if the doc only allows group admins and mods to comment, return false for regular group members
             // if the doc only allows group admins and mods to comment, return false for regular group members
             case 'admins-mods':
                 // get the email address of the replier
                 $user_email = BP_Reply_By_Email_Parser::get_header($data['headers'], 'From');
                 // get an array of group admin / mod email addresses
                 // note: email addresses are set as key, not value
                 $admin_mod_emails = $this->get_admin_mod_user_emails($group_id);
                 // if the replier's email address does not match a group admin or mod, stop now!
                 if (!isset($admin_mod_emails[$user_email])) {
                     //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_user_not_admin_mod' );
                     return new WP_Error('bp_doc_user_not_admin_mod', '', $data);
                 }
                 break;
                 // if the doc allows any group member to comment, check if member is still part of
                 // the group and not banned
             // if the doc allows any group member to comment, check if member is still part of
             // the group and not banned
             case 'group-members':
                 if (!groups_is_user_member($user_id, $group_id)) {
                     //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_user_not_member' );
                     return new WP_Error('bp_doc_user_not_member', '', $data);
                 }
                 if (groups_is_user_banned($user_id, $group_id)) {
                     //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_user_banned' );
                     return new WP_Error('bp_doc_user_banned', '', $data);
                 }
                 break;
         }
         /* okay! we should be good to post now! */
         // get the userdata
         $userdata = get_userdata($user_id);
         // we're using wp_insert_comment() instead of wp_new_comment()
         // why? because wp_insert_comment() bypasses all the WP comment hooks, which is good for us!
         $new_comment_id = wp_insert_comment(array('user_id' => $user_id, 'comment_post_ID' => $comment->comment_post_ID, 'comment_content' => $data['content'], 'comment_parent' => $comment_id, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => '', 'comment_author_email' => $userdata->user_email, 'comment_author_IP' => '', 'comment_agent' => '', 'comment_type' => ''));
         // comment successfully posted!
         if (!empty($new_comment_id)) {
             // more internal logging
             bp_rbe_log('Message #' . $i . ': BP Doc comment reply successfully posted!');
             /* now let's record the activity item for this comment */
             // override BP Docs' default comment activity action
             add_filter('bp_docs_comment_activity_action', array($this, 'comment_activity_action'));
             // now post the activity item with BP Docs' special class method
             if (class_exists('BP_Docs_BP_Integration')) {
                 // BP Docs v1.1.x support
                 $activity_id = BP_Docs_BP_Integration::post_comment_activity($new_comment_id);
             } else {
                 // BP Docs v1.2.x support
                 $activity_id = BP_Docs_Component::post_comment_activity($new_comment_id);
             }
             // special hook for RBE activity items
             // if you're adding an activity entry in this method, remember to add this hook after posting
             // your activity item in this method!
             do_action('bp_rbe_new_activity', array('activity_id' => $activity_id, 'type' => $this->activity_type, 'user_id' => $user_id, 'item_id' => $group_id, 'secondary_item_id' => $comment_id, 'content' => $data['content']));
             // remove the filter after posting
             remove_filter('bp_docs_comment_activity_action', array($this, 'comment_activity_action'));
             return array('bp_doc_comment_id' => $new_comment_id);
         } else {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bp_doc_new_comment_fail' );
             return new WP_Error('bp_doc_new_comment_fail', '', $data);
         }
     }
 }
Пример #15
0
/**
 * Join or leave a group when clicking the "join/leave" button via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_joinleave_group()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (groups_is_user_banned(bp_loggedin_user_id(), $_POST['gid'])) {
        return;
    }
    if (!($group = groups_get_group(array('group_id' => $_POST['gid'])))) {
        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', 'logicalboneshug');
            } else {
                echo '<a id="group-' . esc_attr($group->id) . '" class="leave-group" rel="leave" title="' . __('Leave Group', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'leave-group', 'groups_leave_group') . '">' . __('Leave Group', 'logicalboneshug') . '</a>';
            }
        } elseif ('private' == $group->status) {
            check_ajax_referer('groups_request_membership');
            if (!groups_send_membership_request(bp_loggedin_user_id(), $group->id)) {
                _e('Error requesting membership', 'logicalboneshug');
            } else {
                echo '<a id="group-' . esc_attr($group->id) . '" class="membership-requested" rel="membership-requested" title="' . __('Membership Requested', 'logicalboneshug') . '" href="' . bp_get_group_permalink($group) . '">' . __('Membership Requested', 'logicalboneshug') . '</a>';
            }
        }
    } else {
        check_ajax_referer('groups_leave_group');
        if (!groups_leave_group($group->id)) {
            _e('Error leaving group', 'logicalboneshug');
        } elseif ('public' == $group->status) {
            echo '<a id="group-' . esc_attr($group->id) . '" class="join-group" rel="join" title="' . __('Join Group', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'join', 'groups_join_group') . '">' . __('Join Group', 'logicalboneshug') . '</a>';
        } elseif ('private' == $group->status) {
            echo '<a id="group-' . esc_attr($group->id) . '" class="request-membership" rel="join" title="' . __('Request Membership', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_get_group_permalink($group) . 'request-membership', 'groups_send_membership_request') . '">' . __('Request Membership', 'logicalboneshug') . '</a>';
        }
    }
    exit;
}
Пример #16
0
/**
 * Catch and process "Join Group" button clicks.
 */
function groups_action_join_group()
{
    global $bp;
    if (!bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action('join')) {
        return false;
    }
    // Nonce check
    if (!check_admin_referer('groups_join_group')) {
        return false;
    }
    // Skip if banned or already a member
    if (!groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id) && !groups_is_user_banned(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
        // User wants to join a group that is not public
        if ($bp->groups->current_group->status != 'public') {
            if (!groups_check_user_has_invite(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error joining the group.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
            }
        }
        // User wants to join any group
        if (!groups_join_group($bp->groups->current_group->id)) {
            bp_core_add_message(__('There was an error joining the group.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('You joined the group!', 'buddypress'));
        }
        bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
    }
    bp_core_load_template(apply_filters('groups_template_group_home', 'groups/single/home'));
}
Пример #17
0
/**
 * 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
             *
             * @param int $topic_id ID of the topic being closed.
             */
            do_action('groups_close_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('open', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_open_topic');
            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id, 'mode' => 'open'))) {
                bp_core_add_message(__('There was an error when opening that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was opened successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been opened.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being opened.
             */
            do_action('groups_open_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            /* Check the logged in user can delete this topic */
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_topic');
            /**
             * Fires before a group forum topic is deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_before_delete_forum_topic', $topic_id);
            if (!groups_delete_group_forum_topic($topic_id)) {
                bp_core_add_message(__('There was an error deleting the topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_delete_forum_topic', $topic_id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/');
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_topic');
                $topic_tags = !empty($_POST['topic_tags']) ? $_POST['topic_tags'] : false;
                if (!groups_update_group_forum_topic($topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags)) {
                    bp_core_add_message(__('There was an error when editing that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The topic was edited successfully', 'buddypress'));
                }
                /**
                 * Fires after a group forum topic has been edited.
                 *
                 * @since 1.1.0
                 *
                 * @param int $topic_id ID of the topic being edited.
                 */
                do_action('groups_edit_forum_topic', $topic_id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/');
            }
            /**
             * Filters the template to load for a topic edit page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic edit template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Delete a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_post');
            /**
             * Fires before the deletion of a group forum post.
             *
             * @since 1.5.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_before_delete_forum_post', $post_id);
            if (!groups_delete_group_forum_post($post_id)) {
                bp_core_add_message(__('There was an error deleting that post', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The post was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after the deletion of a group forum post.
             *
             * @since 1.1.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_delete_forum_post', $post_id);
            bp_core_redirect(wp_get_referer());
            // Editing a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_post');
                $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                if (!($post_id = groups_update_group_forum_post($post_id, $_POST['post_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when editing that post', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The post was edited successfully', 'buddypress'));
                }
                if ($_SERVER['QUERY_STRING']) {
                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
                }
                /**
                 * Fires after the editing of a group forum post.
                 *
                 * @since 1.1.0
                 *
                 * @param int $post_id ID of the forum post being edited.
                 */
                do_action('groups_edit_forum_post', $post_id);
                bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
            }
            /** This filter is documented in bp-groups/bp-groups-screens.php */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Standard topic display.
        } else {
            if (!empty($user_is_banned)) {
                bp_core_add_message(__("You have been banned from this group.", 'buddypress'));
            }
            /**
             * Filters the template to load for a topic page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic', 'groups/single/home'));
        }
        // Forum topic does not exist.
    } elseif (!empty($topic_slug) && empty($topic_id)) {
        bp_do_404();
        return;
    } else {
        // Posting a topic.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            // Check the nonce.
            check_admin_referer('bp_forums_new_topic');
            if ($user_is_banned) {
                $error_message = __("You have been banned from this group.", 'buddypress');
            } elseif (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)) {
                // Auto join this user if they are not yet a member of this group.
                groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
            }
            if (empty($_POST['topic_title'])) {
                $error_message = __('Please provide a title for your forum topic.', 'buddypress');
            } elseif (empty($_POST['topic_text'])) {
                $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
            }
            if (empty($forum_id)) {
                $error_message = __('This group does not have a forum setup yet.', 'buddypress');
            }
            if (isset($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);
        }
        /**
         * Fires at the end of the group forum screen loading process.
         *
         * @since 1.0.0
         *
         * @param int $topic_id ID of the topic being displayed.
         * @param int $forum_id ID of the forum being displayed.
         */
        do_action('groups_screen_group_forum', $topic_id, $forum_id);
        /**
         * Filters the template to load for a group forum page.
         *
         * @since 1.0.0
         *
         * @param string $value Path to a group forum template.
         */
        bp_core_load_template(apply_filters('groups_template_group_forum', 'groups/single/home'));
    }
}
/**
 * Get a list of friends that a user can invite into this group.
 *
 * Excludes friends that are already in the group, and banned friends if the
 * user is not a group admin.
 *
 * @since 1.0.0
 *
 * @param int $user_id  User ID whose friends to see can be invited. Default:
 *                      ID of the logged-in user.
 * @param int $group_id Group to check possible invitations against.
 * @return mixed False if no friends, array of users if friends.
 */
function friends_get_friends_invite_list($user_id = 0, $group_id = 0)
{
    // Default to logged in user id.
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // Only group admins can invited previously banned users.
    $user_is_admin = (bool) groups_is_user_admin($user_id, $group_id);
    // Assume no friends.
    $friends = array();
    /**
     * Filters default arguments for list of friends a user can invite into this group.
     *
     * @since 1.5.4
     *
     * @param array $value Array of default parameters for invite list.
     */
    $args = apply_filters('bp_friends_pre_get_invite_list', array('user_id' => $user_id, 'type' => 'alphabetical', 'per_page' => 0));
    // User has friends.
    if (bp_has_members($args)) {
        /**
         * Loop through all friends and try to add them to the invitation list.
         *
         * Exclude friends that:
         *     1. are already members of the group
         *     2. are banned from this group if the current user is also not a
         *        group admin.
         */
        while (bp_members()) {
            // Load the member.
            bp_the_member();
            // Get the user ID of the friend.
            $friend_user_id = bp_get_member_user_id();
            // Skip friend if already in the group.
            if (groups_is_user_member($friend_user_id, $group_id)) {
                continue;
            }
            // Skip friend if not group admin and user banned from group.
            if (false === $user_is_admin && groups_is_user_banned($friend_user_id, $group_id)) {
                continue;
            }
            // Friend is safe, so add it to the array of possible friends.
            $friends[] = array('id' => $friend_user_id, 'full_name' => bp_get_member_name());
        }
    }
    // If no friends, explicitly set to false.
    if (empty($friends)) {
        $friends = false;
    }
    /**
     * Filters the list of potential friends that can be invited to this group.
     *
     * @since 1.5.4
     *
     * @param array|bool $friends  Array friends available to invite or false for no friends.
     * @param int        $user_id  ID of the user checked for who they can invite.
     * @param int        $group_id ID of the group being checked on.
     */
    return apply_filters('bp_friends_get_invite_list', $friends, $user_id, $group_id);
}
Пример #19
0
/**
 * 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;
}
Пример #20
0
/**
 * Checks if a user is banned from a group.
 *
 * If this function is invoked inside the groups template loop (e.g. the group directory), then
 * check $groups_template->group->is_banned instead of making another SQL query.
 * However, if used in a single group's pages, we must use groups_is_user_banned().
 *
 * @global object $bp BuddyPress global settings
 * @global BP_Groups_Template $groups_template Group template loop object
 * @param object $group Group to check if user is banned from the group
 * @param int $user_id
 * @return bool If user is banned from the group or not
 * @since 1.5
 */
function bp_group_is_user_banned($group = false, $user_id = 0)
{
    global $bp, $groups_template;
    // Site admins always have access
    if ($bp->loggedin_user->is_super_admin) {
        return false;
    }
    if (!$group) {
        $group =& $groups_template->group;
        if (!$user_id && isset($group->is_banned)) {
            return apply_filters('bp_group_is_user_banned', $group->is_banned);
        }
    }
    if (!$user_id) {
        $user_id = $bp->loggedin_user->id;
    }
    return apply_filters('bp_group_is_user_banned', groups_is_user_banned($user_id, $group->id));
}
/**
 * Checks if a user is banned from a group.
 *
 * If this function is invoked inside the groups template loop (e.g. the group directory), then
 * check $groups_template->group->is_banned instead of making another SQL query.
 * However, if used in a single group's pages, we must use groups_is_user_banned().
 *
 * @global BP_Groups_Template $groups_template Group template loop object
 * @param object $group Group to check if user is banned from the group
 * @param int $user_id
 * @return bool If user is banned from the group or not
 * @since BuddyPress (1.5)
 */
function bp_group_is_user_banned($group = false, $user_id = 0)
{
    global $groups_template;
    // Site admins always have access
    if (bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (empty($group)) {
        $group =& $groups_template->group;
        if (!$user_id && isset($group->is_banned)) {
            return apply_filters('bp_group_is_user_banned', $group->is_banned);
        }
    }
    if (!$user_id) {
        $user_id = bp_loggedin_user_id();
    }
    return apply_filters('bp_group_is_user_banned', groups_is_user_banned($user_id, $group->id));
}
function groups_send_membership_request($requesting_user_id, $group_id)
{
    // Prevent duplicate requests
    if (groups_check_for_membership_request($requesting_user_id, $group_id)) {
        return false;
    }
    // Check if the user is already a member or is banned
    if (groups_is_user_member($requesting_user_id, $group_id) || groups_is_user_banned($requesting_user_id, $group_id)) {
        return false;
    }
    $requesting_user = new BP_Groups_Member();
    $requesting_user->group_id = $group_id;
    $requesting_user->user_id = $requesting_user_id;
    $requesting_user->inviter_id = 0;
    $requesting_user->is_admin = 0;
    $requesting_user->user_title = '';
    $requesting_user->date_modified = bp_core_current_time();
    $requesting_user->is_confirmed = 0;
    $requesting_user->comments = isset($_POST['group-request-membership-comments']) ? $_POST['group-request-membership-comments'] : '';
    if ($requesting_user->save()) {
        $admins = groups_get_group_admins($group_id);
        // Saved okay, now send the email notification
        for ($i = 0, $count = count($admins); $i < $count; ++$i) {
            groups_notification_new_membership_request($requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id);
        }
        do_action('groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id);
        return true;
    }
    return false;
}
/**
 * Create a group membership request.
 *
 * @param int $requesting_user_id ID of the user requesting membership.
 * @param int $group_id           ID of the group.
 *
 * @return bool True on success, false on failure.
 */
function groups_send_membership_request($requesting_user_id, $group_id)
{
    // Prevent duplicate requests
    if (groups_check_for_membership_request($requesting_user_id, $group_id)) {
        return false;
    }
    // Check if the user is already a member or is banned
    if (groups_is_user_member($requesting_user_id, $group_id) || groups_is_user_banned($requesting_user_id, $group_id)) {
        return false;
    }
    // Check if the user is already invited - if so, simply accept invite
    if (groups_check_user_has_invite($requesting_user_id, $group_id)) {
        groups_accept_invite($requesting_user_id, $group_id);
        return true;
    }
    $requesting_user = new BP_Groups_Member();
    $requesting_user->group_id = $group_id;
    $requesting_user->user_id = $requesting_user_id;
    $requesting_user->inviter_id = 0;
    $requesting_user->is_admin = 0;
    $requesting_user->user_title = '';
    $requesting_user->date_modified = bp_core_current_time();
    $requesting_user->is_confirmed = 0;
    $requesting_user->comments = isset($_POST['group-request-membership-comments']) ? $_POST['group-request-membership-comments'] : '';
    if ($requesting_user->save()) {
        $admins = groups_get_group_admins($group_id);
        // Saved okay, now send the email notification
        for ($i = 0, $count = count($admins); $i < $count; ++$i) {
            groups_notification_new_membership_request($requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id);
        }
        /**
         * Fires after the creation of a new membership request.
         *
         * @since 1.0.0
         *
         * @param int   $requesting_user_id  ID of the user requesting membership.
         * @param array $admins              Array of group admins.
         * @param int   $group_id            ID of the group being requested to.
         * @param int   $requesting_user->id ID of the user requesting membership.
         */
        do_action('groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id);
        return true;
    }
    return false;
}
 /**
  * Fetch extra data for a list of groups.
  *
  * This method is used throughout the class, by methods that take a
  * $populate_extras parameter.
  *
  * Data fetched:
  *     - Logged-in user's status within each group (is_member,
  *       is_confirmed, is_pending, is_banned)
  *
  * @since 1.6.0
  *
  * @param array        $paged_groups Array of groups.
  * @param string|array $group_ids    Array or comma-separated list of IDs matching
  *                                   $paged_groups.
  * @param string|bool  $type         Not used.
  * @return array $paged_groups
  */
 public static function get_group_extras(&$paged_groups, &$group_ids, $type = false)
 {
     $user_id = bp_loggedin_user_id();
     foreach ($paged_groups as &$group) {
         $group->is_member = groups_is_user_member($user_id, $group->id) ? 1 : 0;
         $group->is_invited = groups_is_user_invited($user_id, $group->id) ? 1 : 0;
         $group->is_pending = groups_is_user_pending($user_id, $group->id) ? 1 : 0;
         $group->is_banned = (bool) groups_is_user_banned($user_id, $group->id);
     }
     return $paged_groups;
 }