Example #1
0
/**
 * Return value of topic tags field
 *
 * @since 2.0.0 bbPress (r2976)
 *
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
 * @return string Value of topic tags field
 */
function bbp_get_form_topic_tags()
{
    // Default return value
    $topic_tags = '';
    // Get _POST data
    if ((bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request()) && isset($_POST['bbp_topic_tags'])) {
        $topic_tags = wp_unslash($_POST['bbp_topic_tags']);
        // Get edit data
    } elseif (bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit()) {
        // Determine the topic id based on the post type
        switch (get_post_type()) {
            // Post is a topic
            case bbp_get_topic_post_type():
                $topic_id = bbp_get_topic_id(get_the_ID());
                break;
                // Post is a reply
            // Post is a reply
            case bbp_get_reply_post_type():
                $topic_id = bbp_get_reply_topic_id(get_the_ID());
                break;
        }
        // Topic exists
        if (!empty($topic_id)) {
            // Topic is spammed so display pre-spam terms
            if (bbp_is_topic_spam($topic_id)) {
                // Get pre-spam terms
                $spam_terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true);
                $topic_tags = !empty($spam_terms) ? implode(', ', $spam_terms) : '';
                // Topic is not spam so get real terms
            } else {
                $topic_tags = bbp_get_topic_tag_names($topic_id);
            }
        }
    }
    return apply_filters('bbp_get_form_topic_tags', $topic_tags);
}
        do_action('bbp_theme_before_reply_form_tags');
        ?>

						<p>
							<label for="bbp_topic_tags"><?php 
        esc_html_e('Tags:', 'monsoon');
        ?>
</label><br />
							<input type="text" value="<?php 
        bbp_form_topic_tags();
        ?>
" tabindex="<?php 
        bbp_tab_index();
        ?>
