public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $users = array(array('aardvark', 'Bob Smith'), array('alpaca red', 'William Quinn'), array('cat', 'Lauren Curtis'), array('caterpillar', 'Eldon Burrows'), array('dog green', 'Reece Thornton'), array('pig', 'Joshua Barton'), array('rabbit blue', 'Amber Hooper'), array('smith', 'Robert Bar'), array('snake', 'Eleanor Moore'), array('xylo', 'Silver McFadden'), array('zoom', 'Lisa Smithy'));
     $factory = new BP_UnitTest_Factory();
     // Create some dummy users.
     foreach ($users as $user_index => $user) {
         $new_user = $factory->user->create(array('display_name' => $user[1], 'user_login' => $user[0], 'user_email' => "test-{$user_index}@example.com"));
         self::$user_ids[$user[0]] = $new_user;
     }
     self::$group_slugs['hidden'] = 'the-maw';
     self::$group_slugs['public'] = 'the-great-journey';
     self::$group_slugs['private'] = 'tsavo-highway';
     // Create dummy groups.
     self::$group_ids['hidden'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['hidden'], 'status' => 'hidden'));
     self::$group_ids['public'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['public'], 'status' => 'public'));
     self::$group_ids['private'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['private'], 'status' => 'private'));
     // Add dummy users to dummy hidden groups.
     groups_join_group(self::$group_ids['hidden'], self::$user_ids['pig']);
     groups_join_group(self::$group_ids['hidden'], self::$user_ids['alpaca red']);
     // Add dummy users to dummy public groups.
     groups_join_group(self::$group_ids['public'], self::$user_ids['aardvark']);
     groups_join_group(self::$group_ids['public'], self::$user_ids['alpaca red']);
     groups_join_group(self::$group_ids['public'], self::$user_ids['cat']);
     groups_join_group(self::$group_ids['public'], self::$user_ids['smith']);
     // Add dummy users to dummy private groups.
     groups_join_group(self::$group_ids['private'], self::$user_ids['cat']);
     groups_join_group(self::$group_ids['private'], self::$user_ids['caterpillar']);
     self::commit_transaction();
 }
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $user = elgg_get_logged_in_user_entity();
     $group = get_entity($params->guid);
     // join or request
     $join = false;
     if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
         // anyone can join public groups and admins can join any group
         $join = true;
     } else {
         if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
             // user has invite to closed group
             $join = true;
         }
     }
     if ($join) {
         if (groups_join_group($group, $user)) {
             $msg = elgg_echo("groups:joined");
         } else {
             throw new GraphException(elgg_echo("groups:cantjoin"));
         }
     } else {
         if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) {
             throw new GraphException(elgg_echo("groups:joinrequestnotmade"));
         }
         $owner = $group->getOwnerEntity();
         $url = elgg_normalize_url("groups/requests/{$group->guid}");
         $subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
         $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
         // Notify group owner
         notify_user($owner->guid, $user->getGUID(), $subject, $body);
         $msg = elgg_echo("groups:joinrequestmade");
     }
     return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid)));
 }
/**
 * Load the Forums directory.
 */
function bp_forums_directory_forums_setup()
{
    // Get BuddyPress once
    $bp = buddypress();
    if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) {
        if (!bp_forums_has_directory()) {
            return false;
        }
        if (!bp_forums_is_installed_correctly()) {
            bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain());
        }
        bp_update_is_directory(true, 'forums');
        do_action('bbpress_init');
        // Check to see if the user has posted a new topic from the forums page.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            check_admin_referer('bp_forums_new_topic');
            $bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id']));
            if (!empty($bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group
                if (!bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                    groups_join_group($bp->groups->current_group->id);
                }
                $error_message = '';
                $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
                if (!empty($forum_id)) {
                    if (empty($_POST['topic_title'])) {
                        $error_message = __('Please provide a title for your forum topic.', 'buddypress');
                    } else {
                        if (empty($_POST['topic_text'])) {
                            $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
                        }
                    }
                    if ($error_message) {
                        bp_core_add_message($error_message, 'error');
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                    } else {
                        if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                            bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                        } else {
                            bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                        }
                    }
                    bp_core_redirect($redirect);
                } else {
                    bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                    bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
                }
            } else {
                bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
            }
        }
        do_action('bp_forums_directory_forums_setup');
        bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index'));
    }
}
Beispiel #4
0
/**
 * Web service for joining a group
 *
 * @param string $username username of author
 * @param string $groupid  GUID of the group
 *
 * @return bool
 */
