예제 #1
0
 function save()
 {
     global $bp;
     /* Set error redirect based on save method */
     if ($this->method == 'create') {
         $redirect_url = $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $this->slug;
     } else {
         $redirect_url = bp_get_group_permalink($bp->groups->current_group) . '/admin/' . $this->slug;
     }
     groups_send_invites($bp->loggedin_user->id, $bp->groups->current_group->id);
     if ($this->has_invites) {
         bp_core_add_message(__('Group invites sent.', 'buddypress'));
     } else {
         bp_core_add_message(__('Group created successfully.', 'buddypress'));
     }
 }
예제 #2
0
function invite_anyone_activate_user($user_id, $key, $user)
{
    global $bp;
    $email = bp_core_get_user_email($user_id);
    $inviters = array();
    // Fire the query
    $invites = invite_anyone_get_invitations_by_invited_email($email);
    if ($invites->have_posts()) {
        // From the posts returned by the query, get a list of unique inviters
        $groups = array();
        while ($invites->have_posts()) {
            $invites->the_post();
            $inviter_id = get_the_author_meta('ID');
            $inviters[] = $inviter_id;
            $groups_data = wp_get_post_terms(get_the_ID(), invite_anyone_get_invited_groups_tax_name());
            foreach ($groups_data as $group_data) {
                if (!isset($groups[$group_data->name])) {
                    // Keyed by inviter, which means they'll only get one invite per group
                    $groups[$group_data->name] = $inviter_id;
                }
            }
            // Mark as accepted
            update_post_meta(get_the_ID(), 'bp_ia_accepted', date('Y-m-d H:i:s'));
        }
        $inviters = array_unique($inviters);
        // Friendship requests
        if (bp_is_active('friends') && apply_filters('invite_anyone_send_friend_requests_on_acceptance', true)) {
            if (function_exists('friends_add_friend')) {
                foreach ($inviters as $inviter) {
                    friends_add_friend($inviter, $user_id);
                }
            }
        }
        // BuddyPress Followers support
        if (function_exists('bp_follow_start_following') && apply_filters('invite_anyone_send_follow_requests_on_acceptance', true)) {
            foreach ($inviters as $inviter) {
                bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
                bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
            }
        }
        // Group invitations
        if (bp_is_active('groups')) {
            foreach ($groups as $group_id => $inviter_id) {
                $args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id);
                groups_invite_user($args);
                groups_send_invites($inviter_id, $group_id);
            }
        }
    }
    do_action('accepted_email_invite', $user_id, $inviters);
}
예제 #3
0
/**
 * Handle the display of a group's Send Invites page.
 */
function groups_screen_group_invite()
{
    if (!bp_is_single_item()) {
        return false;
    }
    $bp = buddypress();
    if (bp_is_action_variable('send', 0)) {
        if (!check_admin_referer('groups_send_invites', '_wpnonce_send_invites')) {
            return false;
        }
        if (!empty($_POST['friends'])) {
            foreach ((array) $_POST['friends'] as $friend) {
                groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->current_group->id));
            }
        }
        // Send the invites.
        groups_send_invites(bp_loggedin_user_id(), $bp->groups->current_group->id);
        bp_core_add_message(__('Group invites sent.', 'buddypress'));
        /**
         * Fires after the sending of a group invite inside the group's Send Invites page.
         *
         * @since 1.0.0
         *
         * @param int $id ID of the group whose members are being displayed.
         */
        do_action('groups_screen_group_invite', $bp->groups->current_group->id);
        bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
    } elseif (!bp_action_variable(0)) {
        /**
         * Filters the template to load for a group's Send Invites page.
         *
         * @since 1.0.0
         *
         * @param string $value Path to a group's Send Invites template.
         */
        bp_core_load_template(apply_filters('groups_template_group_invite', 'groups/single/home'));
    } else {
        bp_do_404();
    }
}
예제 #4
0
/**
 * Catch and process group creation form submissions.
 */
