/**
  * Render Metabox
  * 
  * @param type $item
  */
 public function admin_metabox($item)
 {
     $group_id = $item->id;
     $page_id = groups_get_groupmeta($group_id, '_group_linked_page', true);
     wp_nonce_field('_bp_linked_group_page', '_bp_linked_group_page_nonce');
     wp_dropdown_pages(array('name' => '_group_linked_page', 'selected' => $page_id, 'show_option_none' => __('Please select a page')));
 }
Exemplo n.º 2
0
/**
 * This function return the object val from given object and object_id
 * @param <string> $object mention for what you need cover eg. user,taxonomy,group
 * @param <int> $object_id ID of the object
 * @return <string> Object value of object.
 **/
function buddyboss_cover_photo_get($object, $object_id)
{
    global $bb_cover_photo_support;
    if (!in_array($object, $bb_cover_photo_support)) {
        //return nothing.
        return false;
    }
    $attachment = null;
    //user
    if ($object == 'user') {
        $meta = get_user_meta($object_id, "_bb_cover_photo", true);
        return (array) @$meta;
    }
    //taxonomy
    if ($object == 'taxonomy') {
        return '';
    }
    //group
    if ($object == 'group') {
        $meta = groups_get_groupmeta($object_id, '_bb_cover_photo', true);
        return (array) @$meta;
    }
    //forum
    if ($object == 'forum') {
        $meta = get_post_meta($object_id, '_bb_cover_photo', true);
        return (array) @$meta;
    }
}
Exemplo n.º 3
0
/**
 * Get allowed space for the given component( In MB) 
 * @param type $component
 * @param type $component_id
 * @return numeric : no. of MBs
 */
function mpp_get_allowed_space($component, $component_id = null)
{
    if (!empty($component_id)) {
        if ($component == 'members') {
            $space_allowed = bp_get_user_meta($component_id, 'mpp_upload_space', true);
        } elseif ($component == 'groups' && function_exists('groups_get_groupmeta')) {
            $space_allowed = groups_get_groupmeta($component_id, 'mpp_upload_space', true);
        }
    }
    if (empty($component_id) || empty($space_allowed)) {
        //if owner id is empty
        //get the gallery/group space
        if ($component == 'members') {
            $space_allowed = mpp_get_option('mpp_upload_space');
        } elseif ($component == 'groups') {
            $space_allowed = mpp_get_option('mpp_upload_space_groups');
        }
    }
    //we should have some value by now
    //if( empty($space_allowed))
    ///   $space_allowed = get_option("gallery_upload_space");//currently let us deal with blog space gallery will have it's own limit later
    if (empty($space_allowed)) {
        $space_allowed = mpp_get_option('mpp_upload_space');
    }
    //if we still don't have anything
    if (empty($space_allowed) || !is_numeric($space_allowed)) {
        $space_allowed = 10;
    }
    //by default
    return apply_filters('mpp_allowed_space', $space_allowed, $component, $component_id);
    //allow to override for specific users/groups
}
Exemplo n.º 4
0
/**
 * 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'));
    }
}
Exemplo n.º 5
0
function bp_forums_delete_group_forum($group_id)
{
    $forum_id = groups_get_groupmeta($group_id, 'forum_id');
    if (!empty($forum_id) && is_int($forum_id)) {
        do_action('bbpress_init');
        bb_delete_forum($forum_id);
    }
}
function bp_checkins_group_can_checkin()
{
    if (groups_get_groupmeta(bp_get_group_id(), 'checkins_ok')) {
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 7
0
function groups_update_group_forum($group_id)
{
    $group = new BP_Groups_Group($group_id);
    if (empty($group->enable_forum) || !bp_is_active('forums')) {
        return false;
    }
    $args = array('forum_id' => groups_get_groupmeta($group_id, 'forum_id'), 'forum_name' => $group->name, 'forum_desc' => $group->description, 'forum_slug' => $group->slug);
    bp_forums_update_forum(apply_filters('groups_update_group_forum', $args));
}
Exemplo n.º 8
0
function bp_cover_group_get_image_scr()
{
    global $bp;
    if (empty($group_id)) {
        $group_id = $bp->groups->current_group->id;
    }
    $image = groups_get_groupmeta($group_id, 'bp_cover_group', true);
    $filter .= "<img class='bp-cover' src='{$image}'/>";
    return $filter;
}
Exemplo n.º 9
0
function meso_fetch_random_groups($limit = '', $size = '', $type = '', $block_id = '')
{
    global $wpdb, $bp;
    $fetch_group = "SELECT * FROM " . $wpdb->base_prefix . "bp_groups WHERE status = 'public' ORDER BY rand() LIMIT {$limit}";
    $sql_fetch_group = $wpdb->get_results($fetch_group);
    ?>
<ul class="random-groups item-list group-in-<?php 
    echo $block_id;
    ?>
">
<?php 
    $no_avatar = 'http://www.gravatar.com/avatar';
    foreach ($sql_fetch_group as $group_fe) {
        $avatar_full = bp_core_fetch_avatar('item_id=' . $group_fe->id . '&class=avatar&object=group&type=' . $type . '&width=' . $size . '&height=' . $size);
        $group_description = stripslashes($group_fe->description);
        ?>
<li>
<div class="item-avatar"><?php 
        echo $avatar_full;
        ?>
</div>
<div class="item">
<div class="item-title">
<a title="<?php 
        echo $group_fe->name . ' - ' . dez_get_short_text($group_description, 150);
        ?>
" href="<?php 
        echo home_url() . '/' . bp_get_root_slug('groups') . '/' . $group_fe->slug;
        ?>
"><?php 
        echo $group_fe->name;
        ?>
</a>
</div>
<div class="item-meta">
<span class="activity">
<?php 
        echo groups_get_groupmeta($group_fe->id, $meta_key = 'total_member_count');
        ?>
 <?php 
        echo bp_get_root_slug('members');
        ?>
</span>
</div>
</div>
</li>
<?php 
    }
    ?>
</ul>
<?php 
}
Exemplo n.º 10
0
/**
 * Update group forum metadata (title, description, slug) when the group's details are edited.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $group_id Group id, passed from groups_details_updated.
 */