function group_join($username, $groupid)
{
    $user = get_user_by_username($username);
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $group = get_entity($groupid);
    $return['success'] = false;
    if ($user instanceof ElggUser && $group instanceof ElggGroup) {
        // join or request
        $join = false;
        if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
            // anyone can join public groups and admins can join any group
            $join = true;
        } else {
            if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
                // user has invite to closed group
                $join = true;
            }
        }
        if ($join) {
            if (groups_join_group($group, $user)) {
                $return['success'] = true;
                $return['message'] = elgg_echo("groups:joined");
            } else {
                $return['message'] = elgg_echo("groups:cantjoin");
            }
        } else {
            add_entity_relationship($user->guid, 'membership_request', $group->guid);
            // Notify group owner
            $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}";
            $subject = elgg_echo('groups:request:subject', array($user->name, $group->name));
            $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url));
            if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
                $return['success'] = true;
                $return['message'] = elgg_echo("groups:joinrequestmade");
            } else {
                $return['message'] = elgg_echo("groups:joinrequestnotmade");
            }
        }
    } else {
        $return['message'] = elgg_echo("groups:cantjoin");
    }
    return $return;
}
Beispiel #5
0
function bp_forums_directory_forums_setup() {
	global $bp;

	if ( $bp->current_component == $bp->forums->slug ) {
		if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
			return false;

		if ( !bp_forums_is_installed_correctly() ) {
			bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
			bp_core_redirect( $bp->root_domain );
		}

		$bp->is_directory = true;

		do_action( 'bbpress_init' );

		/* Check to see if the user has posted a new topic from the forums page. */
		if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
			/* Check the nonce */
			check_admin_referer( 'bp_forums_new_topic' );

			if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
				/* Auto join this user if they are not yet a member of this group */
				if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
					groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );

				if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
					if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
						bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
					else
						bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );

					bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
				} else {
					bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
				}
			}
		}

		do_action( 'bp_forums_directory_forums_setup' );

		bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
	}
}
Beispiel #6
0
 function bp_group_reviews_extension()
 {
     global $bp;
     $this->group_id = BP_Groups_Group::group_exists($bp->current_item);
     $this->name = __('Reviews', 'bpgr');
     $this->slug = $bp->group_reviews->slug;
     $this->nav_item_position = 22;
     $this->enable_create_step = false;
     $this->enable_nav_item = BP_Group_Reviews::current_group_is_available();
     $this->enable_edit_item = false;
     if (isset($_POST['review_submit'])) {
         check_admin_referer('review_submit');
         $has_posted = '';
         if (empty($_POST['review_content']) || !(int) $_POST['rating']) {
             // Something has gone wrong. Save the user's submitted data to reinsert into the post box after redirect
             $cookie_data = array('review_content' => $_POST['review_content'], 'rating' => $_POST['rating']);
             $cookie = json_encode($cookie_data);
             setcookie('bpgr-data', $cookie, time() + 60 * 60 * 24, COOKIEPATH);
             bp_core_add_message(__("Please make sure you fill in the review, and don't forget to provide a rating!", 'bpgr'), 'error');
         } else {
             /* Auto join this user if they are not yet a member of this group */
             if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) {
                 groups_join_group($bp->groups->current_group->id, $bp->loggedin_user->id);
             }
             if ($rating_id = $this->post_review(array('content' => $_POST['review_content'], 'rating' => (int) $_POST['rating']))) {
                 bp_core_add_message("Your review was posted successfully!");
                 $has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review');
                 if (!in_array((int) $bp->loggedin_user->id, (array) $has_posted)) {
                     $has_posted[] = (int) $bp->loggedin_user->id;
                 }
                 groups_update_groupmeta($bp->groups->current_group->id, 'posted_review', $has_posted);
                 if ((int) $_POST['rating'] < 0) {
                     $_POST['rating'] = 1;
                 }
                 if ((int) $_POST['rating'] > 5) {
                     $_POST['rating'] = 5;
                 }
             } else {
                 bp_core_add_message("There was a problem posting your review, please try again.", 'error');
             }
         }
         bp_core_redirect(apply_filters('bpgr_after_post_redirect', trailingslashit(bp_get_group_permalink($bp->groups->current_group) . $this->slug, $has_posted)));
     }
 }
 /**
  * @group groups_join_group
  * @group group_membership
  */
 public function test_groups_join_group_cleanup_requests()
 {
     $u1 = $this->factory->user->create();
     $g = $this->factory->group->create();
     self::create_group_membership_request($u1, $g);
     groups_join_group($g, $u1);
     // Upon joining the group, outstanding requests should be cleaned up.
     $this->assertEquals(null, groups_check_for_membership_request($u1, $g));
 }
Beispiel #8
0
/**
 * @param $guid
 * @return mixed
 * @throws InvalidParameterException
 */
function group_join_group($guid)
{
    global $CONFIG;
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    /* @var ElggGroup $group */
    $group = get_entity($guid);
    if (!$group instanceof ElggGroup) {
        $return['joined'] = false;
        $return['message'] = 'Group Not Found';
        exit;
    }
    // access bypass for getting invisible group
    $ia = elgg_set_ignore_access(true);
    elgg_set_ignore_access($ia);
    if ($user && $group instanceof ElggGroup) {
        // join or request
        $join = false;
        if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
            // anyone can join public groups and admins can join any group
            $join = true;
        } else {
            if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
                // user has invite to closed group
                $join = true;
            }
        }
        if ($join) {
            if (groups_join_group($group, $user)) {
                $return['member'] = 'joined';
                $return['message'] = 'joined';
            } else {
                $isMember = isMemberOf($group, $user);
                if ($isMember) {
                    $return['member'] = 'joined';
                    $return['message'] = 'isMemberOf';
                } else {
                    $return['member'] = 'cantjoin';
                    $return['message'] = 'cantjoin';
                }
            }
        } else {
            add_entity_relationship($user->guid, 'membership_request', $group->guid);
            $owner = $group->getOwnerEntity();
            $url = "{$CONFIG->url}groups/requests/{$group->guid}";
            $subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
            $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
            // Notify group owner
            if (notify_user($owner->guid, $user->getGUID(), $subject, $body)) {
                $return['member'] = 'cantjoin';
                $return['message'] = 'joinrequestmade';
            } else {
                $return['member'] = 'cantjoin';
                $return['message'] = 'joinrequestnotmade';
            }
        }
    } else {
        $isMember = isMemberOf($group, $user);
        if ($isMember) {
            $return['member'] = 'joined';
            $return['message'] = 'isMemberOf';
        } else {
            $return['member'] = 'cantjoin';
            $return['message'] = 'cantjoin';
        }
    }
    return $return;
}
function bp_course_add_user_to_course($user_id, $course_id)
{
    $duration = get_post_meta($course_id, 'vibe_duration', true);
    $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
    $t = time() + $duration * $course_duration_parameter;
    update_post_meta($course_id, $user_id, 0);
    update_user_meta($user_id, 'course_status' . $course_id, 1);
    update_user_meta($user_id, $course_id, $t);
    $group_id = get_post_meta($course_id, 'vibe_group', true);
    if (isset($group_id) && $group_id != '') {
        groups_join_group($group_id, $user_id);
    } else {
        $group_id = '';
    }
    do_action('wplms_course_subscribed', $course, $user_id, $group_id);
}
Beispiel #10
0
 function wplms_edd_completed_purchase($payment_id, $new_status, $old_status)
 {
     if ($old_status == 'publish' || $old_status == 'complete') {
         return;
     }
     // Make sure that payments are only completed once
     // Make sure the payment completion is only processed when new status is complete
     if ($new_status != 'publish' && $new_status != 'complete') {
         return;
     }
     $user_id = get_current_user_id();
     $cart_items = edd_get_payment_meta_cart_details($payment_id);
     foreach ($cart_items as $key => $cart_item) {
         $item_id = isset($cart_item['id']) ? $cart_item['id'] : $cart_item;
         if (is_numeric($item_id) && get_post_type($item_id) == 'download') {
             $courses = vibe_sanitize(get_post_meta($item_id, 'vibe_courses', false));
             $subscribed = get_post_meta($product_id, 'vibe_subscription', true);
             if (vibe_validate($subscribed)) {
                 $duration = get_post_meta($product_id, 'vibe_duration', true);
                 $product_duration_parameter = apply_filters('vibe_product_duration_parameter', 86400);
                 // Product duration for subscription based
                 $t = time() + $duration * $product_duration_parameter;
                 foreach ($courses as $course) {
                     update_post_meta($course, $user_id, 0);
                     update_user_meta($user_id, $course, $t);
                     $group_id = get_post_meta($course, 'vibe_group', true);
                     if (isset($group_id) && $group_id != '') {
                         groups_join_group($group_id, $user_id);
                     }
                     bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
                 }
             } else {
                 if (isset($courses) && is_array($courses)) {
                     foreach ($courses as $course) {
                         $duration = get_post_meta($course, 'vibe_duration', true);
                         $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
                         // Course duration for subscription based
                         $t = time() + $duration * $course_duration_parameter;
                         update_post_meta($course, $user_id, 0);
                         update_user_meta($user_id, $course, $t);
                         $group_id = get_post_meta($course, 'vibe_group', true);
                         if (isset($group_id) && $group_id != '') {
                             groups_join_group($group_id, $user_id);
                         }
                         bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
                     }
                 }
             }
         }
     }
 }