function groups_action_create_group()
{
    global $bp;
    // If we're not at domain.org/groups/create/ then return false
    if (!bp_is_groups_component() || !bp_is_current_action('create')) {
        return false;
    }
    if (!is_user_logged_in()) {
        return false;
    }
    if (!bp_user_can_create_groups()) {
        bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error');
        bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug()));
    }
    // Make sure creation steps are in the right order
    groups_action_sort_creation_steps();
    // If no current step is set, reset everything so we can start a fresh group creation
    $bp->groups->current_create_step = bp_action_variable(1);
    if (!bp_get_groups_current_create_step()) {
        unset($bp->groups->current_create_step);
        unset($bp->groups->completed_create_steps);
        setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH);
        setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH);
        $reset_steps = true;
        $keys = array_keys($bp->groups->group_creation_steps);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/');
    }
    // If this is a creation step that is not recognized, just redirect them back to the first screen
    if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) {
        bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error');
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
    }
    // Fetch the currently completed steps variable
    if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) {
        $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps'])));
    }
    // Set the ID of the new group, if it has already been created in a previous step
    if (isset($_COOKIE['bp_new_group_id'])) {
        $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id'];
        $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id));
        // Only allow the group creator to continue to edit the new group
        if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) {
            bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
        }
    }
    // If the save, upload or skip button is hit, lets calculate what we need to save
    if (isset($_POST['save'])) {
        // Check the nonce
        check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step());
        if ('group-details' == bp_get_groups_current_create_step()) {
            if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) {
                bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0;
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
        }
        if ('group-settings' == bp_get_groups_current_create_step()) {
            $group_status = 'public';
            $group_enable_forum = 1;
            if (!isset($_POST['group-show-forum'])) {
                $group_enable_forum = 0;
            } else {
                // Create the forum if enable_forum = 1
                if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) {
                    groups_new_group_forum();
                }
            }
            if ('private' == $_POST['group-status']) {
                $group_status = 'private';
            } else {
                if ('hidden' == $_POST['group-status']) {
                    $group_status = 'hidden';
                }
            }
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            // Set the invite status
            // Checked against a whitelist for security
            $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
            $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
            groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status);
        }
        if ('group-invites' === bp_get_groups_current_create_step()) {
            if (!empty($_POST['friends'])) {
                foreach ((array) $_POST['friends'] as $friend) {
                    groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id));
                }
            }
            groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id);
        }
        do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step());
        do_action('groups_create_group_step_complete');
        // Mostly for clearing cache on a generic action name
        /**
         * Once we have successfully saved the details for this step of the creation process
         * we need to add the current step to the array of completed steps, then update the cookies
         * holding the information
         */
        $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array();
        if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) {
            $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step();
        }
        // Reset cookie info
        setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH);
        setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH);
        // If we have completed all steps and hit done on the final step we
        // can redirect to the completed group
        $keys = array_keys($bp->groups->group_creation_steps);
        if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) {
            unset($bp->groups->current_create_step);
            unset($bp->groups->completed_create_steps);
            // Once we compelete all steps, record the group creation in the activity stream.
            groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id));
            do_action('groups_group_create_complete', $bp->groups->new_group_id);
            bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
        } else {
            /**
             * Since we don't know what the next step is going to be (any plugin can insert steps)
             * we need to loop the step array and fetch the next step that way.
             */
            foreach ($keys as $key) {
                if ($key == bp_get_groups_current_create_step()) {
                    $next = 1;
                    continue;
                }
                if (isset($next)) {
                    $next_step = $key;
                    break;
                }
            }
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/');
        }
    }
    // Remove invitations
    if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) {
        if (!check_admin_referer('groups_invite_uninvite_user')) {
            return false;
        }
        $message = __('Invite successfully removed', 'buddypress');
        $error = false;
        if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) {
            $message = __('There was an error removing the invite', 'buddypress');
            $error = 'error';
        }
        bp_core_add_message($message, $error);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/');
    }
    // Group avatar is handled separately
    if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) {
        if (!isset($bp->avatar_admin)) {
            $bp->avatar_admin = new stdClass();
        }
        if (!empty($_FILES) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            // Pass the file to the avatar upload handler
            if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
                $bp->avatar_admin->step = 'crop-image';
                // Make sure we include the jQuery jCrop file for image cropping
                add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
            }
        }
        // If the image cropping is done, crop the image and save a full/thumb version
        if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
                bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress'));
            }
        }
    }
    bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create'));
}
예제 #5
0
/**
 * Handle the display of a group's Send Invites page.
 */
