/**
 * 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);
}
예제 #2
0
function bp_has_forum_topic_posts( $args = '' ) {
	global $topic_template, $bp;

	$defaults = array(
		'topic_id' => false,
		'per_page' => 15,
		'max'      => false,
		'order'    => 'ASC'
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
		$topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );

	if ( is_numeric( $topic_id ) ) {
		$topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order );

		// Current topic forum_id needs to match current_group forum_id
		if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) )
			return false;

	} else {
		return false;
	}

	return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
}
예제 #3
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'));
    }
}
예제 #4
0
/**
 * 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'));
        }
    }
}
예제 #5
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;
	}

	/**
	 * Filters whether or not there are topics to display.
	 *
	 * @since BuddyPress (1.1.0)
	 *
	 * @param bool                     $value          Whether or not there are topics.
	 * @param BP_Forums_Template_Topic $topic_template Topic template global to use when rendering.
	 */
	return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), $topic_template );
}
예제 #6
0
파일: bp.php 프로젝트: kubens/Snippets
 protected function _get_topic_id()
 {
     return bp_forums_get_topic_id_from_slug($this->params['bp_action_variables'][1]);
 }
예제 #7
0
파일: bp-groups.php 프로젝트: n-sane/zaroka
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' ) );
		}
	}
}
예제 #8
0
/**
 * @since 1.0.3
 * it is not used any more because qwe are linking to threaded view
 * Remove notification for group forum posts/new topic
 */
function ac_notifier_remove_notification_for_topic()
{
    global $bp;
    //is group & group forum active ?
    if (!(bp_is_active("groups") && bp_is_active("forums"))) {
        return;
    }
    //if either group or forum is not actuive do not do anything
    //check if we are on single topic screen, right?
    if (bp_is_group_forum_topic() && is_user_logged_in()) {
        $topic_id = bp_forums_get_topic_id_from_slug($bp->action_variables[1]);
        //get id from slug
        $topic = get_topic($topic_id);
        $group_id = $bp->groups->current_group->id;
        //find activity id for this topic
        $activity_id = bp_activity_get_activity_id(array('user_id' => $topic->poster_id, 'component' => $bp->groups->id, 'type' => "new_forum_topic", "item_id" => $group_id, 'secondary_item_id' => $topic_id));
        //remove notification for new topic comments: easy
        if (!empty($activity_id)) {
            bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $activity_id, $bp->ac_notifier->id, 'new_activity_comment_' . $activity_id);
        }
        $posts = ac_notifier_get_forum_post_ids($topic_id);
        if (!empty($posts)) {
            //find all activities for the post
            $activities = ac_notifier_get_activity_ids(array("item_id" => $group_id, "secondary_ids" => $posts, "component" => $bp->groups->id, "type" => "new_forum_post"));
            //pass the array
            foreach ((array) $activities as $ac_id) {
                bp_core_delete_notifications_by_item_id($bp->loggedin_user->id, $ac_id, $bp->ac_notifier->id, 'new_activity_comment_' . $ac_id);
            }
        }
    }
}
예제 #9
0
/**
 * Catches requests to our extra RSS feeds and sets up the parameters needed
 * to display the RSS feed.
 *
 * @since 1.0
 */