/**
 * Set up the Groups admin page.
 *
 * Loaded before the page is rendered, this function does all initial setup,
 * including: processing form requests, registering contextual help, and
 * setting up screen options.
 *
 * @since 1.7.0
 *
 * @global BP_Groups_List_Table $bp_groups_list_table Groups screen list table.
 */
function bp_groups_admin_load()
{
    global $bp_groups_list_table;
    // Build redirection URL
    $redirect_to = remove_query_arg(array('action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified'), $_SERVER['REQUEST_URI']);
    // Decide whether to load the dev version of the CSS and JavaScript
    $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : 'min.';
    $doaction = bp_admin_list_table_current_bulk_action();
    /**
     * Fires at top of groups admin page.
     *
     * @since 1.7.0
     *
     * @param string $doaction Current $_GET action being performed in admin screen.
     */
    do_action('bp_groups_admin_load', $doaction);
    // Edit screen
    if ('do_delete' == $doaction && !empty($_GET['gid'])) {
        check_admin_referer('bp-groups-delete');
        $group_ids = wp_parse_id_list($_GET['gid']);
        $count = 0;
        foreach ($group_ids as $group_id) {
            if (groups_delete_group($group_id)) {
                $count++;
            }
        }
        $redirect_to = add_query_arg('deleted', $count, $redirect_to);
        bp_core_redirect($redirect_to);
    } elseif ('edit' == $doaction && !empty($_GET['gid'])) {
        // columns screen option
        add_screen_option('layout_columns', array('default' => 2, 'max' => 2));
        get_current_screen()->add_help_tab(array('id' => 'bp-group-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This page is a convenient way to edit the details associated with one of your groups.', 'buddypress') . '</p>' . '<p>' . __('The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p><a href="https://buddypress.org/support">' . __('Support Forums', 'buddypress') . '</a></p>');
        // Register metaboxes for the edit screen.
        add_meta_box('submitdiv', _x('Save', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high');
        add_meta_box('bp_group_settings', _x('Settings', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core');
        add_meta_box('bp_group_add_members', _x('Add New Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_group_members', _x('Manage Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core');
        /**
         * Fires after the registration of all of the default group meta boxes.
         *
         * @since 1.7.0
         */
        do_action('bp_groups_admin_meta_boxes');
        // Enqueue JavaScript files
        wp_enqueue_script('postbox');
        wp_enqueue_script('dashboard');
        // Index screen
    } else {
        // Create the Groups screen list table
        $bp_groups_list_table = new BP_Groups_List_Table();
        // per_page screen option
        add_screen_option('per_page', array('label' => _x('Groups', 'Groups per page (screen options)', 'buddypress')));
        // Help panel - overview text
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage groups much like you can manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on groups by using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview-actions', 'title' => __('Group Actions', 'buddypress'), 'content' => '<p>' . __('Clicking "Visit" will take you to the group&#8217;s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress') . '</p>' . '<p>' . __('Clicking "Edit" will take you to a Dashboard panel where you can manage various details about the group, such as its name and description, its members, and other settings.', 'buddypress') . '</p>' . '<p>' . __('If you click "Delete" under a specific group, or select a number of groups and then choose Delete from the Bulk Actions menu, you will be led to a page where you&#8217;ll be asked to confirm the permanent deletion of the group(s).', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
    }
    $bp = buddypress();
    // Enqueue CSS and JavaScript
    wp_enqueue_script('bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin.{$min}js", array('jquery', 'wp-ajax-response', 'jquery-ui-autocomplete'), bp_get_version(), true);
    wp_localize_script('bp_groups_admin_js', 'BP_Group_Admin', array('add_member_placeholder' => __('Start typing a username to add a new member.', 'buddypress'), 'warn_on_leave' => __('If you leave this page, you will lose any unsaved changes you have made to the group.', 'buddypress')));
    wp_enqueue_style('bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin.{$min}css", array(), bp_get_version());
    wp_style_add_data('bp_groups_admin_css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp_groups_admin_css', 'suffix', $min);
    }
    if ($doaction && 'save' == $doaction) {
        // Get group ID
        $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : '';
        $redirect_to = add_query_arg(array('gid' => (int) $group_id, 'action' => 'edit'), $redirect_to);
        // Check this is a valid form submission
        check_admin_referer('edit-group_' . $group_id);
        // Get the group from the database
        $group = groups_get_group('group_id=' . $group_id);
        // If the group doesn't exist, just redirect back to the index
        if (empty($group->slug)) {
            wp_redirect($redirect_to);
            exit;
        }
        // Check the form for the updated properties
        // Store errors
        $error = 0;
        $success_new = $error_new = $success_modified = $error_modified = array();
        // Group name and description are handled with
        // groups_edit_base_group_details()
        if (!groups_edit_base_group_details($group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0)) {
            $error = $group_id;
            // using negative integers for different error messages... eek!
            if (empty($_POST['bp-groups-name']) && empty($_POST['bp-groups-description'])) {
                $error = -3;
            } elseif (empty($_POST['bp-groups-name'])) {
                $error = -1;
            } elseif (empty($_POST['bp-groups-description'])) {
                $error = -2;
            }
        }
        // Enable discussion forum
        $enable_forum = isset($_POST['group-show-forum']) ? 1 : 0;
        /**
         * Filters the allowed status values for the group.
         *
         * @since 1.0.2
         *
         * @param array $value Array of allowed group statuses.
         */
        $allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
        $status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
        /**
         * Filters the allowed invite status values for the group.
         *
         * @since 1.5.0
         *
         * @param array $value Array of allowed invite statuses.
         */
        $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
        $invite_status = in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
        if (!groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status)) {
            $error = $group_id;
        }
        // Process new members
        $user_names = array();
        if (!empty($_POST['bp-groups-new-members'])) {
            $user_names = array_merge($user_names, explode(',', $_POST['bp-groups-new-members']));
        }
        if (!empty($user_names)) {
            foreach (array_values($user_names) as $user_name) {
                $un = trim($user_name);
                // Make sure the user exists before attempting
                // to add to the group
                $user = get_user_by('slug', $un);
                if (empty($user)) {
                    $error_new[] = $un;
                } else {
                    if (!groups_join_group($group_id, $user->ID)) {
                        $error_new[] = $un;
                    } else {
                        $success_new[] = $un;
                    }
                }
            }
        }
        // Process member role changes
        if (!empty($_POST['bp-groups-role']) && !empty($_POST['bp-groups-existing-role'])) {
            // Before processing anything, make sure you're not
            // attempting to remove the all user admins
            $admin_count = 0;
            foreach ((array) $_POST['bp-groups-role'] as $new_role) {
                if ('admin' == $new_role) {
                    $admin_count++;
                    break;
                }
            }
            if (!$admin_count) {
                $redirect_to = add_query_arg('no_admins', 1, $redirect_to);
                $error = $group_id;
            } else {
                // Process only those users who have had their roles changed
                foreach ((array) $_POST['bp-groups-role'] as $user_id => $new_role) {
                    $existing_role = isset($_POST['bp-groups-existing-role'][$user_id]) ? $_POST['bp-groups-existing-role'][$user_id] : '';
                    if ($existing_role != $new_role) {
                        switch ($new_role) {
                            case 'mod':
                                // Admin to mod is a demotion. Demote to
                                // member, then fall through
                                if ('admin' == $existing_role) {
                                    groups_demote_member($user_id, $group_id);
                                }
                            case 'admin':
                                // If the user was banned, we must
                                // unban first
                                if ('banned' == $existing_role) {
                                    groups_unban_member($user_id, $group_id);
                                }
                                // At this point, each existing_role
                                // is a member, so promote
                                $result = groups_promote_member($user_id, $group_id, $new_role);
                                break;
                            case 'member':
                                if ('admin' == $existing_role || 'mod' == $existing_role) {
                                    $result = groups_demote_member($user_id, $group_id);
                                } elseif ('banned' == $existing_role) {
                                    $result = groups_unban_member($user_id, $group_id);
                                }
                                break;
                            case 'banned':
                                $result = groups_ban_member($user_id, $group_id);
                                break;
                            case 'remove':
                                $result = groups_remove_member($user_id, $group_id);
                                break;
                        }
                        // Store the success or failure
                        if ($result) {
                            $success_modified[] = $user_id;
                        } else {
                            $error_modified[] = $user_id;
                        }
                    }
                }
            }
        }
        /**
         * Fires before redirect so plugins can do something first on save action.
         *
         * @since 1.6.0
         *
         * @param int $group_id ID of the group being edited.
         */
        do_action('bp_group_admin_edit_after', $group_id);
        // Create the redirect URL
        if ($error) {
            // This means there was an error updating group details
            $redirect_to = add_query_arg('error', (int) $error, $redirect_to);
        } else {
            // Group details were update successfully
            $redirect_to = add_query_arg('updated', 1, $redirect_to);
        }
        if (!empty($success_new)) {
            $success_new = implode(',', array_filter($success_new, 'urlencode'));
            $redirect_to = add_query_arg('success_new', $success_new, $redirect_to);
        }
        if (!empty($error_new)) {
            $error_new = implode(',', array_filter($error_new, 'urlencode'));
            $redirect_to = add_query_arg('error_new', $error_new, $redirect_to);
        }
        if (!empty($success_modified)) {
            $success_modified = implode(',', array_filter($success_modified, 'urlencode'));
            $redirect_to = add_query_arg('success_modified', $success_modified, $redirect_to);
        }
        if (!empty($error_modified)) {
            $error_modified = implode(',', array_filter($error_modified, 'urlencode'));
            $redirect_to = add_query_arg('error_modified', $error_modified, $redirect_to);
        }
        /**
         * Filters the URL to redirect to after successfully editing a group.
         *
         * @since 1.7.0
         *
         * @param string $redirect_to URL to redirect user to.
         */
        wp_redirect(apply_filters('bp_group_admin_edit_redirect', $redirect_to));
        exit;
        // If a referrer and a nonce is supplied, but no action, redirect back.
    } elseif (!empty($_GET['_wp_http_referer'])) {
        wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
        exit;
    }
}
Beispiel #12
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>';
                }
            }
        }
    }
}
/**
 * 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;
}
/**
 * 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'));
    }
}
Beispiel #15
0
 /**
  * @ticket BP6169
  * @group bp_has_activities
  */
 public function test_bp_has_activities_hidden_group_home_scope()
 {
     global $activities_template;
     $bp = buddypress();
     $reset_current_group = $bp->groups->current_group;
     $reset_current_action = $bp->current_action;
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $u3 = $this->factory->user->create();
     $this->set_current_user($u1);
     $g = $this->factory->group->create(array('status' => 'hidden'));
     groups_join_group($g, $u2);
     groups_join_group($g, $u3);
     $a1 = $this->factory->activity->create(array('component' => $bp->groups->id, 'item_id' => $g, 'type' => 'activity_update', 'user_id' => $u2, 'content' => 'foo bar'));
     $a2 = $this->factory->activity->create(array('component' => $bp->groups->id, 'item_id' => $g, 'type' => 'activity_update', 'user_id' => $u3, 'content' => 'bar foo'));
     $bp->groups->current_group = groups_get_group(array('group_id' => $g, 'populate_extras' => true));
     // On group's home the scope is set to 'home'
     $bp->current_action = 'home';
     bp_has_activities(array('action' => 'activity_update'));
     $this->assertEqualSets(array($a1, $a2), wp_list_pluck($activities_template->activities, 'id'));
     // clean up!
     $activities_template = null;
     $bp->groups->current_group = $reset_current_group;
     $bp->current_action = $reset_current_action;
 }
Beispiel #16
0
function pleio_api_join_group($group_id)
{
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    // access bypass for getting invisible group
    $ia = elgg_set_ignore_access(true);
    $group = get_entity($group_id);
    elgg_set_ignore_access($ia);
    if ($user instanceof ElggUser && $group instanceof ElggGroup) {
        // join or request
        $join = false;
        if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
            // anyone can join public groups and admins can join any group
            $join = true;
        } else {
            if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
                // user has invite to closed group
                $join = true;
            }
        }
        if ($join) {
            if (groups_join_group($group, $user)) {
                return new SuccessResult(elgg_echo("groups:joined"));
            } else {
                return new ErrorResult(elgg_echo("groups:cantjoin"));
            }
        } else {
            add_entity_relationship($user->guid, 'membership_request', $group->guid);
            // Notify group owner
            $url = "{$CONFIG->url}groups/requests/{$group->guid}";
            $subject = elgg_echo('groups:request:subject', array($user->name, $group->name));
            $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url));
            if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
                return new SuccessResult(elgg_echo("groups:joinrequestmade"));
            } else {
                return new ErrorResult(elgg_echo("groups:joinrequestnotmade"));
            }
        }
    } else {
        return new ErrorResult(elgg_echo("groups:cantjoin"));
    }
}
 /**
  * @group group_activity
  */
 public function test_wp_idea_stream_activity_private_group()
 {
     $bp = buddypress();
     $reset_current_group = $bp->groups->current_group;
     $reset_current_component = $bp->current_component;
     $bp->current_component = $bp->groups->id;
     $ga = $this->factory->user->create();
     $gm1 = $this->factory->user->create();
     $gm2 = $this->factory->user->create();
     $g = $this->factory->group->create(array('creator_id' => $ga, 'status' => 'private'));
     // Allow IdeaStream
     groups_update_groupmeta($g, '_group_ideastream_activate', 1);
     groups_update_groupmeta($g, '_group_ideastream_comments', 1);
     groups_join_group($g, $gm1);
     groups_join_group($g, $gm2);
     $bp->groups->current_group = groups_get_group(array('group_id' => $g, 'populate_extras' => true));
     $idea_id = $this->factory->idea->create(array('author' => $gm1, 'metas' => array('group_id' => $g), 'status' => 'private'));
     $component = $bp->groups->id;
     $a = bp_activity_get(array('filter' => array('action' => 'new_ideas', 'object' => $component, 'primary_id' => $g, 'secondary_id' => $idea_id), 'show_hidden' => true));
     $this->assertTrue($idea_id == $a['activities'][0]->secondary_item_id, 'An activity should be created when an idea is published in a private group');
     $this->assertTrue($component == $a['activities'][0]->component, 'The component should be set to groups');
     $this->assertTrue(!empty($a['activities'][0]->hide_sitewide), 'The visibility should be hidden');
     /** comments ****/
     $gadmin = $this->factory->user->get_object_by_id($ga);
     $gmember2 = $this->factory->user->get_object_by_id($gm2);
     // Create comments
     $c1 = $this->factory->idea_comment->create(array('user_id' => $ga, 'comment_author_email' => $gadmin->user_email, 'comment_post_ID' => $idea_id));
     $c2 = $this->factory->idea_comment->create(array('user_id' => $gm2, 'comment_author_email' => $gmember2->user_email, 'comment_post_ID' => $idea_id));
     // Approve the comment made by the "not" authors
     $this->factory->idea_comment->update_object($c1, array('comment_approved' => 1));
     $this->factory->idea_comment->update_object($c2, array('comment_approved' => 1));
     $a = bp_activity_get(array('filter' => array('action' => 'new_ideas_comment', 'object' => $component, 'primary_id' => $g), 'show_hidden' => true));
     $this->assertTrue($component == $a['activities'][0]->component, 'The component should be set to groups');
     $this->assertTrue(!empty($a['activities'][0]->hide_sitewide), 'The visibility should be hidden');
     $this->assertEqualSets(array($c1, $c2), wp_list_pluck($a['activities'], 'secondary_item_id'), 'An activity should be created when a comment is made by a group member on a private idea');
     // clean up!
     $bp->groups->current_group = $reset_current_group;
     $bp->current_component = $reset_current_component;
 }