function groups_screen_group_invite()
{
    if (!bp_is_single_item()) {
        return false;
    }
    $bp = buddypress();
    if (bp_is_action_variable('send', 0)) {
        if (!check_admin_referer('groups_send_invites', '_wpnonce_send_invites')) {
            return false;
        }
        if (!empty($_POST['friends'])) {
            foreach ((array) $_POST['friends'] as $friend) {
                groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->current_group->id));
            }
        }
        // Send the invites.
        groups_send_invites(bp_loggedin_user_id(), $bp->groups->current_group->id);
        bp_core_add_message(__('Group invites sent.', 'buddypress'));
        do_action('groups_screen_group_invite', $bp->groups->current_group->id);
        bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
    } elseif (!bp_action_variable(0)) {
        // Show send invite page
        bp_core_load_template(apply_filters('groups_template_group_invite', 'groups/single/home'));
    } else {
        bp_do_404();
    }
}
예제 #6
0
파일: bp-groups.php 프로젝트: n-sane/zaroka
function groups_action_create_group() {
	global $bp;

	/* If we're not at domain.org/groups/create/ then return false */
	if ( $bp->current_component != $bp->groups->slug || 'create' != $bp->current_action )
		return false;

	if ( !is_user_logged_in() )
		return false;

	/* Make sure creation steps are in the right order */
	groups_action_sort_creation_steps();

	/* If no current step is set, reset everything so we can start a fresh group creation */
	if ( !$bp->groups->current_create_step = $bp->action_variables[1] ) {

		unset( $bp->groups->current_create_step );
		unset( $bp->groups->completed_create_steps );

		setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH );
		setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH );

		$reset_steps = true;
		bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );
	}

	/* If this is a creation step that is not recognized, just redirect them back to the first screen */
	if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) {
		bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
		bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/' );
	}

	/* Fetch the currently completed steps variable */
	if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !$reset_steps )
		$bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) );

	/* Set the ID of the new group, if it has already been created in a previous step */
	if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
		$bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
		$bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id );
	}

	/* If the save, upload or skip button is hit, lets calculate what we need to save */
	if ( isset( $_POST['save'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );

		if ( 'group-details' == $bp->groups->current_create_step ) {
			if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
				bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}

			if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) {
				bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}

			groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
			groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
		}

		if ( 'group-settings' == $bp->groups->current_create_step ) {
			$group_status = 'public';
			$group_enable_forum = 1;

			if ( !isset($_POST['group-show-forum']) ) {
				$group_enable_forum = 0;
			} else {
				/* Create the forum if enable_forum = 1 */
				if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
					groups_new_group_forum();
				}
			}

			if ( 'private' == $_POST['group-status'] )
				$group_status = 'private';
			else if ( 'hidden' == $_POST['group-status'] )
				$group_status = 'hidden';

			if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
				bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}
		}

		if ( 'group-invites' == $bp->groups->current_create_step ) {
			groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id );
		}

		do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
		do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name

		/**
		 * Once we have successfully saved the details for this step of the creation process
		 * we need to add the current step to the array of completed steps, then update the cookies
		 * holding the information
		 */
		if ( !in_array( $bp->groups->current_create_step, (array)$bp->groups->completed_create_steps ) )
			$bp->groups->completed_create_steps[] = $bp->groups->current_create_step;

		/* Reset cookie info */
		setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
		setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );

		/* If we have completed all steps and hit done on the final step we can redirect to the completed group */
		if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
			unset( $bp->groups->current_create_step );
			unset( $bp->groups->completed_create_steps );

			/* Once we compelete all steps, record the group creation in the activity stream. */
			groups_record_activity( array(
				'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%s created the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
				'type' => 'created_group',
				'item_id' => $bp->groups->new_group_id
			) );

			do_action( 'groups_group_create_complete', $bp->groups->new_group_id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
		} else {
			/**
			 * Since we don't know what the next step is going to be (any plugin can insert steps)
			 * we need to loop the step array and fetch the next step that way.
			 */
			foreach ( (array)$bp->groups->group_creation_steps as $key => $value ) {
				if ( $key == $bp->groups->current_create_step ) {
					$next = 1;
					continue;
				}

				if ( $next ) {
					$next_step = $key;
					break;
				}
			}

			bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $next_step . '/' );
		}
	}

	/* Group avatar is handled separately */
	if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
		if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
			/* Normally we would check a nonce here, but the group save nonce is used instead */

			/* Pass the file to the avatar upload handler */
			if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
				$bp->avatar_admin->step = 'crop-image';

				/* Make sure we include the jQuery jCrop file for image cropping */
				add_action( 'wp', 'bp_core_add_jquery_cropper' );
			}
		}

		/* If the image cropping is done, crop the image and save a full/thumb version */
		if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
			/* Normally we would check a nonce here, but the group save nonce is used instead */

			if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
				bp_core_add_message( __( 'There was an error saving the group avatar, please try uploading again.', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'The group avatar was uploaded successfully!', 'buddypress' ) );
		}
	}

 	bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
}
 /**
  * @group groups_send_invites
  * @group group_invitations
  * @group group_membership_requests
  * @group group_membership
  */
 public function test_groups_membership_request_plus_invite_equals_member()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $g1 = $this->factory->group->create(array('creator_id' => $u1));
     // Create membership request
     groups_send_membership_request($u2, $g1);
     // Create draft invitation
     groups_invite_user(array('user_id' => $u2, 'group_id' => $g1, 'inviter_id' => $u1, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 0));
     // Send the invitation
     groups_send_invites($u1, $g1);
     // User should now be a group member
     $member = groups_is_user_member($u2, $g1);
     $this->assertTrue(is_numeric($member) && $member > 0);
 }