" size="40" name="bbp_topic_tags" id="bbp_topic_tags" <?php 
        disabled(bbp_is_topic_spam());
        ?>
 />
						</p>

						<?php 
        do_action('bbp_theme_after_reply_form_tags');
        ?>

					<?php 
    }
    ?>

					<?php 
    if (bbp_is_subscriptions_active() && !bbp_is_anonymous() && (!bbp_is_reply_edit() || bbp_is_reply_edit() && !bbp_is_reply_anonymous())) {
        ?>
/**
 * Handles the front end reply submission
 *
 * @since bbPress (r2574)
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_add_error() To add an error message
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_anonymous() To check if an anonymous post is being made
 * @uses current_user_can() To check if the current user can publish replies
 * @uses bbp_get_current_user_id() To get the current user id
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user
 *                                                cookies
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses remove_filter() To remove kses filters if needed
 * @uses esc_attr() For sanitization
 * @uses bbp_check_for_flood() To check for flooding
 * @uses bbp_check_for_duplicate() To check for duplicates
 * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title
 * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wp_set_post_terms() To set the topic tags
 * @uses wp_insert_post() To insert the reply
 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
 *                    id, anonymous data, reply author, edit (false), and
 *                    the reply to id
 * @uses bbp_get_reply_url() To get the paginated url to the reply
 * @uses wp_safe_redirect() To redirect to the reply url
 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
 *                                              message
 */
function bbp_new_reply_handler($action = '')
{
    // Bail if action is not bbp-new-reply
    if ('bbp-new-reply' !== $action) {
        return;
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-new-reply')) {
        bbp_add_error('bbp_new_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Define local variable(s)
    $topic_id = $forum_id = $reply_author = $anonymous_data = $reply_to = 0;
    $reply_title = $reply_content = $terms = '';
    /** Reply Author **********************************************************/
    // User is anonymous
    if (bbp_is_anonymous()) {
        // Filter anonymous data
        $anonymous_data = bbp_filter_anonymous_post_data();
        // Anonymous data checks out, so set cookies, etc...
        if (!empty($anonymous_data) && is_array($anonymous_data)) {
            bbp_set_current_anonymous_user_data($anonymous_data);
        }
        // User is logged in
    } else {
        // User cannot create replies
        if (!current_user_can('publish_replies')) {
            bbp_add_error('bbp_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress'));
        }
        // Reply author is current user
        $reply_author = bbp_get_current_user_id();
    }
    /** Topic ID **************************************************************/
    // Topic id was not passed
    if (empty($_POST['bbp_topic_id'])) {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID is missing.', 'bbpress'));
        // Topic id is not a number
    } elseif (!is_numeric($_POST['bbp_topic_id'])) {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID must be a number.', 'bbpress'));
        // Topic id might be valid
    } else {
        // Get the topic id
        $posted_topic_id = intval($_POST['bbp_topic_id']);
        // Topic id is a negative number
        if (0 > $posted_topic_id) {
            bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID cannot be a negative number.', 'bbpress'));
            // Topic does not exist
        } elseif (!bbp_get_topic($posted_topic_id)) {
            bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic does not exist.', 'bbpress'));
            // Use the POST'ed topic id
        } else {
            $topic_id = $posted_topic_id;
        }
    }
    /** Forum ID **************************************************************/
    // Try to use the forum id of the topic
    if (!isset($_POST['bbp_forum_id']) && !empty($topic_id)) {
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // Error check the POST'ed forum id
    } elseif (isset($_POST['bbp_forum_id'])) {
        // Empty Forum id was passed
        if (empty($_POST['bbp_forum_id'])) {
            bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
            // Forum id is not a number
        } elseif (!is_numeric($_POST['bbp_forum_id'])) {
            bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID must be a number.', 'bbpress'));
            // Forum id might be valid
        } else {
            // Get the forum id
            $posted_forum_id = intval($_POST['bbp_forum_id']);
            // Forum id is empty
            if (0 === $posted_forum_id) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
                // Forum id is a negative number
            } elseif (0 > $posted_forum_id) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum ID cannot be a negative number.', 'bbpress'));
                // Forum does not exist
            } elseif (!bbp_get_forum($posted_forum_id)) {
                bbp_add_error('bbp_topic_forum_id', __('<strong>ERROR</strong>: Forum does not exist.', 'bbpress'));
                // Use the POST'ed forum id
            } else {
                $forum_id = $posted_forum_id;
            }
        }
    }
    // Forum exists
    if (!empty($forum_id)) {
        // Forum is a category
        if (bbp_is_forum_category($forum_id)) {
            bbp_add_error('bbp_new_reply_forum_category', __('<strong>ERROR</strong>: This forum is a category. No replies can be created in this forum.', 'bbpress'));
            // Forum is not a category
        } else {
            // Forum is closed and user cannot access
            if (bbp_is_forum_closed($forum_id) && !current_user_can('edit_forum', $forum_id)) {
                bbp_add_error('bbp_new_reply_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress'));
            }
            // Forum is private and user cannot access
            if (bbp_is_forum_private($forum_id)) {
                if (!current_user_can('read_private_forums')) {
                    bbp_add_error('bbp_new_reply_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress'));
                }
                // Forum is hidden and user cannot access
            } elseif (bbp_is_forum_hidden($forum_id)) {
                if (!current_user_can('read_hidden_forums')) {
                    bbp_add_error('bbp_new_reply_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress'));
                }
            }
        }
    }
    /** Unfiltered HTML *******************************************************/
    // Remove kses filters from title and content for capable users and if the nonce is verified
    if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $topic_id) === $_POST['_bbp_unfiltered_html_reply']) {
        remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
        remove_filter('bbp_new_reply_pre_content', 'bbp_encode_bad', 10);
        remove_filter('bbp_new_reply_pre_content', 'bbp_filter_kses', 30);
    }
    /** Reply Title ***********************************************************/
    if (!empty($_POST['bbp_reply_title'])) {
        $reply_title = esc_attr(strip_tags($_POST['bbp_reply_title']));
    }
    // Filter and sanitize
    $reply_title = apply_filters('bbp_new_reply_pre_title', $reply_title);
    /** Reply Content *********************************************************/
    if (!empty($_POST['bbp_reply_content'])) {
        $reply_content = $_POST['bbp_reply_content'];
    }
    // Filter and sanitize
    $reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content);
    // No reply content
    if (empty($reply_content)) {
        bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress'));
    }
    /** Reply Flooding ********************************************************/
    if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
        bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
    }
    /** Reply Duplicate *******************************************************/
    if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
        bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress'));
    }
    /** Reply Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress'));
    }
    /** Reply Status **********************************************************/
    // Maybe put into moderation
    if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        $reply_status = bbp_get_pending_status_id();
        // Default
    } else {
        $reply_status = bbp_get_public_status_id();
    }
    /** Reply To **************************************************************/
    // Handle Reply To of the reply; $_REQUEST for non-JS submissions
    if (isset($_REQUEST['bbp_reply_to'])) {
        $reply_to = bbp_validate_reply_to($_REQUEST['bbp_reply_to']);
    }
    /** Topic Closed **********************************************************/
    // If topic is closed, moderators can still reply
    if (bbp_is_topic_closed($topic_id) && !current_user_can('moderate')) {
        bbp_add_error('bbp_reply_topic_closed', __('<strong>ERROR</strong>: Topic is closed.', 'bbpress'));
    }
    /** Topic Tags ************************************************************/
    // Either replace terms
    if (bbp_allow_topic_tags() && current_user_can('assign_topic_tags') && !empty($_POST['bbp_topic_tags'])) {
        $terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
        // ...or remove them.
    } elseif (isset($_POST['bbp_topic_tags'])) {
        $terms = '';
        // Existing terms
    } else {
        $terms = bbp_get_topic_tag_names($topic_id);
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $reply_data as an array
    // Just in time manipulation of reply data before being created
    $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1));
    // Insert reply
    $reply_id = wp_insert_post($reply_data);
    /** No Errors *************************************************************/
    // Check for missing reply_id or error
    if (!empty($reply_id) && !is_wp_error($reply_id)) {
        /** Topic Tags ********************************************************/
        // Just in time manipulation of reply terms before being edited
        $terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
        // Insert terms
        $terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
        // Term error
        if (is_wp_error($terms)) {
            bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
        }
        /** Trash Check *******************************************************/
        // If this reply starts as trash, add it to pre_trashed_replies
        // for the topic, so it is properly restored.
        if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] === bbp_get_trash_status_id()) {
            // Trash the reply
            wp_trash_post($reply_id);
            // Only add to pre-trashed array if topic is trashed
            if (bbp_is_topic_trash($topic_id)) {
                // Get pre_trashed_replies for topic
                $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
                // Add this reply to the end of the existing replies
                $pre_trashed_replies[] = $reply_id;
                // Update the pre_trashed_reply post meta
                update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
            }
            /** Spam Check ********************************************************/
            // If reply or topic are spam, officially spam this reply
        } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] === bbp_get_spam_status_id()) {
            add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
            // Only add to pre-spammed array if topic is spam
            if (bbp_is_topic_spam($topic_id)) {
                // Get pre_spammed_replies for topic
                $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
                // Add this reply to the end of the existing replies
                $pre_spammed_replies[] = $reply_id;
                // Update the pre_spammed_replies post meta
                update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies);
            }
        }
        /** Update counts, etc... *********************************************/
        do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to);
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_new_reply_post_extras', $reply_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = bbp_get_redirect_to();
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Allow to be filtered
        $reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
        /** Successful Save ***************************************************/
        // Redirect back to new reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        /** Errors ****************************************************************/
    } else {
        $append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
    }
}
Example #4
0
/**
 * Handles the front end opening/closing, spamming/unspamming,
 * sticking/unsticking and trashing/untrashing/deleting of topics
 *
 * @since bbPress (r2727)
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_get_topic() To get the topic
 * @uses current_user_can() To check if the user is capable of editing or
 *                           deleting the topic
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses check_ajax_referer() To verify the nonce and check the referer
 * @uses bbp_is_topic_open() To check if the topic is open
 * @uses bbp_close_topic() To close the topic
 * @uses bbp_open_topic() To open the topic
 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
 * @uses bbp_unstick_topic() To unstick the topic
 * @uses bbp_stick_topic() To stick the topic
 * @uses bbp_is_topic_spam() To check if the topic is marked as spam
 * @uses bbp_spam_topic() To make the topic as spam
 * @uses bbp_unspam_topic() To unmark the topic as spam
 * @uses wp_trash_post() To trash the topic
 * @uses wp_untrash_post() To untrash the topic
 * @uses wp_delete_post() To delete the topic
 * @uses do_action() Calls 'bbp_toggle_topic_handler' with success, post data
 *                    and action
 * @uses bbp_get_forum_permalink() To get the forum link
 * @uses bbp_get_topic_permalink() To get the topic link
 * @uses wp_safe_redirect() To redirect to the topic
 * @uses bbPress::errors:add() To log the error messages
 */