Beispiel #18
0
function demodata_create_group_member($group_id, $admin, $num)
{
    $user_id = demodata_random_user_id();
    return groups_join_group($group_id, $user_id);
}
Beispiel #19
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'));
}
Beispiel #20
0
 /**
  * @group remove_from_group
  */
 public function test_wp_idea_stream_groups_member_remove_public_group()
 {
     $bp = buddypress();
     // Set current group
     $bp->groups->current_group = groups_get_group(array('group_id' => $this->group_id, 'populate_extras' => true));
     $u = $this->factory->user->create();
     groups_join_group($this->group_id, $u);
     $idea1 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id)));
     $idea2 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id)));
     $bp->is_item_admin = true;
     groups_remove_member($u, $this->group_id);
     // Check metas
     $this->assertEmpty(wp_idea_stream_ideas_get_meta($idea1, 'group_id'));
     $this->assertEmpty(wp_idea_stream_ideas_get_meta($idea2, 'group_id'));
     $ideas = wp_idea_stream_ideas_get_ideas(array('include' => array($idea1, $idea2)));
     $public_ideas = wp_filter_object_list($ideas['ideas'], array('post_status' => 'publish'), 'and', 'ID');
     $this->assertEqualSets(array($idea1, $idea2), $public_ideas, 'When a member is banned from the group, ideas should always be public');
     // Reset item admin
     $bp->is_item_admin = false;
 }
