/**
 * Return the admin links for the current topic in the loop.
 *
 * @param array $args {
 *     @type string $seperator The character to use when separating
 *           links. Default: '|'.
 * }
 * @return HTML string containing the admin links for the current topic.
 */
function bp_get_the_topic_admin_links($args = '')
{
    global $forum_template;
    $defaults = array('seperator' => '|');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic') . '">' . __('Edit Topic', 'buddypress') . '</a>';
    if (bp_is_item_admin() || bp_is_item_mod() || bp_current_user_can('bp_moderate')) {
        if (0 == (int) $forum_template->topic->topic_sticky) {
            $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic') . '">' . __('Sticky Topic', 'buddypress') . '</a>';
        } else {
            $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic') . '">' . __('Un-stick Topic', 'buddypress') . '</a>';
        }
        if (0 == (int) $forum_template->topic->topic_open) {
            $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic') . '">' . __('Open Topic', 'buddypress') . '</a>';
        } else {
            $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic') . '">' . __('Close Topic', 'buddypress') . '</a>';
        }
        $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic') . '">' . __('Delete Topic', 'buddypress') . '</a>';
    }
    return implode(' ' . $seperator . ' ', (array) $links);
}
function bp_group_is_mod()
{
    return bp_is_item_mod();
}
/**
 * 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 bp_group_admin_tabs($group = false)
{
    global $bp, $groups_template;
    if (empty($group)) {
        $group = $groups_template->group ? $groups_template->group : $bp->groups->current_group;
    }
    $current_tab = bp_get_group_current_admin_tab();
    if (bp_is_item_admin() || bp_is_item_mod()) {
        ?>

		<li<?php 
        if ('edit-details' == $current_tab || empty($current_tab)) {
            ?>
 class="current"<?php 
        }
        ?>
><a href="<?php 
        echo trailingslashit(bp_get_group_permalink($group) . 'admin/edit-details');
        ?>
"><?php 
        _e('Details', 'buddypress');
        ?>
</a></li>

	<?php 
    }
    ?>

	<?php 
    if (!bp_is_item_admin()) {
        return false;
    }
    ?>

	<li<?php 
    if ('group-settings' == $current_tab) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_get_group_permalink($group) . 'admin/group-settings');
    ?>
"><?php 
    _e('Settings', 'buddypress');
    ?>
</a></li>

	<?php 
    if (!(int) bp_get_option('bp-disable-avatar-uploads')) {
        ?>

		<li<?php 
        if ('group-avatar' == $current_tab) {
            ?>
 class="current"<?php 
        }
        ?>
><a href="<?php 
        echo trailingslashit(bp_get_group_permalink($group) . 'admin/group-avatar');
        ?>
"><?php 
        _e('Avatar', 'buddypress');
        ?>
</a></li>

	<?php 
    }
    ?>

	<li<?php 
    if ('manage-members' == $current_tab) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_get_group_permalink($group) . 'admin/manage-members');
    ?>
"><?php 
    _e('Members', 'buddypress');
    ?>
</a></li>

	<?php 
    if ($groups_template->group->status == 'private') {
        ?>

		<li<?php 
        if ('membership-requests' == $current_tab) {
            ?>
 class="current"<?php 
        }
        ?>
><a href="<?php 
        echo trailingslashit(bp_get_group_permalink($group) . 'admin/membership-requests');
        ?>
"><?php 
        _e('Requests', 'buddypress');
        ?>
</a></li>

	<?php 
    }
    ?>

	<?php 
    do_action('groups_admin_tabs', $current_tab, $group->slug);
    ?>

	<li<?php 
    if ('delete-group' == $current_tab) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    echo trailingslashit(bp_get_group_permalink($group) . 'admin/delete-group');
    ?>
"><?php 
    _e('Delete', 'buddypress');
    ?>
</a></li>

<?php 
}
function bp_link_is_mod()
{
    return true === bp_is_item_mod() || true === bp_links_is_mod();
}
 /**
  * Setup BuddyBar navigation
  *
  * @global BuddyPress $bp The one true BuddyPress instance
  */
 function setup_nav()
 {
     // Define local variables
     $sub_nav = array();
     // Add 'Groups' to the main navigation
     $main_nav = array('name' => sprintf(__('Groups <span>%d</span>', 'buddypress'), groups_total_groups_for_user()), 'slug' => $this->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $this->id);
     $groups_link = trailingslashit(bp_loggedin_user_domain() . $this->slug);
     // Add the My Groups nav item
     $sub_nav[] = array('name' => __('Memberships', 'buddypress'), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups');
     // Add the Group Invites nav item
     $sub_nav[] = array('name' => __('Invitations', 'buddypress'), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_group_invites', 'user_has_access' => bp_is_my_profile(), 'position' => 30);
     parent::setup_nav($main_nav, $sub_nav);
     if (bp_is_groups_component() && bp_is_single_item()) {
         // Reset sub nav
         $sub_nav = array();
         // Add 'Groups' to the main navigation
         $main_nav = array('name' => __('Memberships', 'buddypress'), 'slug' => $this->current_group->slug, 'position' => -1, 'screen_function' => 'groups_screen_group_home', 'default_subnav_slug' => $this->default_extension, 'item_css_id' => $this->id);
         $group_link = bp_get_group_permalink($this->current_group);
         // Add the "Home" subnav item, as this will always be present
         $sub_nav[] = array('name' => _x('Home', 'Group home navigation title', 'buddypress'), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home');
         // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
         if (is_user_logged_in() && !bp_current_user_can('bp_moderate') && !$this->current_group->is_user_member && !groups_check_for_membership_request(bp_loggedin_user_id(), $this->current_group->id) && $this->current_group->status == 'private') {
             $sub_nav[] = array('name' => __('Request Membership', 'buddypress'), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30);
         }
         // Forums are enabled and turned on
         if ($this->current_group->enable_forum && bp_is_active('forums')) {
             $sub_nav[] = array('name' => __('Forum', 'buddypress'), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'forums');
         }
         $sub_nav[] = array('name' => sprintf(__('Members <span>%s</span>', 'buddypress'), number_format($this->current_group->total_member_count)), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'members');
         if (bp_is_active('friends') && bp_groups_user_can_send_invites()) {
             $sub_nav[] = array('name' => __('Send Invites', 'buddypress'), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $this->current_group->user_has_access);
         }
         // If the user is a group mod or more, then show the group admin nav item
         if (bp_is_item_admin() || bp_is_item_mod()) {
             $sub_nav[] = array('name' => __('Admin', 'buddypress'), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 1000, 'user_has_access' => true, 'item_css_id' => 'admin');
         }
         parent::setup_nav($main_nav, $sub_nav);
     }
     if (isset($this->current_group->user_has_access)) {
         do_action('groups_setup_nav', $this->current_group->user_has_access);
     } else {
         do_action('groups_setup_nav');
     }
 }
function groups_screen_group_admin_edit_details()
{
    global $bp;
    if ('edit-details' == bp_get_group_current_admin_tab()) {
        if (bp_is_item_admin() || bp_is_item_mod()) {
            // If the edit form has been submitted, save the edited details
            if (isset($_POST['save'])) {
                // Check the nonce
                if (!check_admin_referer('groups_edit_group_details')) {
                    return false;
                }
                if (!groups_edit_base_group_details($_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], (int) $_POST['group-notify-members'])) {
                    bp_core_add_message(__('There was an error updating group details, please try again.', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Group details were successfully updated.', 'buddypress'));
                }
                do_action('groups_group_details_edited', $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/edit-details/');
            }
            do_action('groups_screen_group_admin_edit_details', $bp->groups->current_group->id);
            bp_core_load_template(apply_filters('groups_template_group_admin', 'groups/single/home'));
        }
    }
}
示例#8
0
        /**
         * Add topic row action HTML when viewing group forum admin
         *
         * @since bbPress (r3653)
         * @uses bp_is_item_admin()
         * @uses bbp_get_forum_id()
         */
        public function topic_row_actions()
        {
            // Only admins can take actions on forums
            if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) {
                ?>

		<div class="row-actions">

			<?php 
                echo 'Edit | View | Trash | Close | Stick (To Front) | Spam';
                ?>

		</div>

		<?php 
            }
        }
示例#9
0
文件: group.php 项目: hscale/webento
        /**
         * Output the forums for a group in the edit screens
         *
         * @since bbPress (r3653)
         * @uses bp_get_current_group_id()
         * @uses bbp_get_group_forum_ids()
         * @uses bbp_has_forums()
         * @uses bbp_get_template_part()
         */
        public function display_forums($offset = 0)
        {
            // Allow actions immediately before group forum output
            do_action('bbp_before_group_forum_display');
            // Load up bbPress once
            $bbp = bbpress();
            // Forum data
            $forum_slug = bp_action_variable($offset);
            $forum_ids = bbp_get_group_forum_ids(bp_get_current_group_id());
            $forum_args = array('post__in' => $forum_ids, 'post_parent' => null);
            // Unset global queries
            $bbp->forum_query = new stdClass();
            $bbp->topic_query = new stdClass();
            $bbp->reply_query = new stdClass();
            // Unset global ID's
            $bbp->current_forum_id = 0;
            $bbp->current_topic_id = 0;
            $bbp->current_reply_id = 0;
            $bbp->current_topic_tag_id = 0;
            // Reset the post data
            wp_reset_postdata();
            // Allow admins special views
            $post_status = array(bbp_get_closed_status_id(), bbp_get_public_status_id());
            if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) {
                $post_status = array_merge($post_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()));
            }
            ?>

		<div id="bbpress-forums">

			<?php 
            // Looking at the group forum root
            if (empty($forum_slug) || 'page' == $forum_slug) {
                // Query forums and show them if they exist
                if (!empty($forum_ids) && bbp_has_forums($forum_args)) {
                    // Only one forum found
                    if (1 == $bbp->forum_query->post_count) {
                        // Remove 'name' check for paginated requests
                        if ('page' == $forum_slug) {
                            $forum_args = array('post_type' => bbp_get_forum_post_type());
                        } else {
                            $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type());
                        }
                        // Get the forums
                        $forums = get_posts($forum_args);
                        bbp_the_forum();
                        // Forum exists
                        if (!empty($forums)) {
                            $forum = $forums[0];
                            // Suppress subforums for now
                            add_filter('bbp_get_forum_subforum_count', '__return_false');
                            // Set up forum data
                            bbpress()->current_forum_id = $forum->ID;
                            bbp_set_query_name('bbp_single_forum');
                            ?>

							<h3><?php 
                            bbp_forum_title();
                            ?>
</h3>

							<?php 
                            bbp_get_template_part('content', 'single-forum');
                            ?>

							<?php 
                            // Remove the subforum suppression filter
                            remove_filter('bbp_get_forum_subforum_count', '__return_false');
                            ?>

						<?php 
                        } else {
                            ?>

							<?php 
                            bbp_get_template_part('feedback', 'no-topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        }
                        // More than 1 forum found or group forum admin screen
                    } elseif (1 < $bbp->forum_query->post_count) {
                        ?>

						<h3><?php 
                        _e('Forums', 'bbpress');
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('loop', 'forums');
                        ?>

						<h3><?php 
                        _e('Topics', 'bbpress');
                        ?>
</h3>

						<?php 
                        if (bbp_has_topics(array('post_parent__in' => $forum_ids))) {
                            ?>

							<?php 
                            bbp_get_template_part('pagination', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('loop', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('pagination', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        } else {
                            ?>

							<?php 
                            bbp_get_template_part('feedback', 'no-topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        }
                        // No forums found
                    } else {
                        ?>

						<div id="message" class="info">
							<p><?php 
                        _e('This group does not currently have any forums.', 'bbpress');
                        ?>
</p>
						</div>

					<?php 
                    }
                    // No forums found
                } else {
                    ?>

					<div id="message" class="info">
						<p><?php 
                    _e('This group does not currently have any forums.', 'bbpress');
                    ?>
</p>
					</div>

				<?php 
                }
                // Single forum
            } elseif (bp_action_variable($offset) != $this->slug && bp_action_variable($offset) != $this->topic_slug && bp_action_variable($offset) != $this->reply_slug) {
                // Get forum data
                $forum_slug = bp_action_variable($offset);
                $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type());
                $forums = get_posts($forum_args);
                // Forum exists
                if (!empty($forums)) {
                    $forum = $forums[0];
                    // Set up forum data
                    $forum_id = bbpress()->current_forum_id = $forum->ID;
                    // Reset necessary forum_query attributes for forums loop to function
                    $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                    $bbp->forum_query->in_the_loop = true;
                    $bbp->forum_query->post = get_post($forum_id);
                    // Forum edit
                    if (bp_action_variable($offset + 1) == $bbp->edit_id) {
                        global $wp_query, $post;
                        $wp_query->bbp_is_edit = true;
                        $wp_query->bbp_is_forum_edit = true;
                        $post = $forum;
                        bbp_set_query_name('bbp_forum_form');
                        bbp_get_template_part('form', 'forum');
                    } else {
                        bbp_set_query_name('bbp_single_forum');
                        ?>

						<h3><?php 
                        bbp_forum_title();
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('content', 'single-forum');
                    }
                } else {
                    bbp_get_template_part('feedback', 'no-topics');
                    bbp_get_template_part('form', 'topic');
                }
                // Single topic
            } elseif (bp_action_variable($offset) == $this->topic_slug) {
                // Get topic data
                $topic_slug = bp_action_variable($offset + 1);
                $topic_args = array('name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status);
                $topics = get_posts($topic_args);
                // Topic exists
                if (!empty($topics)) {
                    $topic = $topics[0];
                    // Set up topic data
                    $topic_id = bbpress()->current_topic_id = $topic->ID;
                    $forum_id = bbp_get_topic_forum_id($topic_id);
                    // Reset necessary forum_query attributes for topics loop to function
                    $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                    $bbp->forum_query->in_the_loop = true;
                    $bbp->forum_query->post = get_post($forum_id);
                    // Reset necessary topic_query attributes for topics loop to function
                    $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
                    $bbp->topic_query->in_the_loop = true;
                    $bbp->topic_query->post = $topic;
                    // Topic edit
                    if (bp_action_variable($offset + 2) == $bbp->edit_id) {
                        global $wp_query, $post;
                        $wp_query->bbp_is_edit = true;
                        $wp_query->bbp_is_topic_edit = true;
                        $post = $topic;
                        // Merge
                        if (!empty($_GET['action']) && 'merge' == $_GET['action']) {
                            bbp_set_query_name('bbp_topic_merge');
                            bbp_get_template_part('form', 'topic-merge');
                            // Split
                        } elseif (!empty($_GET['action']) && 'split' == $_GET['action']) {
                            bbp_set_query_name('bbp_topic_split');
                            bbp_get_template_part('form', 'topic-split');
                            // Edit
                        } else {
                            bbp_set_query_name('bbp_topic_form');
                            bbp_get_template_part('form', 'topic');
                        }
                        // Single Topic
                    } else {
                        bbp_set_query_name('bbp_single_topic');
                        ?>

						<h3><?php 
                        bbp_topic_title();
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('content', 'single-topic');
                    }
                    // No Topics
                } else {
                    bbp_get_template_part('feedback', 'no-topics');
                    bbp_get_template_part('form', 'topic');
                }
                // Single reply
            } elseif (bp_action_variable($offset) == $this->reply_slug) {
                // Get reply data
                $reply_slug = bp_action_variable($offset + 1);
                $reply_args = array('name' => $reply_slug, 'post_type' => bbp_get_reply_post_type());
                $replies = get_posts($reply_args);
                if (empty($replies)) {
                    return;
                }
                // Get the first reply
                $reply = $replies[0];
                // Set up reply data
                $reply_id = bbpress()->current_reply_id = $reply->ID;
                $topic_id = bbp_get_reply_topic_id($reply_id);
                $forum_id = bbp_get_reply_forum_id($reply_id);
                // Reset necessary forum_query attributes for reply to function
                $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                $bbp->forum_query->in_the_loop = true;
                $bbp->forum_query->post = get_post($forum_id);
                // Reset necessary topic_query attributes for reply to function
                $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
                $bbp->topic_query->in_the_loop = true;
                $bbp->topic_query->post = get_post($topic_id);
                // Reset necessary reply_query attributes for reply to function
                $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
                $bbp->reply_query->in_the_loop = true;
                $bbp->reply_query->post = $reply;
                if (bp_action_variable($offset + 2) == $bbp->edit_id) {
                    global $wp_query, $post;
                    $wp_query->bbp_is_edit = true;
                    $wp_query->bbp_is_reply_edit = true;
                    $post = $reply;
                    bbp_set_query_name('bbp_reply_form');
                    bbp_get_template_part('form', 'reply');
                }
            }
            ?>

		</div>

		<?php 
            // Allow actions immediately after group forum output
            do_action('bbp_after_group_forum_display');
        }