/** * 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')); } } }
/** * 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 groups_screen_group_forum() { global $bp; if ( $bp->is_single_item && $bp->groups->current_group->user_has_access ) { /* Fetch the details we need */ $topic_slug = $bp->action_variables[1]; $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug ); $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); if ( $topic_slug && $topic_id ) { /* Posting a reply */ if ( !$bp->action_variables[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 && !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 ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $_GET['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 ( $_SERVER['QUERY_STRING'] ) $query_vars = '?' . $_SERVER['QUERY_STRING']; bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id ); } /* Sticky a topic */ else if ( 'stick' == $bp->action_variables[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' ) ); do_action( 'groups_stick_forum_topic', $topic_id ); bp_core_redirect( wp_get_referer() ); } /* Un-Sticky a topic */ else if ( 'unstick' == $bp->action_variables[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') ); do_action( 'groups_unstick_forum_topic', $topic_id ); bp_core_redirect( wp_get_referer() ); } /* Close a topic */ else if ( 'close' == $bp->action_variables[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') ); do_action( 'groups_close_forum_topic', $topic_id ); bp_core_redirect( wp_get_referer() ); } /* Open a topic */ else if ( 'open' == $bp->action_variables[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') ); do_action( 'groups_open_forum_topic', $topic_id ); bp_core_redirect( wp_get_referer() ); } /* Delete a topic */ else if ( 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[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' ); 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( wp_get_referer() ); } /* Editing a topic */ else if ( 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[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' ); if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'] ) ) 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( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' ); } bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) ); } /* Delete a post */ else if ( 'delete' == $bp->action_variables[2] && $post_id = $bp->action_variables[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' ); if ( !groups_delete_group_forum_post( $bp->action_variables[4], $topic_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() ); } /* Editing a post */ else if ( 'edit' == $bp->action_variables[2] && $post_id = $bp->action_variables[4] ) { /* Fetch the post */ $post = bp_forums_get_post( $bp->action_variables[4] ); /* 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' ); if ( !$post_id = groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id, $_GET['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' ) ); } /* Standard topic display */ else { bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) ); } } else { /* Posting a topic */ if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic') ) { /* Check the nonce */ check_admin_referer( 'bp_forums_new_topic' ); /* Auto join this user if they are not yet a member of this group */ if ( $bp->groups->auto_join && !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 ( !$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 . '/' ); } do_action( 'groups_screen_group_forum', $topic_id, $forum_id ); bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) ); } } }