Beispiel #21
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;
}
Beispiel #22
0
function nuthanhtoan()
{
    global $post;
    if (isset($id) && $id) {
        $course_id = $id;
    } else {
        $course_id = get_the_ID();
    }
    // Free Course
    $free_course = get_post_meta($course_id, 'vibe_course_free', true);
    if (!is_user_logged_in() && vibe_validate($free_course)) {
        echo apply_filters('wplms_course_non_loggedin_user', '<a href="#" class="unlogin course_button button full">' . __('TAKE THIS COURSE', 'vibe') . '</a>');
        return;
    }
    $take_course_page_id = vibe_get_option('take_course_page');
    if (function_exists('icl_object_id')) {
        $take_course_page_id = icl_object_id($take_course_page_id, 'page', true);
    }
    $take_course_page = get_permalink($take_course_page_id);
    $user_id = get_current_user_id();
    do_action('wplms_the_course_button', $course_id, $user_id);
    $coursetaken = get_user_meta($user_id, $course_id, true);
    if (isset($free_course) && $free_course && $free_course != 'H' && is_user_logged_in() && (!isset($coursetaken) || !is_numeric($coursetaken))) {
        $duration = get_post_meta($course_id, 'vibe_duration', true);
        $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
        $new_duration = time() + $course_duration_parameter * $duration;
        //parameter 86400
        $new_duration = apply_filters('wplms_free_course_check', $new_duration);
        update_user_meta($user_id, $course_id, $new_duration);
        bp_course_update_user_course_status($user_id, $course_id, 0);
        $group_id = get_post_meta($course_id, 'vibe_group', true);
        if (isset($group_id) && $group_id != '') {
            groups_join_group($group_id, $user_id);
        }
        $coursetaken = $new_duration;
    }
    if (isset($coursetaken) && $coursetaken && is_user_logged_in()) {
        // COURSE IS TAKEN & USER IS LOGGED IN
        if ($coursetaken) {
            // COURSE ACTIVE
            $course_user = bp_course_get_user_course_status($user_id, $course_id);
            // Validates that a user has taken this course
            $new_course_user = get_user_meta($user_id, 'course_status' . $course_id, true);
            // Remove this line in 1.8.5
            if (isset($course_user) && is_numeric($course_user) || isset($free_course) && $free_course && $free_course != 'H' && is_user_logged_in()) {
                // COURSE PURCHASED SECONDARY VALIDATION
                echo '<form action="' . apply_filters('wplms_take_course_page', $take_course_page, $course_id) . '" method="post">';
                if (isset($new_course_user) && is_numeric($new_course_user) && $new_course_user) {
                    // For Older versions
                    switch ($course_user) {
                        case 1:
                            echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('START COURSE', 'vibe') . '">';
                            wp_nonce_field('start_course' . $user_id, 'start_course');
                            break;
                        case 2:
                            echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('HỌC TIẾP', 'vibe') . '">';
                            wp_nonce_field('continue_course' . $user_id, 'continue_course');
                            break;
                        case 3:
                            echo '<a href="#" class="full button">' . __('COURSE UNDER EVALUATION', 'vibe') . '</a>';
                            break;
                        case 4:
                            $finished_course_access = vibe_get_option('finished_course_access');
                            if (isset($finished_course_access) && $finished_course_access) {
                                echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('HOÀN THÀNH', 'vibe') . '">';
                                wp_nonce_field('continue_course' . $user_id, 'continue_course');
                            } else {
                                echo '<a href="#" class="full button">' . __('HOÀN THÀNH', 'vibe') . '</a>';
                            }
                            break;
                        default:
                            $course_button_html = '<a class="course_button button">' . __('COURSE ENABLED', 'vibe') . '<span>' . __('CONTACT ADMIN TO ENABLE', 'vibe') . '</span></a>';
                            echo apply_filters('wplms_default_course_button', $course_button_html, $user_id, $course_id, $course_user);
                            break;
                    }
                } else {
                    switch ($course_user) {
                        case 0:
                            echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('START COURSE', 'vibe') . '">';
                            wp_nonce_field('start_course' . $user_id, 'start_course');
                            break;
                        case 1:
                            echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('HỌC TIẾP', 'vibe') . '">';
                            wp_nonce_field('continue_course' . $user_id, 'continue_course');
                            break;
                        case 2:
                            echo '<a href="#" class="full button">' . __('COURSE UNDER EVALUATION', 'vibe') . '</a>';
                            break;
                        default:
                            $finished_course_access = vibe_get_option('finished_course_access');
                            if (isset($finished_course_access) && $finished_course_access) {
                                echo '<input type="submit" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button" value="' . __('HOÀN THÀNH', 'vibe') . '">';
                                wp_nonce_field('continue_course' . $user_id, 'continue_course');
                            } else {
                                echo '<a href="#" class="full button">' . __('COURSE FINISHED', 'vibe') . '</a>';
                            }
                            break;
                    }
                }
                echo '<input type="hidden" name="course_id" value="' . $course_id . '" />';
                echo '</form>';
            } else {
                $pid = get_post_meta($course_id, 'vibe_product', true);
                // SOME ISSUE IN PROCESS BUT STILL DISPLAYING THIS FOR NO REASON.
                echo '<a href="' . get_permalink($pid) . '" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button">' . __('COURSE ENABLED', 'vibe') . '<span>' . __('CONTACT ADMIN TO ENABLE', 'vibe') . '</span></a>';
            }
        } else {
            $pid = get_post_meta($course_id, 'vibe_product', true);
            $pid = apply_filters('wplms_course_product_id', $pid, $course_id, -1);
            // $id checks for Single Course page or Course page in the my courses section
            if (is_numeric($pid)) {
                $pid = get_permalink($pid);
            }
            echo '<a href="' . $pid . '" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button">' . __('Course Expired', 'vibe') . '&nbsp;<span>' . __('Click to renew', 'vibe') . '</span></a>';
        }
    } else {
        $pid = get_post_meta($course_id, 'vibe_product', true);
        $pid = apply_filters('wplms_course_product_id', $pid, $course_id, 0);
        if (is_numeric($pid)) {
            $pid = get_permalink($pid);
            $check = vibe_get_option('direct_checkout');
            $check = intval($check);
            if (isset($check) && $check) {
                $pid .= '?redirect';
            }
        }
        $extra = '';
        if (isset($pid) && $pid) {
            if (is_user_logged_in()) {
                if (get_post_meta($course_id, 'vibe_coming_soon', true) == 'S') {
                    echo '<a href="#" class="full button hienthikhoahoccomingsoon">' . __('COMING SOON', 'vibe') . '</a></br>';
                    echo '<div class="khoahoccomingsoon anpopupthongtinkhoahoc">';
                    echo '<span>Khóa học đang trong thời gian hoàn thiện, mong các bạn thông cảm</span>';
                    echo '</br>';
                    echo '<span  class="button dongkhoahoccomingsoon">' . __('ĐÓNG', 'vibe') . '</span>';
                    echo '</div>';
                } else {
                    echo '<a href="#" class="full button hienxacnhandangkykhoahoc">' . __('TAKE THIS COURSE', 'vibe') . '</a></br>';
                }
                //echo '<a href="#" class="full button hienxacnhandangkykhoahoc">'.__('TAKE THIS COURSE','vibe').'</a></br>';
                echo '<div class="xacnhandangkykhoahoc anpopupthongtinkhoahoc">';
                echo '<span>Nhấn vào nút "đồng ý" để ghi danh khóa học : ' . get_the_title($course_id) . '</span>';
                echo '</br>';
                echo '<span>Giá tiền khóa học là: ' . bp_course_get_course_credits('course_id=' . $course_id) . '</span></br>';
                echo '<div class="sapxepnutdangkykhoahoc">';
                echo '<a href="' . get_home_url() . '/thanh-toan-khoa-hoc/?course_id=' . $course_id . '" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button">' . __('Đồng ý', 'vibe') . apply_filters('wplms_course_button_extra', $extra, $course_id) . '</a>';
                echo '<span  class="full button huydangkykhoahoc">' . __('Hủy bỏ', 'vibe') . '</span>';
                echo '</div>';
                echo '<form action="' . apply_filters('wplms_take_course_page', $take_course_page, $course_id) . '" method="post" style="display: none" id="vaotranghockhoahoc">';
                wp_nonce_field('start_course' . $user_id, 'start_course');
                echo '<input type="hidden" name="course_id" value="' . $course_id . '" />';
                echo '</form>';
                echo '</div>';
            } else {
                //echo '<a href="#" class="unlogin '.((isset($id) && $id )?'':'course_button full ').'button">'.__('TAKE THIS COURSE','vibe').'</a>';
                if (get_post_meta($course_id, 'vibe_coming_soon', true) == 'S') {
                    echo '<a href="#" class="full button hienthikhoahoccomingsoon">' . __('COMING SOON', 'vibe') . '</a></br>';
                    echo '<div class="khoahoccomingsoon anpopupthongtinkhoahoc">';
                    echo '<span>Khóa học đang trong thời gian hoàn thiện, mong các bạn thông cảm</span>';
                    echo '</br>';
                    echo '<span  class="button dongkhoahoccomingsoon">' . __('ĐÓNG', 'vibe') . '</span>';
                    echo '</div>';
                } else {
                    echo '<a href="#" class="unlogin ' . (isset($id) && $id ? '' : 'course_button full ') . 'button">' . __('TAKE THIS COURSE', 'vibe') . '</a>';
                }
            }
        } else {
            echo '<a href="' . apply_filters('wplms_private_course_button', '#') . '" class="' . (isset($id) && $id ? '' : 'course_button full ') . 'button">' . apply_filters('wplms_private_course_button_label', __('PRIVATE COURSE', 'vibe')) . '</a>';
        }
    }
}
/**
 * Routes group invitation confirmation page
 *
 * @param string $hook   "route"
 * @param string $type   "groups"
 * @param array  $return Identifier and segments
 * @param array  $params Hook params
 * @return array
 */