예제 #8
0
function groups_create_group($step, $group_id)
{
    global $bp, $create_group_step, $group_obj, $bbpress_live;
    if (is_numeric($step) && (1 == (int) $step || 2 == (int) $step || 3 == (int) $step || 4 == (int) $step)) {
        if (!$group_obj) {
            $group_obj = new BP_Groups_Group($group_id);
        }
        switch ($step) {
            case '1':
                if (!check_admin_referer('groups_step1_save')) {
                    return false;
                }
                if ($_POST['group-name'] != '' && $_POST['group-desc'] != '') {
                    $group_obj->creator_id = $bp->loggedin_user->id;
                    $group_obj->name = stripslashes($_POST['group-name']);
                    $group_obj->description = stripslashes($_POST['group-desc']);
                    $group_obj->news = stripslashes($_POST['group-news']);
                    $slug = groups_check_slug(sanitize_title($_POST['group-name']));
                    $group_obj->slug = $slug;
                    $group_obj->status = 'public';
                    $group_obj->is_invitation_only = 0;
                    $group_obj->enable_wire = 1;
                    $group_obj->enable_forum = 1;
                    $group_obj->enable_photos = 1;
                    $group_obj->photos_admin_only = 0;
                    $group_obj->date_created = time();
                    if (!$group_obj->save()) {
                        return false;
                    }
                    // Save the creator as the group administrator
                    $admin = new BP_Groups_Member($bp->loggedin_user->id, $group_obj->id);
                    $admin->is_admin = 1;
                    $admin->user_title = __('Group Admin', 'buddypress');
                    $admin->date_modified = time();
                    $admin->inviter_id = 0;
                    $admin->is_confirmed = 1;
                    if (!$admin->save()) {
                        return false;
                    }
                    do_action('groups_create_group_step1_save');
                    /* Set groupmeta */
                    groups_update_groupmeta($group_obj->id, 'total_member_count', 1);
                    groups_update_groupmeta($group_obj->id, 'last_activity', time());
                    groups_update_groupmeta($group_obj->id, 'theme', 'buddypress');
                    groups_update_groupmeta($group_obj->id, 'stylesheet', 'buddypress');
                    return $group_obj->id;
                }
                return false;
                break;
            case '2':
                if (!check_admin_referer('groups_step2_save')) {
                    return false;
                }
                $group_obj->status = 'public';
                $group_obj->is_invitation_only = 0;
                $group_obj->enable_wire = 1;
                $group_obj->enable_forum = 1;
                $group_obj->enable_photos = 1;
                $group_obj->photos_admin_only = 0;
                if (!isset($_POST['group-show-wire'])) {
                    $group_obj->enable_wire = 0;
                }
                if (!isset($_POST['group-show-forum'])) {
                    $group_obj->enable_forum = 0;
                } else {
                    /* Create the forum if enable_forum = 1 */
                    if (function_exists('bp_forums_setup') && '' == groups_get_groupmeta($group_obj->id, 'forum_id')) {
                        groups_new_group_forum();
                    }
                }
                if (!isset($_POST['group-show-photos'])) {
                    $group_obj->enable_photos = 0;
                }
                if ($_POST['group-photos-status'] != 'all') {
                    $group_obj->photos_admin_only = 1;
                }
                if ('private' == $_POST['group-status']) {
                    $group_obj->status = 'private';
                } else {
                    if ('hidden' == $_POST['group-status']) {
                        $group_obj->status = 'hidden';
                    }
                }
                if (!$group_obj->save()) {
                    return false;
                }
                /* Record in activity streams */
                groups_record_activity(array('item_id' => $group_obj->id, 'component_name' => $bp->groups->slug, 'component_action' => 'created_group', 'is_private' => 0));
                do_action('groups_create_group_step2_save');
                return $group_obj->id;
                break;
            case '3':
                if (!check_admin_referer('groups_step3_save')) {
                    return false;
                }
                if (isset($_POST['skip'])) {
                    return $group_obj->id;
                }
                // Image already cropped and uploaded, lets store a reference in the DB.
                if (!wp_verify_nonce($_POST['nonce'], 'slick_avatars') || !($result = bp_core_avatar_cropstore($_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h'], false, 'groupavatar', $group_obj->id))) {
                    return false;
                }
                // Success on group avatar cropping, now save the results.
                $avatar_hrefs = groups_get_avatar_hrefs($result);
                $group_obj->avatar_thumb = stripslashes($avatar_hrefs['thumb_href']);
                $group_obj->avatar_full = stripslashes($avatar_hrefs['full_href']);
                if (!$group_obj->save()) {
                    return false;
                }
                do_action('groups_create_group_step3_save');
                return $group_obj->id;
                break;
            case '4':
                if (!check_admin_referer('groups_step4_save')) {
                    return false;
                }
                groups_send_invites($group_obj, true);
                do_action('groups_created_group', $group_obj->id);
                return $group_obj->id;
                break;
        }
    }
    return false;
}
예제 #9
0
 function save($group_id = null)
 {
     global $bp;
     if (null === $group_id) {
         $group_id = bp_get_current_group_id();
     }
     /* Set error redirect based on save method */
     if ($this->method == 'create') {
         $redirect_url = $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $this->slug;
     } else {
         $group = groups_get_group(array('group_id' => $group_id));
         $redirect_url = bp_get_group_permalink($group) . '/admin/' . $this->slug;
     }
     groups_send_invites($bp->loggedin_user->id, $group_id);
     if ($this->has_invites) {
         bp_core_add_message(__('Group invites sent.', 'invite-anyone'));
     } else {
         bp_core_add_message(__('Group created successfully.', 'invite-anyone'));
     }
 }
예제 #10
0
function invite_anyone_activate_user($user_id, $key, $user)
{
    global $bp;
    $email = bp_core_get_user_email($user_id);
    if ($invites = invite_anyone_get_invitations_by_invited_email($email)) {
        // Mark as "is_joined"
        invite_anyone_mark_as_joined($email);
        // Friendship requests
        if (bp_is_active('friends')) {
            $inviters = array();
            foreach ($invites as $invite) {
                if (!in_array($invite->inviter_id, $inviters)) {
                    $inviters[] = $invite->inviter_id;
                }
            }
            if (function_exists('friends_add_friend')) {
                foreach ($inviters as $inviter) {
                    friends_add_friend($inviter, $user_id);
                }
            }
        }
        // BuddyPress Followers support
        if (function_exists('bp_follow_start_following')) {
            $inviters = array();
            foreach ($invites as $invite) {
                if (!in_array($invite->inviter_id, $inviters)) {
                    $inviters[] = $invite->inviter_id;
                }
            }
            foreach ($inviters as $inviter) {
                bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
                bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
            }
        }
        // BuddyPress Followers support
        if (function_exists('bp_follow_start_following')) {
            $inviters = array();
            foreach ($invites as $invite) {
                if (!in_array($invite->inviter_id, $inviters)) {
                    $inviters[] = $invite->inviter_id;
                }
            }
            foreach ($inviters as $inviter) {
                bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
                bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
            }
        }
        // Group invitations
        if (bp_is_active('groups')) {
            $groups = array();
            foreach ($invites as $invite) {
                if (!$invite->group_invitations[0]) {
                    continue;
                } else {
                    $group_invitations = unserialize($invite->group_invitations);
                }
                foreach ($group_invitations as $group) {
                    if (!in_array($group, array_keys($groups))) {
                        $groups[$group] = $invite->inviter_id;
                    }
                }
            }
            foreach ($groups as $group_id => $inviter_id) {
                $args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id);
                groups_invite_user($args);
                groups_send_invites($inviter_id, $group_id);
            }
        }
    }
    do_action('accepted_email_invite', $user_id, $inviters);
}
예제 #11
0
 /**
  * The main workhorse where the friends, groups and welcome message features happens.
  * Triggers when a user account is activated.
  *
  * @param int $user_id ID of the new user
  * @since 3.0
  */
 function user_activated($user_id)
 {
     $settings = DP_Welcome_Pack::get_settings();
     // Is the Friend invitations component enabled?
     if (!empty($settings['dpw_friendstoggle']) && bp_is_active('friends') && !empty($settings['friends'])) {
         // Send friend requests
         foreach ((array) $settings['friends'] as $friend_id) {
             friends_add_friend((int) $friend_id, $user_id, constant('WELCOME_PACK_AUTOACCEPT_INVITATIONS'));
         }
     }
     // Is the Group invitations component enabled?
     if (!empty($settings['dpw_groupstoggle']) && bp_is_active('groups') && !empty($settings['groups'])) {
         foreach ((array) $settings['groups'] as $group_id) {
             $group = new BP_Groups_Group((int) $group_id);
             // Send group invites
             groups_invite_user(array('user_id' => $user_id, 'group_id' => (int) $group_id, 'inviter_id' => $group->creator_id, 'is_confirmed' => constant('WELCOME_PACK_AUTOACCEPT_INVITATIONS')));
             groups_send_invites($group->creator_id, (int) $group_id);
         }
     }
     // Is the Welcome Message component enabled?
     if (!empty($settings['dpw_welcomemsgtoggle']) && bp_is_active('messages') && !empty($settings['welcomemsgsender']) && !empty($settings['welcomemsgsubject']) && !empty($settings['welcomemsg'])) {
         messages_new_message(array('sender_id' => $settings['welcomemsgsender'], 'recipients' => $user_id, 'subject' => apply_filters('dpw_keyword_replacement', $settings['welcomemsgsubject'], $user_id), 'content' => apply_filters('dpw_keyword_replacement', $settings['welcomemsg'], $user_id)));
     }
     // Call an action for third-parties to hook into
     do_action('dpw_user_activated', $user_id);
 }
예제 #12
0
 /**
  * @group counts
  */
 public function test_get_invite_count_for_user()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $g = $this->factory->group->create(array('creator_id' => $u1));
     // create invitation
     groups_invite_user(array('user_id' => $u2, 'group_id' => $g, 'inviter_id' => $u1));
     // send the invite
     // this function is imperative to set the 'invite_sent' flag in the DB
     // why is this separated from groups_invite_user()?
     // @see groups_screen_group_invite()
     groups_send_invites($u1, $g);
     // assert invite count
     $this->assertEquals(1, groups_get_invite_count_for_user($u2));
     // accept the invite and reassert
     groups_accept_invite($u2, $g);
     $this->assertEquals(0, groups_get_invite_count_for_user($u2));
 }