function bbp_toggle_topic_handler($action = '')
{
    // Bail if required GET actions aren't passed
    if (empty($_GET['topic_id'])) {
        return;
    }
    // Setup possible get actions
    $possible_actions = array('bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_trash');
    // Bail if actions aren't meant for this function
    if (!in_array($action, $possible_actions)) {
        return;
    }
    $failure = '';
    // Empty failure string
    $view_all = false;
    // Assume not viewing all
    $topic_id = (int) $_GET['topic_id'];
    // What's the topic id?
    $success = false;
    // Flag
    $post_data = array('ID' => $topic_id);
    // Prelim array
    $redirect = '';
    // Empty redirect URL
    // Make sure topic exists
    $topic = bbp_get_topic($topic_id);
    if (empty($topic)) {
        return;
    }
    // What is the user doing here?
    if (!current_user_can('edit_topic', $topic->ID) || 'bbp_toggle_topic_trash' === $action && !current_user_can('delete_topic', $topic->ID)) {
        bbp_add_error('bbp_toggle_topic_permission', __('<strong>ERROR:</strong> You do not have the permission to do that.', 'bbpress'));
        return;
    }
    // What action are we trying to perform?
    switch ($action) {
        // Toggle open/close
        case 'bbp_toggle_topic_close':
            check_ajax_referer('close-topic_' . $topic_id);
            $is_open = bbp_is_topic_open($topic_id);
            $success = true === $is_open ? bbp_close_topic($topic_id) : bbp_open_topic($topic_id);
            $failure = true === $is_open ? __('<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress');
            break;
            // Toggle sticky/super-sticky/unstick
        // Toggle sticky/super-sticky/unstick
        case 'bbp_toggle_topic_stick':
            check_ajax_referer('stick-topic_' . $topic_id);
            $is_sticky = bbp_is_topic_sticky($topic_id);
            $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false;
            $success = true === $is_sticky ? bbp_unstick_topic($topic_id) : bbp_stick_topic($topic_id, $is_super);
            $failure = true === $is_sticky ? __('<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress');
            break;
            // Toggle spam
        // Toggle spam
        case 'bbp_toggle_topic_spam':
            check_ajax_referer('spam-topic_' . $topic_id);
            $is_spam = bbp_is_topic_spam($topic_id);
            $success = true === $is_spam ? bbp_unspam_topic($topic_id) : bbp_spam_topic($topic_id);
            $failure = true === $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress');
            $view_all = !$is_spam;
            break;
            // Toggle trash
        // Toggle trash
        case 'bbp_toggle_topic_trash':
            $sub_action = !empty($_GET['sub_action']) && in_array($_GET['sub_action'], array('trash', 'untrash', 'delete')) ? $_GET['sub_action'] : false;
            if (empty($sub_action)) {
                break;
            }
            switch ($sub_action) {
                case 'trash':
                    check_ajax_referer('trash-' . bbp_get_topic_post_type() . '_' . $topic_id);
                    $view_all = true;
                    $success = wp_trash_post($topic_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress');
                    break;
                case 'untrash':
                    check_ajax_referer('untrash-' . bbp_get_topic_post_type() . '_' . $topic_id);
                    $success = wp_untrash_post($topic_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress');
                    break;
                case 'delete':
                    check_ajax_referer('delete-' . bbp_get_topic_post_type() . '_' . $topic_id);
                    $success = wp_delete_post($topic_id);
                    $failure = __('<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress');
                    break;
            }
            break;
    }
    // Do additional topic toggle actions
    do_action('bbp_toggle_topic_handler', $success, $post_data, $action);
    // No errors
    if (false !== $success && !is_wp_error($success)) {
        // Redirect back to the topic's forum
        if (isset($sub_action) && 'delete' === $sub_action) {
            $redirect = bbp_get_forum_permalink($success->post_parent);
            // Redirect back to the topic
        } else {
            // Get the redirect detination
            $permalink = bbp_get_topic_permalink($topic_id);
            $redirect = bbp_add_view_all($permalink, $view_all);
        }
        wp_safe_redirect($redirect);
        // For good measure
        exit;
        // Handle errors
    } else {
        bbp_add_error('bbp_toggle_topic', $failure);
    }
}
Example #5
0
 /**
  * Topic Row actions
  *
  * Remove the quick-edit action link under the topic title and add the
  * content and close/stick/spam links
  *
  * @since 2.0.0 bbPress (r2485)
  *
  * @param array $actions Actions
  * @param array $topic Topic object
  * @uses bbp_get_topic_post_type() To get the topic post type
  * @uses bbp_topic_content() To output topic content
  * @uses bbp_get_topic_permalink() To get the topic link
  * @uses bbp_get_topic_title() To get the topic title
  * @uses current_user_can() To check if the current user can edit or
  *                           delete the topic
  * @uses bbp_is_topic_open() To check if the topic is open
  * @uses bbp_is_topic_spam() To check if the topic is marked as spam
  * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a
  *                              super sticky
  * @uses get_post_type_object() To get the topic post type object
  * @uses add_query_arg() To add custom args to the url
  * @uses remove_query_arg() To remove custom args from the url
  * @uses wp_nonce_url() To nonce the url
  * @uses get_delete_post_link() To get the delete post link of the topic
  * @return array $actions Actions
  */
 public function row_actions($actions, $topic)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Show view link if it's not set, the topic is trashed and the user can view trashed topics
     if (empty($actions['view']) && bbp_get_trash_status_id() === $topic->post_status && current_user_can('view_trash')) {
         $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
     }
     // Only show the actions if the user is capable of viewing them :)
     if (current_user_can('moderate', $topic->ID)) {
         // Pending
         // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only
         $approve_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_approve'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'approve-topic_' . $topic->ID);
         if (bbp_is_topic_published($topic->ID)) {
             $actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this topic', 'bbpress') . '">' . _x('Unapprove', 'Unapprove Topic', 'bbpress') . '</a>';
         } elseif (!bbp_is_topic_private($topic->ID)) {
             $actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this topic', 'bbpress') . '">' . _x('Approve', 'Approve Topic', 'bbpress') . '</a>';
             $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
         }
         // Close
         // Show the 'close' and 'open' link on published and closed posts only
         if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) {
             $close_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'close-topic_' . $topic->ID);
             if (bbp_is_topic_open($topic->ID)) {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this topic', 'bbpress') . '">' . _x('Close', 'Close a Topic', 'bbpress') . '</a>';
             } else {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this topic', 'bbpress') . '">' . _x('Open', 'Open a Topic', 'bbpress') . '</a>';
             }
         }
         // Sticky
         // Dont show sticky if topic links is spam, trash or pending
         if (!bbp_is_topic_spam($topic->ID) && !bbp_is_topic_trash($topic->ID) && !bbp_is_topic_pending($topic->ID)) {
             $stick_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID);
             if (bbp_is_topic_sticky($topic->ID)) {
                 $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Unstick this topic', 'bbpress') . '">' . esc_html__('Unstick', 'bbpress') . '</a>';
             } else {
                 $super_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID);
                 $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Stick this topic to its forum', 'bbpress') . '">' . esc_html__('Stick', 'bbpress') . '</a> <a href="' . esc_url($super_uri) . '" title="' . esc_attr__('Stick this topic to front', 'bbpress') . '">' . esc_html__('(to front)', 'bbpress') . '</a>';
             }
         }
         // Spam
         $spam_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'spam-topic_' . $topic->ID);
         if (bbp_is_topic_spam($topic->ID)) {
             $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the topic as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>';
         } else {
             $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this topic as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>';
         }
     }
     // Do not show trash links for spam topics, or spam links for trashed topics
     if (current_user_can('delete_topic', $topic->ID)) {
         if (bbp_get_trash_status_id() === $topic->post_status) {
             $post_type_object = get_post_type_object(bbp_get_topic_post_type());
             $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . wp_nonce_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $topic->ID))), 'untrash-' . $topic->post_type . '_' . $topic->ID) . "'>" . esc_html__('Restore', 'bbpress') . "</a>";
         } elseif (EMPTY_TRASH_DAYS) {
             $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__('Move this item to the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>";
         }
         if (bbp_get_trash_status_id() === $topic->post_status || !EMPTY_TRASH_DAYS) {
             $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__('Delete this item permanently', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>";
         } elseif (bbp_get_spam_status_id() === $topic->post_status) {
             unset($actions['trash']);
         }
     }
     return $actions;
 }