function groups_update_group_forum($group_id)
{
    $group = groups_get_group(array('group_id' => $group_id));
    /**
     * Bail in the following three situations:
     *  1. Forums are not enabled for this group
     *  2. The BP Forum component is not enabled
     *  3. The built-in bbPress forums are not correctly installed (usually means they've been
     *     uninstalled)
     */
    if (empty($group->enable_forum) || !bp_is_active('forums') || function_exists('bp_forums_is_installed_correctly') && !bp_forums_is_installed_correctly()) {
        return false;
    }
    bp_forums_update_forum(apply_filters('groups_update_group_forum', array('forum_id' => groups_get_groupmeta($group_id, 'forum_id'), 'forum_name' => $group->name, 'forum_desc' => $group->description, 'forum_slug' => $group->slug)));
}
/**
 * Checks upload permissions.
 * Adapted from Group Documents plugin.
 */
function bpfb_documents_allowed($group = false)
{
    if (!$group) {
        return false;
    }
    $user = wp_get_current_user();
    $moderator_of = BP_Groups_Member::get_is_admin_of($user->ID) + BP_Groups_Member::get_is_mod_of($user->ID);
    $moderator_of = is_array($moderator_of) && isset($moderator_of['groups']) ? $moderator_of['groups'] : false;
    $is_mod = false;
    foreach ($moderator_of as $gm) {
        if ($gm->id == $group->id) {
            $is_mod = true;
            break;
        }
    }
    switch (get_option('bp_group_documents_upload_permission')) {
        case 'mods_decide':
            switch (groups_get_groupmeta($group->id, 'group_documents_upload_permission')) {
                case 'mods_only':
                    if ($is_mod) {
                        return true;
                    }
                    break;
                case 'members':
                default:
                    if (bp_group_is_member($group)) {
                        return true;
                    }
                    break;
            }
            break;
        case 'mods_only':
            if ($is_mod) {
                return true;
            }
            break;
        case 'members':
        default:
            if (bp_group_is_member($group)) {
                return true;
            }
            break;
    }
    return false;
}
Exemplo n.º 12
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' ) );
	}
}
Exemplo n.º 13
0
 function get()
 {
     if (false === $this->group_id) {
         global $groups_template;
         if (!empty($groups_template->group)) {
             $group_id = bp_get_group_id();
             if (!empty($group_id)) {
                 $this->group_id = $group_id;
             }
         } else {
             if (isset($this->media) && isset($this->media->context_id)) {
                 $this->group_id = $this->media->context_id;
             } else {
                 return false;
             }
         }
     }
     $this->featured = groups_get_groupmeta($this->group_id, 'rtmedia_group_featured_media', true);
     return $this->featured;
 }