function groups_invite_router($hook, $type, $return, $params)
{
    $identifier = $return['identifier'];
    $segments = $return['segments'];
    if ($identifier == 'groups' && $segments[0] == 'invitations' && $segments[1] == 'confirm') {
        $i = (int) get_input('i');
        $g = (int) get_input('g');
        $hmac = elgg_build_hmac(array('i' => $i, 'g' => $g));
        if (!$hmac->matchesToken(get_input('m'))) {
            register_error(elgg_echo('groups:invite:confirm:error'));
            forward('', '403');
        }
        $ia = elgg_set_ignore_access(true);
        $user = get_entity($i);
        $group = get_entity($g);
        if (groups_join_group($group, $user)) {
            system_message(elgg_echo('groups:joined'));
        } else {
            register_error(elgg_echo('groups:invite:confirm:error'));
        }
        forward('');
    }
}
Beispiel #24
0
function wplms_pmp_pro_connect($course_id, $user_id)
{
    if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && is_user_logged_in()) {
        $membership_ids = vibe_sanitize(get_post_meta($course_id, 'vibe_pmpro_membership', false));
        if (pmpro_hasMembershipLevel($membership_ids, $user_id) && isset($membership_ids) && count($membership_ids) >= 1) {
            $coursetaken = get_user_meta($user_id, $course_id, true);
            if (!isset($coursetaken) || $coursetaken == '') {
                $duration = get_post_meta($course_id, 'vibe_duration', true);
                $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
                $new_duration = time() + $course_duration_parameter * $duration;
                $new_duration = apply_filters('wplms_pmpro_course_check', $new_duration);
                if (update_user_meta($user_id, $course_id, $new_duration)) {
                    bp_course_update_user_course_status($user_id, $course_id, 0);
                    //since version 1.8.4
                    $group_id = get_post_meta($course_id, 'vibe_group', true);
                    if (isset($group_id) && $group_id != '') {
                        groups_join_group($group_id, $user_id);
                    }
                }
            }
        }
    }
}
Beispiel #25
0
 /**
  * @group groups_get_group_mods
  */
 public function test_groups_get_group_mods_cache()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $g = $this->factory->group->create(array('creator_id' => $u1));
     // User 2 joins the group
     groups_join_group($g, $u2);
     // prime cache
     groups_get_group_mods($g);
     // promote user 2 to an admin
     bp_update_is_item_admin(true);
     groups_promote_member($u2, $g, 'mod');
     // assert new cached value
     $this->assertEquals(1, count(groups_get_group_mods($g)));
 }