/**
 * Return value of topic tags field
 *
 * @since bbPress (r2976)
 *
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags
 * @return string Value of topic tags field
 */
function bbp_get_form_topic_tags()
{
    // Get _POST data
    if (bbp_is_post_request() && isset($_POST['bbp_topic_tags'])) {
        $topic_tags = $_POST['bbp_topic_tags'];
        // Get edit data
    } elseif (bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit()) {
        // Determine the topic id based on the post type
        switch (get_post_type()) {
            // Post is a topic
            case bbp_get_topic_post_type():
                $topic_id = get_the_ID();
                break;
                // Post is a reply
            // Post is a reply
            case bbp_get_reply_post_type():
                $topic_id = bbp_get_reply_topic_id(get_the_ID());
                break;
        }
        // Topic exists
        if (!empty($topic_id)) {
            // Topic is spammed so display pre-spam terms
            if (bbp_is_topic_spam($topic_id)) {
                // Get pre-spam terms
                $new_terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true);
                // If terms exist, explode them and compile the return value
                if (empty($new_terms)) {
                    $new_terms = '';
                }
                // Topic is not spam so get real terms
            } else {
                $terms = array_filter((array) get_the_terms($topic_id, bbp_get_topic_tag_tax_id()));
                // Loop through them
                foreach ($terms as $term) {
                    $new_terms[] = $term->name;
                }
            }
            // Define local variable(s)
        } else {
            $new_terms = '';
        }
        // Set the return value
        $topic_tags = !empty($new_terms) ? implode(', ', $new_terms) : '';
        // No data
    } else {
        $topic_tags = '';
    }
    return apply_filters('bbp_get_form_topic_tags', esc_attr($topic_tags));
}
Example #7
0
/**
 * Do the actual topic toggling
 *
 * This function is used by `bbp_toggle_topic_handler()` to do the actual heavy
 * lifting when it comes to toggling topic. It only really makes sense to call
 * within that context, so if you need to call this function directly, make sure
 * you're also doing what the handler does too.
 *
 * @since 2.6.0  bbPress (r6133)
 * @access private
 *
 * @param array $args
 */