function bplf_catcher()
{
    global $bp, $wp_query, $this_bp_feed;
    // Individual member activity feeds
    if (bp_is_activity_component() && bp_displayed_user_id() && bp_action_variable(0) && bp_action_variable(0) == 'feed') {
        switch (bp_current_action()) {
            // Individual member comment feed
            // /members/username/activity/comments/feed
            case 'comments':
                if (!defined('BPLF_DISABLE_MEMBER_COMMENTS_FEED')) {
                    $this_bp_feed = 'member_comments';
                }
                break;
                // Individual member blog post feed
                // /members/username/activity/blogposts/feed
            // Individual member blog post feed
            // /members/username/activity/blogposts/feed
            case 'blogposts':
                if (!defined('BPLF_DISABLE_MEMBER_BLOG_POSTS_FEED')) {
                    $this_bp_feed = 'member_blog_posts';
                }
                break;
                // Individual member activity update feed
                // /members/username/activity/updates/feed
            // Individual member activity update feed
            // /members/username/activity/updates/feed
            case 'updates':
                if (!defined('BPLF_DISABLE_MEMBER_UPDATES_FEED')) {
                    $this_bp_feed = 'member_updates';
                }
                break;
                // Individual member friendship conection feed
                // /members/username/activity/friendships/feed
            // Individual member friendship conection feed
            // /members/username/activity/friendships/feed
            case 'friendships':
                if (!defined('BPLF_DISABLE_MEMBER_FRIENDSHIPS_FEED')) {
                    $this_bp_feed = 'friendships';
                }
                break;
                // Individual member new forum topic feed
                // /members/username/activity/forumtopics/feed
            // Individual member new forum topic feed
            // /members/username/activity/forumtopics/feed
            case 'forumtopics':
                if (!defined('BPLF_DISABLE_MEMBER_TOPICS_FEED')) {
                    $this_bp_feed = 'member_topics';
                }
                break;
                // Individual member forum reply feed
                // /members/username/activity/forumreplies/feed
            // Individual member forum reply feed
            // /members/username/activity/forumreplies/feed
            case 'forumreplies':
                if (!defined('BPLF_DISABLE_MEMBER_REPLIES_FEED')) {
                    $this_bp_feed = 'member_replies';
                }
                break;
                // Individual member forum activity feed
                // /members/username/activity/forums/feed
            // Individual member forum activity feed
            // /members/username/activity/forums/feed
            case 'forums':
                if (!defined('BPLF_DISABLE_MEMBER_FORUMS_FEED')) {
                    $this_bp_feed = 'member_forums';
                }
                break;
        }
    }
    // Group activity feeds
    if (bp_is_groups_component() && isset($bp->groups->current_group->id) && bp_action_variable(0) == 'feed') {
        switch (bp_current_action()) {
            // Group activity updates
            // /groups/groupname/updates/feed
            case 'updates':
                if (!defined('BPLF_DISABLE_GROUP_UPDATES_FEED')) {
                    $this_bp_feed = 'group_updates';
                }
                break;
                // New group forum topics
                // /groups/groupname/forumtopics/feed
            // New group forum topics
            // /groups/groupname/forumtopics/feed
            case 'forumtopics':
                if (!defined('BPLF_DISABLE_GROUP_TOPICS_FEED')) {
                    $this_bp_feed = 'group_topics';
                }
                break;
                // New group forum replies
                // /groups/groupname/forumreplies/feed
            // New group forum replies
            // /groups/groupname/forumreplies/feed
            case 'forumreplies':
                if (!defined('BPLF_DISABLE_GROUP_REPLIES_FEED')) {
                    $this_bp_feed = 'group_replies';
                }
                break;
                // Group forum activity
                // /groups/groupname/forums/feed
            // Group forum activity
            // /groups/groupname/forums/feed
            case 'forums':
                if (!defined('BPLF_DISABLE_GROUP_FORUMS_FEED')) {
                    $this_bp_feed = 'group_forums';
                }
                break;
                // Group membership activity
                // /groups/groupname/membership/feed
            // Group membership activity
            // /groups/groupname/membership/feed
            case 'membership':
                if (!defined('BPLF_DISABLE_GROUP_MEMBERSHIP_FEED')) {
                    $this_bp_feed = 'group_membership';
                }
                break;
        }
    }
    // Individual forum topic feeds
    // /groups/groupname/forum/topic/topicslug/feed
    if (bp_is_groups_component() && bp_current_action() == 'forum' && bp_action_variable(0) == 'topic' && bp_action_variable(1) && bp_action_variable(2) == 'feed') {
        global $bplf_topic, $bplf_topic_posts;
        if (!defined('BPLF_DISABLE_INDIVIDUAL_TOPIC_FEED')) {
            $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
            $bplf_topic = bp_forums_get_topic_details($topic_id);
            $topic_args = array('per_page' => 50, 'max' => 50, 'order' => 'ASC');
            $topic_args = apply_filters('bp_lotsa_feeds_topic_feed_args', $topic_args);
            extract($topic_args);
            $bplf_topic_posts = new BP_Forums_Template_Topic($topic_id, $per_page, $max, $order);
            $this_bp_feed = 'forum_topic';
        }
    }
    $this_bp_feed = apply_filters('bplf_which_feed', $this_bp_feed);
    if (!$this_bp_feed) {
        return false;
    }
    $wp_query->is_404 = false;
    status_header(200);
    include_once apply_filters('bplf_feed_template', dirname(__FILE__) . '/feed-template.php');
    die;
}
예제 #10
0
 private function get_forum_arr_pos()
 {
     global $bp, $forum_template;
     $topic_slug = $bp->action_variables[1];
     $topic_id = bp_forums_get_topic_id_from_slug($topic_slug);
     for ($i = 0; $i <= count($forum_template->topics); $i++) {
         if ($topic_id == $forum_template->topics[$i]->topic_id) {
             $array_pos = $i;
         }
     }
     return $array_pos;
 }