/**
 * 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'));
        }
    }
}
Beispiel #27
0
<?php

/**
 * Accept an email invitation
 */
$invitecode = get_input("invitecode");
$user = elgg_get_logged_in_user_entity();
$forward_url = REFERER;
if (!empty($invitecode)) {
    $forward_url = elgg_get_site_url() . "groups/invitations/" . $user->username;
    $group = group_tools_check_group_email_invitation($invitecode);
    if (!empty($group)) {
        if (groups_join_group($group, $user)) {
            $invitecode = sanitise_string($invitecode);
            $options = array("guid" => $group->getGUID(), "annotation_name" => "email_invitation", "wheres" => array("(v.string = '" . $invitecode . "' OR v.string LIKE '" . $invitecode . "|%')"), "annotation_owner_guid" => $group->getGUID(), "limit" => 1);
            $annotations = elgg_get_annotations($options);
            if (!empty($annotations)) {
                // ignore access in order to cleanup the invitation
                $ia = elgg_set_ignore_access(true);
                $annotations[0]->delete();
                // restore access
                elgg_set_ignore_access($ia);
            }
            $forward_url = $group->getURL();
            system_message(elgg_echo("group_tools:action:groups:email_invitation:success"));
        } else {
            register_error(elgg_echo("group_tools:action:groups:email_invitation:error:join", array($group->name)));
        }
    } else {
        register_error(elgg_echo("group_tools:action:groups:email_invitation:error:code"));
    }
Beispiel #28
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'));
}
function bp_course_add_user_to_course($user_id, $course_id)
{
    $duration = get_post_meta($course_id, 'vibe_duration', true);
    $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
    $t = time() + $duration * $course_duration_parameter;
    update_post_meta($course_id, $user_id, 0);
    update_user_meta($user_id, 'course_status' . $course_id, 1);
    update_user_meta($user_id, $course_id, $t);
    $group_id = get_post_meta($course_id, 'vibe_group', true);
    if (isset($group_id) && $group_id != '') {
        groups_join_group($group_id, $user_id);
    }
    bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course_id), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course_id) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course_id, 'primary_link' => get_permalink($course_id), 'secondary_item_id' => $user_id));
}
function bp_course_add_user_to_course($user_id, $course_id, $duration = NULL, $force = NULL)
{
    $seats = get_post_meta($course_id, 'vibe_max_students', true);
    $students = bp_course_count_students_pursuing($course_id);
    if (!empty($seats) && $seats < 9999 && empty($force)) {
        if ($seats < $students) {
            return false;
        }
    }
    if (empty($duration)) {
        $duration = get_post_meta($course_id, 'vibe_duration', true);
    }
    $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
    $start_date = get_post_meta($course_id, 'vibe_start_date', true);
    $time = 0;
    if (isset($start_date) && $start_date) {
        $time = strtotime($start_date);
    }
    if ($time < time()) {
        $time = time();
    }
    $t = $time + $duration * $course_duration_parameter;
    update_post_meta($course_id, $user_id, 0);
    $existing = get_user_meta($user_id, $course_id, true);
    if (empty($existing)) {
        update_user_meta($user_id, 'course_status' . $course_id, 1);
        $accuracy = vibe_get_option('sync_student_count');
        if (empty($accuracy) || $accuracy == '0') {
            $students = get_post_meta($course_id, 'vibe_students', true);
        }
        $students++;
        update_post_meta($course_id, 'vibe_students', $students);
    } else {
        update_user_meta($user_id, 'course_status' . $course_id, 2);
    }
    update_user_meta($user_id, $course_id, $t);
    $group_id = get_post_meta($course_id, 'vibe_group', true);
    if (isset($group_id) && $group_id != '') {
        groups_join_group($group_id, $user_id);
    } else {
        $group_id = '';
    }
    do_action('wplms_course_subscribed', $course_id, $user_id, $group_id);
    return $t;
}