function bbp_toggle_topic($args = array())
{
    // Parse the arguments
    $r = bbp_parse_args($args, array('id' => 0, 'action' => '', 'sub_action' => '', 'data' => array()));
    // Build the nonce suffix
    $nonce_suffix = bbp_get_topic_post_type() . '_' . (int) $r['id'];
    // Default return values
    $retval = array('status' => 0, 'message' => '', 'redirect_to' => bbp_get_topic_permalink($r['id'], bbp_get_redirect_to()), 'view_all' => false);
    // What action are we trying to perform?
    switch ($r['action']) {
        // Toggle approve/unapprove
        case 'bbp_toggle_topic_approve':
            check_ajax_referer("approve-{$nonce_suffix}");
            $is_pending = bbp_is_topic_pending($r['id']);
            $retval['view_all'] = !$is_pending;
            // Toggle
            $retval['status'] = true === $is_pending ? bbp_approve_topic($r['id']) : bbp_unapprove_topic($r['id']);
            // Feedback
            $retval['message'] = true === $is_pending ? __('<strong>ERROR</strong>: There was a problem approving the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem unapproving the topic.', 'bbpress');
            break;
            // Toggle open/close
        // Toggle open/close
        case 'bbp_toggle_topic_close':
            check_ajax_referer("close-{$nonce_suffix}");
            $is_open = bbp_is_topic_open($r['id']);
            // Toggle
            $retval['status'] = true === $is_open ? bbp_close_topic($r['id']) : bbp_open_topic($r['id']);
            // Feedback
            $retval['message'] = true === $is_open ? __('<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress');
            break;
            // Toggle sticky/super-sticky/unstick
        // Toggle sticky/super-sticky/unstick
        case 'bbp_toggle_topic_stick':
            check_ajax_referer("stick-{$nonce_suffix}");
            $is_sticky = bbp_is_topic_sticky($r['id']);
            $is_super = false === $is_sticky && !empty($_GET['super']) && "1" === $_GET['super'] ? true : false;
            // Toggle
            $retval['status'] = true === $is_sticky ? bbp_unstick_topic($r['id']) : bbp_stick_topic($r['id'], $is_super);
            // Feedback
            $retval['message'] = true === $is_sticky ? __('<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress');
            break;
            // Toggle spam
        // Toggle spam
        case 'bbp_toggle_topic_spam':
            check_ajax_referer("spam-{$nonce_suffix}");
            $is_spam = bbp_is_topic_spam($r['id']);
            $retval['view_all'] = !$is_spam;
            // Toggle
            $retval['status'] = true === $is_spam ? bbp_unspam_topic($r['id']) : bbp_spam_topic($r['id']);
            // Feedback
            $retval['message'] = true === $is_spam ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress') : __('<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress');
            break;
            // Toggle trash
        // Toggle trash
        case 'bbp_toggle_topic_trash':
            switch ($r['sub_action']) {
                case 'trash':
                    check_ajax_referer("trash-{$nonce_suffix}");
                    $retval['view_all'] = true;
                    $retval['status'] = wp_trash_post($r['id']);
                    $retval['message'] = __('<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress');
                    break;
                case 'untrash':
                    check_ajax_referer("untrash-{$nonce_suffix}");
                    $retval['status'] = wp_untrash_post($r['id']);
                    $retval['message'] = __('<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress');
                    break;
                case 'delete':
                    check_ajax_referer("delete-{$nonce_suffix}");
                    $retval['status'] = wp_delete_post($r['id']);
                    $retval['message'] = __('<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress');
                    break;
            }
            break;
    }
    // Maybe redirect back to the topic's forum
    if (isset($r['sub_action']) && 'delete' === $r['sub_action']) {
        $retval['redirect_to'] = bbp_get_forum_permalink($retval['status']->post_parent);
    }
    // Add view all if needed
    if (!empty($retval['view_all'])) {
        $retval['redirect_to'] = bbp_add_view_all($retval['redirect_to'], true);
    }
    // Filter & return
    return apply_filters('bbp_toggle_topic', $retval, $r, $args);
}
Example #8
0
					<?php if ( ! ( bbp_use_wp_editor() || current_user_can( 'unfiltered_html' ) ) ) : ?>

						<p class="form-allowed-tags">
							<label><?php _e( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:','bbpress' ); ?></label><br />
							<code><?php bbp_allowed_tags(); ?></code>
						</p>

					<?php endif; ?>
					
					<?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?>

						<?php do_action( 'bbp_theme_before_reply_form_tags' ); ?>

						<p>
							<label for="bbp_topic_tags"><?php _e( 'Tags:', 'bbpress' ); ?></label><br />
							<input type="text" value="<?php bbp_form_topic_tags(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_topic_tags" id="bbp_topic_tags" <?php disabled( bbp_is_topic_spam() ); ?> />
						</p>

						<?php do_action( 'bbp_theme_after_reply_form_tags' ); ?>

					<?php endif; ?>

					<?php if ( bbp_is_subscriptions_active() && !bbp_is_anonymous() && ( !bbp_is_reply_edit() || ( bbp_is_reply_edit() && !bbp_is_reply_anonymous() ) ) ) : ?>

						<?php do_action( 'bbp_theme_before_reply_form_subscription' ); ?>

						<p>

							<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe"<?php bbp_form_topic_subscribed(); ?> tabindex="<?php bbp_tab_index(); ?>" />

							<?php if ( bbp_is_reply_edit() && ( bbp_get_reply_author_id() !== bbp_get_current_user_id() ) ) : ?>
Example #9
0
/**
 * Handles the front end reply submission
 *
 * @since bbPress (r2574)
 *
 * @uses bbp_add_error() To add an error message
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_anonymous() To check if an anonymous post is being made
 * @uses current_user_can() To check if the current user can publish replies
 * @uses bbp_get_current_user_id() To get the current user id
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user
 *                                                cookies
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses remove_filter() To remove 'wp_filter_kses' filters if needed
 * @uses esc_attr() For sanitization
 * @uses bbp_check_for_flood() To check for flooding
 * @uses bbp_check_for_duplicate() To check for duplicates
 * @uses apply_filters() Calls 'bbp_new_reply_pre_title' with the title
 * @uses apply_filters() Calls 'bbp_new_reply_pre_content' with the content
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wp_set_post_terms() To set the topic tags
 * @uses wp_insert_post() To insert the reply
 * @uses do_action() Calls 'bbp_new_reply' with the reply id, topic id, forum
 *                    id, anonymous data and reply author
 * @uses bbp_get_reply_url() To get the paginated url to the reply
 * @uses wp_safe_redirect() To redirect to the reply url
 * @uses bbPress::errors::get_error_message() To get the {@link WP_Error} error
 *                                              message
 */
function bbp_new_reply_handler()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if action is not bbp-new-reply
    if (empty($_POST['action']) || 'bbp-new-reply' !== $_POST['action']) {
        return;
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-new-reply')) {
        bbp_add_error('bbp_rew_reply_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Define local variable(s)
    $topic_id = $forum_id = $reply_author = $anonymous_data = 0;
    $reply_title = $reply_content = $terms = '';
    /** Reply Author **********************************************************/
    // User is anonymous
    if (bbp_is_anonymous()) {
        // Filter anonymous data
        $anonymous_data = bbp_filter_anonymous_post_data();
        // Anonymous data checks out, so set cookies, etc...
        if (!empty($anonymous_data) && is_array($anonymous_data)) {
            bbp_set_current_anonymous_user_data($anonymous_data);
        }
        // User is logged in
    } else {
        // User cannot create replies
        if (!current_user_can('publish_replies')) {
            bbp_add_error('bbp_reply_permissions', __('<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress'));
        }
        // Reply author is current user
        $reply_author = bbp_get_current_user_id();
    }
    /** Topic ID **************************************************************/
    // Handle Topic ID to append reply to
    if (isset($_POST['bbp_topic_id'])) {
        $topic_id = (int) $_POST['bbp_topic_id'];
    } else {
        bbp_add_error('bbp_reply_topic_id', __('<strong>ERROR</strong>: Topic ID is missing.', 'bbpress'));
    }
    /** Forum ID **************************************************************/
    // Handle Forum ID to adjust counts of
    if (isset($_POST['bbp_forum_id'])) {
        $forum_id = (int) $_POST['bbp_forum_id'];
    } elseif (!empty($topic_id)) {
        $forum_id = bbp_get_topic_forum_id($topic_id);
    } else {
        bbp_add_error('bbp_reply_forum_id', __('<strong>ERROR</strong>: Forum ID is missing.', 'bbpress'));
    }
    /** Unfiltered HTML *******************************************************/
    // Remove wp_filter_kses filters from title and content for capable users and if the nonce is verified
    if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_reply']) && wp_create_nonce('bbp-unfiltered-html-reply_' . $topic_id) == $_POST['_bbp_unfiltered_html_reply']) {
        remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
        remove_filter('bbp_new_reply_pre_content', 'wp_filter_kses');
    }
    /** Reply Title ***********************************************************/
    if (!empty($_POST['bbp_reply_title'])) {
        $reply_title = esc_attr(strip_tags($_POST['bbp_reply_title']));
    }
    // Filter and sanitize
    $reply_title = apply_filters('bbp_new_reply_pre_title', $reply_title);
    // No reply title
    if (empty($reply_title)) {
        bbp_add_error('bbp_reply_title', __('<strong>ERROR</strong>: Your reply needs a title.', 'bbpress'));
    }
    /** Reply Content *********************************************************/
    if (!empty($_POST['bbp_reply_content'])) {
        $reply_content = $_POST['bbp_reply_content'];
    }
    // Filter and sanitize
    $reply_content = apply_filters('bbp_new_reply_pre_content', $reply_content);
    // No reply content
    if (empty($reply_content)) {
        bbp_add_error('bbp_reply_content', __('<strong>ERROR</strong>: Your reply cannot be empty.', 'bbpress'));
    }
    /** Reply Flooding ********************************************************/
    if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
        bbp_add_error('bbp_reply_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
    }
    /** Reply Duplicate *******************************************************/
    if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
        bbp_add_error('bbp_reply_duplicate', __('<strong>ERROR</strong>: Duplicate reply detected; it looks as though you&#8217;ve already said that!', 'bbpress'));
    }
    /** Reply Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        bbp_add_error('bbp_reply_blacklist', __('<strong>ERROR</strong>: Your reply cannot be created at this time.', 'bbpress'));
    }
    /** Reply Moderation ******************************************************/
    $post_status = bbp_get_public_status_id();
    if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
        $post_status = bbp_get_pending_status_id();
    }
    /** Topic Tags ************************************************************/
    if (!empty($_POST['bbp_topic_tags'])) {
        $terms = esc_attr(strip_tags($_POST['bbp_topic_tags']));
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $reply_data as an array
    // Just in time manipulation of reply data before being created
    $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'post_status' => $post_status, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => (int) (bbp_get_topic_reply_count($topic_id) + 1)));
    // Insert reply
    $reply_id = wp_insert_post($reply_data);
    /** No Errors *************************************************************/
    // Check for missing reply_id or error
    if (!empty($reply_id) && !is_wp_error($reply_id)) {
        /** Topic Tags ********************************************************/
        // Just in time manipulation of reply terms before being edited
        $terms = apply_filters('bbp_new_reply_pre_set_terms', $terms, $topic_id, $reply_id);
        // Insert terms
        $terms = wp_set_post_terms($topic_id, $terms, bbp_get_topic_tag_tax_id(), false);
        // Term error
        if (is_wp_error($terms)) {
            bbp_add_error('bbp_reply_tags', __('<strong>ERROR</strong>: There was a problem adding the tags to the topic.', 'bbpress'));
        }
        /** Trash Check *******************************************************/
        // If this reply starts as trash, add it to pre_trashed_replies
        // for the topic, so it is properly restored.
        if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) {
            // Trash the reply
            wp_trash_post($reply_id);
            // Get pre_trashed_replies for topic
            $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
            // Add this reply to the end of the existing replies
            $pre_trashed_replies[] = $reply_id;
            // Update the pre_trashed_reply post meta
            update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
        }
        /** Spam Check ********************************************************/
        // If reply or topic are spam, officially spam this reply
        if (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) {
            add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
        }
        /** Update counts, etc... *********************************************/
        do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author);
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_new_reply_post_extras', $reply_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
        // Get the reply URL
        $reply_url = bbp_get_reply_url($reply_id, $redirect_to);
        // Allow to be filtered
        $reply_url = apply_filters('bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id);
        /** Successful Save ***************************************************/
        // Redirect back to new reply
        wp_safe_redirect($reply_url);
        // For good measure
        exit;
        /** Errors ****************************************************************/
    } else {
        $append_error = is_wp_error($reply_id) && $reply_id->get_error_message() ? $reply_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_reply_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress'));
    }
}
 /**
  * Post by email handler.
  *
  * For bbPress, the logic in this method is the same as {@link bbp_new_reply_handler()}.
  * It's duplicated because bbPress doesn't utilize hooks for verifying replies.
  *
  * @param bool $retval True by default.
  * @param array $data {
  *     An array of arguments.
  *
  *     @type array $headers Email headers.
  *     @type string $content The email body content.
  *     @type string $subject The email subject line.
  *     @type int $user_id The user ID who sent the email.
  *     @type bool $is_html Whether the email content is HTML or not.
  *     @type int $i The email message number.
  * }
  * @param array $params Parsed paramaters from the email address querystring.
  *   See {@link BP_Reply_By_Email_Parser::get_parameters()}.
  * @return array|object Array of the parsed item on success. WP_Error object
  *  on failure.
  */
 public function post($retval, $data, $params)
 {
     /** SETUP DATA ***************************************************/
     // reset globals
     global $bp;
     if (empty($bp->rbe->temp)) {
         $bp->rbe = new stdClass();
         $bp->rbe->temp = new stdClass();
     }
     $i = $data['i'];
     $user_id = $data['user_id'];
     // get topic ID
     $topic_id = !empty($params[$this->secondary_item_id_param]) ? $params[$this->secondary_item_id_param] : false;
     // get reply post ID
     $reply_to = !empty($params[$this->reply_id_param]) ? $params[$this->reply_id_param] : 0;
     // current email is not a bbPress group reply
     if (empty($topic_id)) {
         // if current email is a bbPress new group topic, parse it
         if (!empty($params[$this->forum_id_param])) {
             $retval = $this->post_new_topic($data, $params);
         }
         return $retval;
     }
     /* current email is a bbPress group reply, let's proceed! */
     // let RBE know that we're in the process of rendering a bbP reply
     // BuddyPress group forum reply
     if (!empty($params[$this->item_id_param])) {
         bp_rbe_log('Message #' . $i . ': this is a bbPress group forum reply');
         // bbPress
     } else {
         bp_rbe_log('Message #' . $i . ': this is a bbPress forum reply');
     }
     // other variables
     $reply_author = $user_id;
     $anonymous_data = 0;
     /** GROUP PERMISSIONS ********************************************/
     // posting from a BP group
     if (!empty($params[$this->item_id_param])) {
         // set group ID and cache it in global for later use
         // $bp->rbe->temp->group_id gets passed to the set_group_id() method later on
         $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param];
         // get all group member data for the user in one swoop!
         $group_member_data = bp_rbe_get_group_member_info($reply_author, $group_id);
         // user is not a member of the group anymore
         if (empty($group_member_data)) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' );
             return new WP_Error('user_not_group_member', '', $data);
         }
         // user is banned from group
         if ((int) $group_member_data->is_banned == 1) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' );
             return new WP_Error('user_banned_from_group', '', $data);
         }
         // override groups_get_current_group() with our cached group ID
         add_filter('groups_get_current_group', array($this, 'set_group_id'));
         // make sure bbP doesn't send any emails as GES handles this
         add_filter('bbp_get_topic_subscribers', '__return_false');
         // temporarily add some GES filters here
         add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode');
         add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode');
         // bbPress-only forums
     } else {
         // Subscriptions - make sure the author stays subscribed to the thread
         // this is due to how bbp_update_reply() works
         $_POST['bbp_topic_subscription'] = 'bbp_subscribe';
     }
     /** REPLY PERMISSIONS ********************************************/
     // Allow member to pass default cap checks.
     // The reason why we keep the 'publish_replies' check below is b/c bbPress
     // plugins may disable cap access for a specific user if they have hooked into
     // the 'bbp_map_meta_caps' filter.
     add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4);
     // User cannot create replies
     if (!user_can($reply_author, 'publish_replies')) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_permissions' );
         return new WP_Error('bbp_reply_permissions', '', $data);
     }
     /** UNFILTERED HTML **********************************************/
     // Remove wp_filter_kses filters from title and content for capable users
     if (user_can($user_id, 'unfiltered_html')) {
         remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses');
         remove_filter('bbp_new_reply_pre_content', 'wp_filter_kses');
     }
     /** REPLY DATA ***************************************************/
     // setup a dummy reply title b/c bbP requires it
     $reply_title = sprintf(__('Reply To: Topic ID %d', 'bp-rbe'), $topic_id);
     // Filter and sanitize
     $reply_content = apply_filters('bbp_new_reply_pre_content', $data['content']);
     /** REPLY MODERATION *********************************************/
     // Reply Flooding
     if (!bbp_check_for_flood($anonymous_data, $reply_author)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_flood' );
         //bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
         return new WP_Error('bbp_reply_flood', '', $data);
     }
     // Reply Duplicate
     if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_duplicate' );
         return new WP_Error('bbp_reply_duplicate', '', $data);
     }
     // Reply Blacklist
     if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_blacklist' );
         return new WP_Error('bbp_reply_blacklist', '', $data);
     }
     // Reply Status
     // Maybe put into moderation
     if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) {
         $reply_status = bbp_get_pending_status_id();
         // Default
     } else {
         $reply_status = bbp_get_public_status_id();
     }
     /** POSTING TIME! ************************************************/
     // get forum ID
     $forum_id = bbp_get_topic_forum_id($topic_id);
     // bbP hook before save
     do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id);
     // Setup reply data
     $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1));
     // Insert reply
     $reply_id = wp_insert_post($reply_data);
     // Reply posted!
     if (!is_wp_error($reply_id)) {
         // more internal logging
         bp_rbe_log('Message #' . $i . ': bbPress reply successfully posted!');
         // Problem posting
     } else {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_error' );
         return new WP_Error('bbp_reply_error', '', $data);
     }
     /** AFTER POSTING ************************************************/
     // stuff that needs to happen after a bbP reply is posted occurs here... bbP
     // should preferably do the following at the 'bbp_new_reply' hook, until then
     // do what bbP does inline.
     // Trash Check ////////////////////////////////////////////////////
     // If this reply starts as trash, add it to pre_trashed_replies
     // for the topic, so it is properly restored.
     if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) {
         // Trash the reply
         wp_trash_post($reply_id);
         // Only add to pre-trashed array if topic is trashed
         if (bbp_is_topic_trash($topic_id)) {
             // Get pre_trashed_replies for topic
             $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true);
             // Add this reply to the end of the existing replies
             $pre_trashed_replies[] = $reply_id;
             // Update the pre_trashed_reply post meta
             update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
         }
         // Spam Check /////////////////////////////////////////////////////
         // If reply or topic are spam, officially spam this reply
     } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) {
         add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
         // Only add to pre-spammed array if topic is spam
         if (bbp_is_topic_spam($topic_id)) {
             // Get pre_spammed_replies for topic
             $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
             // Add this reply to the end of the existing replies
             $pre_spammed_replies[] = $reply_id;
             // Update the pre_spammed_replies post meta
             update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies);
         }
     }
     // Reply By Email /////////////////////////////////////////////////
     // Add a RBE marker to the post's meta
     // Could potentially show that post was made via email on the frontend
     add_post_meta($reply_id, 'bp_rbe', 1);
     /** POST HOOKS ***************************************************/
     // RBE Custom Hooks ///////////////////////////////////////////////
     // change activity action
     add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action'));
     // add RBE's special activity hook
     add_action('bp_activity_after_save', array($this, 'activity_rbe_hook'));
     // bbPress Reply Hooks ////////////////////////////////////////////
     do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to);
     do_action('bbp_new_reply_post_extras', $reply_id);
     return array('bbp_reply_id' => $reply_id);
 }