Exemplo n.º 14
0
 /**
  * @group bp_groups_update_meta_cache
  */
 public function test_bp_groups_update_meta_cache()
 {
     $g1 = $this->factory->group->create();
     $g2 = $this->factory->group->create();
     $time = bp_core_current_time();
     // Set up some data
     groups_update_groupmeta($g1, 'total_member_count', 4);
     groups_update_groupmeta($g1, 'last_activity', $time);
     groups_update_groupmeta($g1, 'foo', 'bar');
     groups_update_groupmeta($g2, 'total_member_count', 81);
     groups_update_groupmeta($g2, 'last_activity', $time);
     groups_update_groupmeta($g2, 'foo', 'baz');
     // Prime the cache for $g1
     groups_update_groupmeta($g1, 'foo', 'bar');
     groups_get_groupmeta($g1, 'foo');
     // Ensure an empty cache for $g2
     wp_cache_delete($g2, 'group_meta');
     bp_groups_update_meta_cache(array($g1, $g2));
     $expected = array($g1 => array('total_member_count' => array(4), 'last_activity' => array($time), 'foo' => array('bar')), $g2 => array('total_member_count' => array(81), 'last_activity' => array($time), 'foo' => array('baz')));
     $found = array($g1 => wp_cache_get($g1, 'group_meta'), $g2 => wp_cache_get($g2, 'group_meta'));
     $this->assertEquals($expected, $found);
 }
 function populate()
 {
     global $wpdb, $bp;
     if ($group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id))) {
         bp_groups_update_meta_cache($this->id);
         $this->id = $group->id;
         $this->creator_id = $group->creator_id;
         $this->name = stripslashes($group->name);
         $this->slug = $group->slug;
         $this->description = stripslashes($group->description);
         $this->status = $group->status;
         $this->enable_forum = $group->enable_forum;
         $this->date_created = $group->date_created;
         $this->last_activity = groups_get_groupmeta($this->id, 'last_activity');
         $this->total_member_count = groups_get_groupmeta($this->id, 'total_member_count');
         $this->is_member = BP_Groups_Member::check_is_member(bp_loggedin_user_id(), $this->id);
         // If this is a private or hidden group, does the current user have access?
         if ('private' == $this->status || 'hidden' == $this->status) {
             if ($this->is_member && is_user_logged_in() || bp_current_user_can('bp_moderate')) {
                 $this->user_has_access = true;
             } else {
                 $this->user_has_access = false;
             }
         } else {
             $this->user_has_access = true;
         }
         // Get group admins and mods
         $admin_mods = $wpdb->get_results(apply_filters('bp_group_admin_mods_user_join_filter', $wpdb->prepare("SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id)));
         foreach ((array) $admin_mods as $user) {
             if ((int) $user->is_admin) {
                 $this->admins[] = $user;
             } else {
                 $this->mods[] = $user;
             }
         }
     } else {
         $this->id = 0;
     }
 }
    function manage_course_settings($group_id = NULL)
    {
        wp_enqueue_script('jquery-ui-datepicker');
        $args = array('post_type' => 'course', 'post_per_page' => -1);
        global $bp;
        $group_id = bp_get_group_id();
        ?>
		<h3><?php 
        _e('Connect with Course');
        ?>
</h3>
		<?php 
        $course_id = groups_get_groupmeta($group_id, 'course_id');
        $the_query = get_posts($args);
        echo '<select name="group_course" class="chosen"><option value="">' . __('Select a Course', 'vibe') . '</option>';
        foreach ($the_query as $result) {
            echo '<option value="' . $result->ID . '" ' . selected($result->ID, $course_id) . '>' . $result->post_title . '</option>';
        }
        echo '</select>';
        ?>
<hr />
		<h4><?php 
        _e('Start Date/Time');
        ?>
</h4>
		<?php 
        $start_date = groups_get_groupmeta($group_id, 'start_date');
        echo '<input type="text" name="start_date" class="date_box" value="' . $start_date . '" />';
        ?>
		<script>
			jQuery(document).ready(function(){
				    jQuery('.date_box').datepicker({
				      dateFormat: 'yy-mm-dd'
				    });
			});
		</script>
		<hr />
		<?php 
    }
Exemplo n.º 17
0
 function unban()
 {
     if ($this->is_admin) {
         return false;
     }
     $this->is_banned = 0;
     groups_update_groupmeta($this->group_id, 'total_member_count', (int) groups_get_groupmeta($this->group_id, 'total_member_count') + 1);
     return $this->save();
 }
Exemplo n.º 18
0
/**
 *
 * @param type $group_id
 * @param type $user_id
 *
 * @return boolean
 */
function can_user_create_album_in_group($group_id = false, $user_id = false)
{
    if ($group_id == false) {
        $group = groups_get_current_group();
        $group_id = $group->id;
    }
    $upload_level = groups_get_groupmeta($group_id, "rt_media_group_control_level");
    if (empty($upload_level)) {
        $upload_level = groups_get_groupmeta($group_id, "bp_media_group_control_level");
        if (empty($upload_level)) {
            $upload_level = "all";
        }
    }
    $user_id = get_current_user_id();
    $display_flag = false;
    if (groups_is_user_member($user_id, $group_id)) {
        if ($upload_level == "admin") {
            if (groups_is_user_admin($user_id, $group_id) > 0) {
                $display_flag = true;
            }
        } else {
            if ($upload_level == "moderators") {
                if (groups_is_user_mod($user_id, $group_id) || groups_is_user_admin($user_id, $group_id)) {
                    $display_flag = true;
                }
            } else {
                $display_flag = true;
            }
        }
    }
    $display_flag = apply_filters('can_user_create_album_in_group', $display_flag);
    return $display_flag;
}
Exemplo n.º 19
0
/**
 * This screen function handles actions related to group forums.
 */
function groups_screen_group_forum()
{
    if (!bp_is_active('forums') || !bp_forums_is_installed_correctly()) {
        return false;
    }
    if (bp_action_variable(0) && !bp_is_action_variable('topic', 0)) {
        bp_do_404();
        return;
    }
    $bp = buddypress();
    if (!$bp->groups->current_group->user_has_access) {
        bp_core_no_access();
        return;
    }
    if (!bp_is_single_item()) {
        return false;
    }
    // Fetch the details we need.
    $topic_slug = (string) bp_action_variable(1);
    $topic_id = bp_forums_get_topic_id_from_slug($topic_slug);
    $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
    $user_is_banned = false;
    if (!bp_current_user_can('bp_moderate') && groups_is_user_banned(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
        $user_is_banned = true;
    }
    if (!empty($topic_slug) && !empty($topic_id)) {
        // Posting a reply.
        if (!$user_is_banned && !bp_action_variable(2) && isset($_POST['submit_reply'])) {
            // Check the nonce.
            check_admin_referer('bp_forums_new_reply');
            // Auto join this user if they are not yet a member of this group.
            if (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
            }
            $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
            // Don't allow reply flooding.
            if (bp_forums_reply_exists($_POST['reply_text'], $topic_id, bp_loggedin_user_id())) {
                bp_core_add_message(__('It looks like you\'ve already said that!', 'buddypress'), 'error');
            } else {
                if (!($post_id = groups_new_group_forum_post($_POST['reply_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when replying to that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Your reply was posted successfully', 'buddypress'));
                }
            }
            $query_vars = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
            $redirect = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
            if (!empty($post_id)) {
                $redirect .= '#post-' . $post_id;
            }
            bp_core_redirect($redirect);
        } elseif (bp_is_action_variable('stick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_stick_topic');
            if (!bp_forums_sticky_topic(array('topic_id' => $topic_id))) {
                bp_core_add_message(__('There was an error when making that topic a sticky', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was made sticky successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been stickied.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being stickied.
             */
            do_action('groups_stick_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('unstick', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_unstick_topic');
            if (!bp_forums_sticky_topic(array('topic_id' => $topic_id, 'mode' => 'unstick'))) {
                bp_core_add_message(__('There was an error when unsticking that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was unstuck successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been un-stickied.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being un-stickied.
             */
            do_action('groups_unstick_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('close', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_close_topic');
            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id))) {
                bp_core_add_message(__('There was an error when closing that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was closed successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been closed.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being closed.
             */
            do_action('groups_close_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (bp_is_action_variable('open', 2) && (bp_is_item_admin() || bp_is_item_mod())) {
            // Check the nonce.
            check_admin_referer('bp_forums_open_topic');
            if (!bp_forums_openclose_topic(array('topic_id' => $topic_id, 'mode' => 'open'))) {
                bp_core_add_message(__('There was an error when opening that topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was opened successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been opened.
             *
             * @since 1.1.0
             *
             * @param int $topic_id ID of the topic being opened.
             */
            do_action('groups_open_forum_topic', $topic_id);
            bp_core_redirect(wp_get_referer());
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            /* Check the logged in user can delete this topic */
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_topic');
            /**
             * Fires before a group forum topic is deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_before_delete_forum_topic', $topic_id);
            if (!groups_delete_group_forum_topic($topic_id)) {
                bp_core_add_message(__('There was an error deleting the topic', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The topic was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after a group forum topic has been deleted.
             *
             * @since 1.5.0
             *
             * @param int $topic_id ID of the topic being deleted.
             */
            do_action('groups_delete_forum_topic', $topic_id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/');
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && !bp_action_variable(3)) {
            // Fetch the topic.
            $topic = bp_forums_get_topic_details($topic_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $topic->topic_poster) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_topic');
                $topic_tags = !empty($_POST['topic_tags']) ? $_POST['topic_tags'] : false;
                if (!groups_update_group_forum_topic($topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags)) {
                    bp_core_add_message(__('There was an error when editing that topic', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The topic was edited successfully', 'buddypress'));
                }
                /**
                 * Fires after a group forum topic has been edited.
                 *
                 * @since 1.1.0
                 *
                 * @param int $topic_id ID of the topic being edited.
                 */
                do_action('groups_edit_forum_topic', $topic_id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic_slug . '/');
            }
            /**
             * Filters the template to load for a topic edit page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic edit template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Delete a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('delete', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            // Check the nonce.
            check_admin_referer('bp_forums_delete_post');
            /**
             * Fires before the deletion of a group forum post.
             *
             * @since 1.5.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_before_delete_forum_post', $post_id);
            if (!groups_delete_group_forum_post($post_id)) {
                bp_core_add_message(__('There was an error deleting that post', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The post was deleted successfully', 'buddypress'));
            }
            /**
             * Fires after the deletion of a group forum post.
             *
             * @since 1.1.0
             *
             * @param int $post_id ID of the forum post being deleted.
             */
            do_action('groups_delete_forum_post', $post_id);
            bp_core_redirect(wp_get_referer());
            // Editing a post.
        } elseif (empty($user_is_banned) && bp_is_action_variable('edit', 2) && ($post_id = bp_action_variable(4))) {
            // Fetch the post.
            $post = bp_forums_get_post($post_id);
            // Check the logged in user can edit this topic.
            if (!bp_is_item_admin() && !bp_is_item_mod() && (int) bp_loggedin_user_id() != (int) $post->poster_id) {
                bp_core_redirect(wp_get_referer());
            }
            if (isset($_POST['save_changes'])) {
                // Check the nonce.
                check_admin_referer('bp_forums_edit_post');
                $topic_page = isset($_GET['topic_page']) ? $_GET['topic_page'] : false;
                if (!($post_id = groups_update_group_forum_post($post_id, $_POST['post_text'], $topic_id, $topic_page))) {
                    bp_core_add_message(__('There was an error when editing that post', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('The post was edited successfully', 'buddypress'));
                }
                if ($_SERVER['QUERY_STRING']) {
                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
                }
                /**
                 * Fires after the editing of a group forum post.
                 *
                 * @since 1.1.0
                 *
                 * @param int $post_id ID of the forum post being edited.
                 */
                do_action('groups_edit_forum_post', $post_id);
                bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id);
            }
            /** This filter is documented in bp-groups/bp-groups-screens.php */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic_edit', 'groups/single/home'));
            // Standard topic display.
        } else {
            if (!empty($user_is_banned)) {
                bp_core_add_message(__("You have been banned from this group.", 'buddypress'));
            }
            /**
             * Filters the template to load for a topic page.
             *
             * @since 1.1.0
             *
             * @param string $value Path to a topic template.
             */
            bp_core_load_template(apply_filters('groups_template_group_forum_topic', 'groups/single/home'));
        }
        // Forum topic does not exist.
    } elseif (!empty($topic_slug) && empty($topic_id)) {
        bp_do_404();
        return;
    } else {
        // Posting a topic.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            // Check the nonce.
            check_admin_referer('bp_forums_new_topic');
            if ($user_is_banned) {
                $error_message = __("You have been banned from this group.", 'buddypress');
            } elseif (bp_groups_auto_join() && !bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group.
                groups_join_group($bp->groups->current_group->id, bp_loggedin_user_id());
            }
            if (empty($_POST['topic_title'])) {
                $error_message = __('Please provide a title for your forum topic.', 'buddypress');
            } elseif (empty($_POST['topic_text'])) {
                $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
            }
            if (empty($forum_id)) {
                $error_message = __('This group does not have a forum setup yet.', 'buddypress');
            }
            if (isset($error_message)) {
                bp_core_add_message($error_message, 'error');
                $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
            } else {
                if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                    bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                    $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                } else {
                    bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                    $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                }
            }
            bp_core_redirect($redirect);
        }
        /**
         * Fires at the end of the group forum screen loading process.
         *
         * @since 1.0.0
         *
         * @param int $topic_id ID of the topic being displayed.
         * @param int $forum_id ID of the forum being displayed.
         */
        do_action('groups_screen_group_forum', $topic_id, $forum_id);
        /**
         * Filters the template to load for a group forum page.
         *
         * @since 1.0.0
         *
         * @param string $value Path to a group forum template.
         */
        bp_core_load_template(apply_filters('groups_template_group_forum', 'groups/single/home'));
    }
}
function gtags_get_group_tags($group = false)
{
    global $groups_template;
    if (!$group) {
        $group =& $groups_template->group;
    }
    if (!$group) {
        return;
    }
    $group_tags = groups_get_groupmeta($group->id, 'gtags_group_tags');
    $group_tags = stripcslashes($group_tags);
    return apply_filters('gtags_get_group_tags', $group_tags);
}
/**
 * Get the invite status of a group.
 *
 * 'invite_status' became part of BuddyPress in BP 1.5. In order to provide
 * backward compatibility with earlier installations, groups without a status
 * set will default to 'members', ie all members in a group can send
 * invitations. Filter 'bp_group_invite_status_fallback' to change this
 * fallback behavior.
 *
 * This function can be used either in or out of the loop.
 *
 * @since 1.5.0
 *
 * @param int|bool $group_id Optional. The ID of the group whose status you want to
 *                           check. Default: the displayed group, or the current group
 *                           in the loop.
 * @return bool|string Returns false when no group can be found. Otherwise
 *                     returns the group invite status, from among 'members',
 *                     'mods', and 'admins'.
 */
function bp_group_get_invite_status($group_id = false)
{
    global $groups_template;
    if (!$group_id) {
        $bp = buddypress();
        if (isset($bp->groups->current_group->id)) {
            // Default to the current group first.
            $group_id = $bp->groups->current_group->id;
        } elseif (isset($groups_template->group->id)) {
            // Then see if we're in the loop.
            $group_id = $groups_template->group->id;
        } else {
            return false;
        }
    }
    $invite_status = groups_get_groupmeta($group_id, 'invite_status');
    // Backward compatibility. When 'invite_status' is not set, fall back to a default value.
    if (!$invite_status) {
        $invite_status = apply_filters('bp_group_invite_status_fallback', 'members');
    }
    /**
     * Filters the invite status of a group.
     *
     * Invite status in this case means who from the group can send invites.
     *
     * @since 1.5.0
     *
     * @param string $invite_status Membership level needed to send an invite.
     * @param int    $group_id      ID of the group whose status is being checked.
     */
    return apply_filters('bp_group_get_invite_status', $invite_status, $group_id);
}
/**
 * Get the invite status of a group
 *
 * 'invite_status' became part of BuddyPress in BP 1.5. In order to provide backward compatibility,
 * groups without a status set will default to 'members', ie all members in a group can send
 * invitations. Filter 'bp_group_invite_status_fallback' to change this fallback behavior.
 *
 * This function can be used either in or out of the loop.
 *
 * @package BuddyPress
 * @subpackage Groups Template
 * @since BuddyPress (1.5)
 *
 * @param int $group_id (optional) The id of the group whose status you want to check
 * @return mixed Returns false when no group can be found. Otherwise returns the group invite
 *    status, from among 'members', 'mods', and 'admins'
 */
function bp_group_get_invite_status($group_id = false)
{
    global $bp, $groups_template;
    if (!$group_id) {
        if (isset($bp->groups->current_group->id)) {
            // Default to the current group first
            $group_id = $bp->groups->current_group->id;
        } else {
            if (isset($groups_template->group->id)) {
                // Then see if we're in the loop
                $group_id = $groups_template->group->id;
            } else {
                return false;
            }
        }
    }
    $invite_status = groups_get_groupmeta($group_id, 'invite_status');
    // Backward compatibility. When 'invite_status' is not set, fall back to a default value
    if (!$invite_status) {
        $invite_status = apply_filters('bp_group_invite_status_fallback', 'members');
    }
    return apply_filters('bp_group_get_invite_status', $invite_status, $group_id);
}
Exemplo n.º 23
0
/**
 * Initiate the loop for a single topic's posts.
 *
 * @param array $args {
 *     Arguments for limiting the contents of the topic posts loop.
 *     @type int $topic_id ID of the topic to which the posts belong.
 *     @type int $per_page Number of items to return per page. Default: 15.
 *     @type int $max Max items to return. Default: false.
 *     @type string $order 'ASC' or 'DESC'.
 * }
 * @return bool True when posts are found corresponding to the args,
 *         otherwise false.
 */
function bp_has_forum_topic_posts($args = '')
{
    global $topic_template;
    $defaults = array('topic_id' => false, 'per_page' => 15, 'max' => false, 'order' => 'ASC');
    $r = bp_parse_args($args, $defaults, 'has_forum_topic_posts');
    extract($r, EXTR_SKIP);
    if (empty($topic_id) && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_action_variable(1)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
    } elseif (empty($topic_id) && bp_is_forums_component() && bp_is_current_action('topic') && bp_action_variable(0)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(0));
    }
    if (empty($topic_id)) {
        return false;
    } else {
        $topic_template = new BP_Forums_Template_Topic((int) $topic_id, $per_page, $max, $order);
        // Current topic forum_id needs to match current_group forum_id
        if (bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta(bp_get_current_group_id(), 'forum_id')) {
            return false;
        }
    }
    return apply_filters('bp_has_topic_posts', $topic_template->has_posts(), $topic_template);
}
Exemplo n.º 24
0
 function remove()
 {
     global $wpdb, $bp;
     $sql = $wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id);
     if (!($result = $wpdb->query($sql))) {
         return false;
     }
     groups_update_groupmeta($this->group_id, 'total_member_count', (int) groups_get_groupmeta($this->group_id, 'total_member_count') - 1);
     $group_count = bp_get_user_meta($this->user_id, 'total_group_count', true);
     if (!empty($group_count)) {
         bp_update_user_meta($this->user_id, 'total_group_count', (int) $group_count - 1);
     }
     return $result;
 }
Exemplo n.º 25
0
/**
 * Edit the base details for a group.
 *
 * These are the settings that appear on the Settings page of the group's Admin
 * section (privacy settings, "enable forum", invitation status).
 *
 * @param int         $group_id      ID of the group.
 * @param bool        $enable_forum  Whether to enable a forum for the group.
 * @param string      $status        Group status. 'public', 'private', 'hidden'.
 * @param string|bool $invite_status Optional. Who is allowed to send invitations
 *                                   to the group. 'members', 'mods', or 'admins'.
 *
 * @return bool True on success, false on failure.
 */
function groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status = false)
{
    $group = groups_get_group(array('group_id' => $group_id));
    $group->enable_forum = $enable_forum;
    /***
     * Before we potentially switch the group status, if it has been changed to public
     * from private and there are outstanding membership requests, auto-accept those requests.
     */
    if ('private' == $group->status && 'public' == $status) {
        groups_accept_all_pending_membership_requests($group->id);
    }
    // Now update the status
    $group->status = $status;
    if (!$group->save()) {
        return false;
    }
    // If forums have been enabled, and a forum does not yet exist, we need to create one.
    if ($group->enable_forum) {
        if (bp_is_active('forums') && !groups_get_groupmeta($group->id, 'forum_id')) {
            groups_new_group_forum($group->id, $group->name, $group->description);
        }
    }
    // Set the invite status
    if ($invite_status) {
        groups_update_groupmeta($group->id, 'invite_status', $invite_status);
    }
    groups_update_groupmeta($group->id, 'last_activity', bp_core_current_time());
    /**
     * Fires after the update of a groups settings.
     *
     * @since 1.0.0
     *
     * @param int $id ID of the group that was updated.
     */
    do_action('groups_settings_updated', $group->id);
    return true;
}
Exemplo n.º 26
0
 /**
  * Markup for the Last Active column.
  *
  * @since 1.7.0
  *
  * @param array $item Information about the current row.
  */
 public function column_last_active($item = array())
 {
     $last_active = groups_get_groupmeta($item['id'], 'last_activity');
     /**
      * Filters the markup for the Last Active column.
      *
      * @since 1.7.0
      *
      * @param string $last_active Markup for the Last Active column.
      * @parma array  $item        The current group item in the loop.
      */
     echo apply_filters_ref_array('bp_groups_admin_get_group_last_active', array($last_active, $item));
 }
 /**
  * @group last_activity
  */
 function test_update_group_last_activity_on_doc_comment()
 {
     $g = $this->factory->group->create();
     $d = $this->factory->doc->create(array('group' => $g));
     $last_activity = date('Y-m-d H:i:s', time() - 100000);
     groups_update_groupmeta($g, 'last_activity', $last_activity);
     $c = $this->factory->comment->create(array('comment_post_ID' => $d));
     $this->assertNotEquals($last_activity, groups_get_groupmeta($g, 'last_activity'));
 }
Exemplo n.º 28
0
 /**
  * Gets the group meta, use default if meta value is not set
  *
  * @package Rendez Vous
  * @subpackage Groups
  *
  * @since Rendez Vous (1.1.0)
  *
  * @param  int                    $group_id the group ID
  * @param  string                 $option   meta key
  * @param  mixed                  $default  the default value to fallback with
  * @uses   groups_get_groupmeta() to get the meta value
  * @uses   apply_filters()        call "rendez_vous_groups_option{$option}" to override the group meta value
  * @return mixed                  the meta value
  */
 public static function group_get_option($group_id = 0, $option = '', $default = '')
 {
     if (empty($group_id) || empty($option)) {
         return false;
     }
     $group_option = groups_get_groupmeta($group_id, $option);
     if ('' === $group_option) {
         $group_option = $default;
     }
     /**
      * @param   mixed $group_option the meta value
      * @param   int   $group_id     the group ID
      */
     return apply_filters("rendez_vous_groups_option{$option}", $group_option, $group_id);
 }
 /**
  * enable_forum_assignment_screen( $vars )
  *
  * Hooks into screen_handler
  * If forum is active for group, creates a thread for assignment
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function enable_forum_assignment_screen($vars)
 {
     global $bp;
     $e_forum_nonce = 'assignment_enable_forum';
     $is_nonce = false;
     if (isset($_POST['_wpnonce'])) {
         $is_nonce = wp_verify_nonce($_POST['_wpnonce'], $e_forum_nonce);
     }
     // Nonce will take care of dublicates
     if ($is_nonce && bp_group_is_forum_enabled()) {
         $assignment = $this->is_assignment($this->current_assignment);
         $assignment_forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
         // Append assignment link to the content
         $assignment->post_content = $assignment->post_content . "\n\n" . "<a href=\"" . $vars['current_uri'] . '/assignment/' . $assignment->post_name . "\">" . __('Courseware Assignment Link', 'bpsp') . "</a>";
         // Create tags from title and append 'assignment' to it
         $assignment->tags = str_replace('-', ', ', $assignment->post_name) . __(", assignment", 'bpsp');
         // Create a topic for current assignment
         $topic = groups_new_group_forum_topic($assignment->post_title, $assignment->post_content, $assignment->tags, $assignment_forum_id);
         // Create topic for assignment and save in post_meta topic link
         if ($topic) {
             $topic_permalink = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug;
             if (update_post_meta($assignment->ID, 'topic_link', $topic_permalink)) {
                 $vars['message'] = __('Assignment forum created.', 'bpsp');
             }
             // Force saving the new permalink to $vars, since it doesn't show up
             $vars['forum_link'] = $topic_permalink;
         }
     } else {
         $vars['error'] = __('Forum was not created.', 'bpsp');
     }
     return $this->single_assignment_screen($vars);
 }
Exemplo n.º 30
0
/**
 * Determine whether the logged-in user has left a review for this group.
 *
 * @package BP Group Reviews
 *
 * @return bool
 */
function bpgr_has_written_review()
{
    global $bp;
    $has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review');
    return apply_filters('bpgr_has_written_reviews', in_array($bp->loggedin_user->id, (array) $has_posted));
}