Example #11
0
 /**
  * Add a Spam row action
  * 
  * @param unknown_type $actions
  * @param unknown_type $post
  */
 function post_row_actions($actions, $post)
 {
     global $wpdb;
     $the_id = $post->ID;
     // For replies:
     if ($post->post_type == 'reply' && $post->post_status == 'pending' && !array_key_exists('spam', $actions)) {
         // Mark posts as spam
         $spam_uri = esc_url(wp_nonce_url(add_query_arg(array('reply_id' => $the_id, 'action' => 'bbp_toggle_reply_spam'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'spam-reply_' . $the_id));
         if (bbp_is_reply_spam($the_id)) {
             $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__('Mark the reply as not spam', 'bbpress') . '">' . __('Not spam', 'bbpress') . '</a>';
         } else {
             $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__('Mark this reply as spam', 'bbpress') . '">' . __('Spam', 'bbpress') . '</a>';
         }
     }
     // For Topics:
     if ($post->post_type == 'topic' && $post->post_status == 'pending' && !array_key_exists('spam', $actions)) {
         // Mark posts as spam
         $spam_uri = esc_url(wp_nonce_url(add_query_arg(array('topic_id' => $the_id, 'action' => 'bbp_toggle_topic_spam'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'spam-topic_' . $the_id));
         if (bbp_is_topic_spam($the_id)) {
             $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__('Mark the topic as not spam', 'bbpress') . '">' . __('Not spam', 'bbpress') . '</a>';
         } else {
             $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__('Mark this topic as spam', 'bbpress') . '">' . __('Spam', 'bbpress') . '</a>';
         }
     }
     return $actions;
 }