public function get_all_forums()
 {
     $bbp_f = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => 'any', 'post_status' => bbp_get_public_status_id(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'ignore_sticky_posts' => true, 'orderby' => 'menu_order title', 'order' => 'ASC'), 'has_forums');
     $bbp = bbpress();
     $bbp->forum_query = new WP_Query($bbp_f);
     $data = array();
     foreach ($bbp->forum_query->posts as $post) {
         $type = 'forum';
         $is_parent = false;
         $is_category = bbp_forum_get_subforums($post->ID);
         if ($is_category) {
             $type = 'category';
             $parent = true;
         }
         $settings = $this->wlm->GetOption('bbpsettings');
         if ($settings && count($settings) > 0) {
             foreach ($settings as $setting) {
                 if ($setting["id"] == $post->ID) {
                     $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => $setting["sku"], "protection" => $setting["protection"], "type" => $type, "parent" => $parent, "date" => "");
                 }
             }
             if (!isset($data[$post->ID])) {
                 $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => "");
             }
         } else {
             $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => "");
         }
     }
     echo json_encode($data);
     die;
 }
        function widget($args, $instance)
        {
            extract($args, EXTR_SKIP);
            $title = !empty($instance['title']) ? $instance['title'] : __('Recent Topics');
            $title = apply_filters('widget_title', $title, $instance, $this->id_base);
            $number = !empty($instance['number']) ? absint($instance['number']) : 5;
            $orderby = !empty($instance['number']) ? strip_tags($instance['order_by']) : 'newness';
            if ($orderby == 'newness') {
                $cb_meta_key = $cb_order_by = NULL;
            } elseif ($orderby == 'popular') {
                $cb_meta_key = '_bbp_reply_count';
                $cb_order_by = 'meta_value';
            } elseif ($orderby == 'freshness') {
                $cb_meta_key = '_bbp_last_active_time';
                $cb_order_by = 'meta_value';
            }
            if (!$number) {
                $number = 5;
            }
            $cb_qry = new WP_Query(array('post_type' => bbp_get_topic_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'order' => 'DESC', 'posts_per_page' => $number, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => $cb_meta_key, 'orderby' => $cb_order_by));
            echo $before_widget;
            echo $before_title . $title . $after_title;
            ?>
            <ul class="cb-bbp-recent-topics">

                <?php 
            while ($cb_qry->have_posts()) {
                $cb_qry->the_post();
                ?>

                    <li>

                        <?php 
                $cb_reply_id = bbp_get_reply_id($cb_qry->post->ID);
                $cb_reply_url = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($cb_reply_id)) . '" title="' . esc_attr(bbp_get_reply_excerpt($cb_reply_id, 50)) . '">' . bbp_get_reply_topic_title($cb_reply_id) . '</a>';
                $cb_number_replies = bbp_get_topic_reply_count($cb_reply_id);
                $cb_author_avatar = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'avatar', 'size' => 60));
                $cb_author_name = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'name'));
                echo $cb_author_avatar . '<div class="cb-bbp-meta">' . $cb_reply_url . '<div class="cb-bbp-byline">' . __('Started by', 'cubell') . ' ' . $cb_author_name . ' <i class="icon-long-arrow-right"></i> ' . $cb_number_replies . ' replies</div></div>';
                ?>

                    </li>

                <?php 
            }
            ?>

            </ul>

<?php 
            echo $after_widget;
            // Reset the $post global
            wp_reset_postdata();
        }
        function widget($args, $instance)
        {
            extract($args, EXTR_SKIP);
            $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments');
            $title = apply_filters('widget_title', $title, $instance, $this->id_base);
            $number = !empty($instance['number']) ? absint($instance['number']) : 5;
            if (!$number) {
                $number = 5;
            }
            $cb_qry = new WP_Query(array('post_type' => bbp_get_reply_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => $number, 'ignore_sticky_posts' => true, 'no_found_rows' => true));
            echo $before_widget;
            echo $before_title . $title . $after_title;
            ?>
            <ul class="cb-bbp-recent-replies">

                <?php 
            while ($cb_qry->have_posts()) {
                $cb_qry->the_post();
                ?>

                    <li>

                        <?php 
                $cb_reply_id = bbp_get_reply_id($cb_qry->post->ID);
                $cb_reply_url = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($cb_reply_id)) . '" title="' . esc_attr(bbp_get_reply_excerpt($cb_reply_id, 50)) . '">' . bbp_get_reply_topic_title($cb_reply_id) . '</a>';
                $cb_author_avatar = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'avatar', 'size' => 60));
                $cb_author_name = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'name'));
                echo $cb_author_avatar . '<div class="cb-bbp-meta">' . $cb_author_name . ' <i class="icon-long-arrow-right"></i> ' . $cb_reply_url . '<div class="cb-bbp-recent-replies-time">' . bbp_get_time_since(get_the_time('U')) . '</div></div>';
                ?>

                    </li>

                <?php 
            }
            ?>

            </ul>

        <?php 
            echo $after_widget;
            // Reset the $post global
            wp_reset_postdata();
        }
/**
 * This function filters the list of forums based on the users rank as set by the Mebmers plugin
 */
function tehnik_bpp_filter_forums_by_permissions($args = '')
{
    $bbp = bbpress();
    // Setup possible post__not_in array
    $post_stati[] = bbp_get_public_status_id();
    // Check if user can read private forums
    if (current_user_can('read_private_forums')) {
        $post_stati[] = bbp_get_private_status_id();
    }
    // Check if user can read hidden forums
    if (current_user_can('read_hidden_forums')) {
        $post_stati[] = bbp_get_hidden_status_id();
    }
    // The default forum query for most circumstances
    $meta_query = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id(), 'post_status' => implode(',', $post_stati), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC');
    //Get an array of IDs which the current user has permissions to view
    $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($meta_query));
    // The default forum query with allowed forum ids array added
    $meta_query['post__in'] = $allowed_forums;
    $bbp_f = bbp_parse_args($args, $meta_query, 'has_forums');
    // Run the query
    $bbp->forum_query = new WP_Query($bbp_f);
    return apply_filters('bpp_filter_forums_by_permissions', $bbp->forum_query->have_posts(), $bbp->forum_query);
}
示例#5
0
/**
 * Recaches the last post in every topic and forum
 *
 * @since 2.0.0 bbPress (r3040)
 *
 * @uses wpdb::query() To run our recount sql queries
 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_is_forum_category() To check if the forum is a ategory
 * @uses bbp_update_forum() To update the forums forum id
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_freshness()
{
    // Define variables
    $bbp_db = bbp_db();
    $statement = __('Recomputing latest post in every topic and forum&hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    // First, delete everything.
    if (is_wp_error($bbp_db->query("DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );"))) {
        return array(1, sprintf($statement, $result));
    }
    // Post types and status
    $fpt = bbp_get_forum_post_type();
    $tpt = bbp_get_topic_post_type();
    $rpt = bbp_get_reply_post_type();
    $pps = bbp_get_public_status_id();
    // Next, give all the topics with replies the ID their last reply.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) {
        return array(2, sprintf($statement, $result));
    }
    // For any remaining topics, give a reply ID of 0.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_reply_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) {
        return array(3, sprintf($statement, $result));
    }
    // Now we give all the forums with topics the ID their last topic.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` INNER JOIN `{$bbp_db->posts}` AS `topic` ON `forum`.`ID` = `topic`.`post_parent`\n\t\t\tWHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}'\n\t\t\tGROUP BY `forum`.`ID` );"))) {
        return array(4, sprintf($statement, $result));
    }
    // For any remaining forums, give a topic ID of 0.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_topic_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` LEFT JOIN `{$bbp_db->postmeta}` AS `topic`\n\t\t\tON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id'\n\t\t\tWHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );"))) {
        return array(5, sprintf($statement, $result));
    }
    // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason).
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) {
        return array(6, sprintf($statement, $result));
    }
    // For any remaining topics, give a reply ID of themself.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_id', `ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) {
        return array(7, sprintf($statement, $result));
    }
    // Give topics with replies their last update time.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) {
        return array(8, sprintf($statement, $result));
    }
    // Give topics without replies their last update time.
    if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_time', `post_date`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) {
        return array(9, sprintf($statement, $result));
    }
    // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database.
    $forums = $bbp_db->get_col("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';");
    if (is_wp_error($forums)) {
        return array(10, sprintf($statement, $result));
    }
    // Loop through forums
    foreach ($forums as $forum_id) {
        if (!bbp_is_forum_category($forum_id)) {
            bbp_update_forum(array('forum_id' => $forum_id));
        }
    }
    // Loop through categories when forums are done
    foreach ($forums as $forum_id) {
        if (bbp_is_forum_category($forum_id)) {
            bbp_update_forum(array('forum_id' => $forum_id));
        }
    }
    // Complete results
    return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
示例#6
0
/**
 * Called before trashing a topic
 *
 * This function is supplemental to the actual topic being trashed which is
 * handled by WordPress core API functions. It is used to clean up after
 * a topic that is being trashed.
 *
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_is_topic() To check if the passed id is a topic
 * @uses do_action() Calls 'bbp_trash_topic' with the topic id
 * @uses wp_trash_post() To trash the reply
 * @uses update_post_meta() To save a list of just trashed replies for future use
 */
function bbp_trash_topic($topic_id = 0)
{
    // Validate topic ID
    $topic_id = bbp_get_topic_id($topic_id);
    if (empty($topic_id) || !bbp_is_topic($topic_id)) {
        return false;
    }
    do_action('bbp_trash_topic', $topic_id);
    // Topic is being trashed, so its replies are trashed too
    $replies = new WP_Query(array('suppress_filters' => true, 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'post_parent' => $topic_id, 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent'));
    if (!empty($replies->posts)) {
        // Prevent debug notices
        $pre_trashed_replies = array();
        // Loop through replies, trash them, and add them to array
        foreach ($replies->posts as $reply) {
            wp_trash_post($reply->ID);
            $pre_trashed_replies[] = $reply->ID;
        }
        // Set a post_meta entry of the replies that were trashed by this action.
        // This is so we can possibly untrash them, without untrashing replies
        // that were purposefully trashed before.
        update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies);
        // Reset the $post global
        wp_reset_postdata();
    }
    // Cleanup
    unset($replies);
}
示例#7
0
/**
 * Trash all topics inside a forum
 *
 * @since bbPress (r3668)
 *
 * @param int $forum_id
 * @uses bbp_get_forum_id() To validate the forum ID
 * @uses bbp_is_forum() To make sure it's a forum
 * @uses bbp_get_public_status_id() To return public post status
 * @uses bbp_get_closed_status_id() To return closed post status
 * @uses bbp_get_pending_status_id() To return pending post status
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses wp_trash_post() To trash the post
 * @uses update_post_meta() To update the forum meta of trashed topics
 * @return If forum is not valid
 */
function bbp_trash_forum_topics($forum_id = 0)
{
    // Validate forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    if (empty($forum_id)) {
        return;
    }
    // Allowed post statuses to pre-trash
    $post_stati = implode(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_pending_status_id()));
    // Forum is being trashed, so its topics and replies are trashed too
    $topics = new WP_Query(array('suppress_filters' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $forum_id, 'post_status' => $post_stati, 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent'));
    // Loop through and trash child topics. Topic replies will get trashed by
    // the bbp_trash_topic() action.
    if (!empty($topics->posts)) {
        // Prevent debug notices
        $pre_trashed_topics = array();
        // Loop through topics, trash them, and add them to array
        foreach ($topics->posts as $topic) {
            wp_trash_post($topic->ID, true);
            $pre_trashed_topics[] = $topic->ID;
        }
        // Set a post_meta entry of the topics that were trashed by this action.
        // This is so we can possibly untrash them, without untrashing topics
        // that were purposefully trashed before.
        update_post_meta($forum_id, '_bbp_pre_trashed_topics', $pre_trashed_topics);
        // Reset the $post global
        wp_reset_postdata();
    }
    // Cleanup
    unset($topics);
}
示例#8
0
/**
 * Is the reply not spam or deleted?
 *
 * @since bbPress (r3496)
 *
 * @param int $reply_id Optional. Topic id
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_status() To get the reply status
 * @return bool True if published, false if not.
 */
function bbp_is_reply_published($reply_id = 0)
{
    $reply_status = bbp_get_reply_status(bbp_get_reply_id($reply_id)) === bbp_get_public_status_id();
    return (bool) apply_filters('bbp_is_reply_published', (bool) $reply_status, $reply_id);
}
示例#9
0
/**
 * Reset main query vars and filter 'the_content' to output a bbPress
 * template part as needed.
 *
 * @since bbPress (r3032)
 * @param string $template
 * @uses bbp_is_single_user() To check if page is single user
 * @uses bbp_get_single_user_template() To get user template
 * @uses bbp_is_single_user_edit() To check if page is single user edit
 * @uses bbp_get_single_user_edit_template() To get user edit template
 * @uses bbp_is_single_view() To check if page is single view
 * @uses bbp_get_single_view_template() To get view template
 * @uses bbp_is_forum_edit() To check if page is forum edit
 * @uses bbp_get_forum_edit_template() To get forum edit template
 * @uses bbp_is_topic_merge() To check if page is topic merge
 * @uses bbp_get_topic_merge_template() To get topic merge template
 * @uses bbp_is_topic_split() To check if page is topic split
 * @uses bbp_get_topic_split_template() To get topic split template
 * @uses bbp_is_topic_edit() To check if page is topic edit
 * @uses bbp_get_topic_edit_template() To get topic edit template
 * @uses bbp_is_reply_edit() To check if page is reply edit
 * @uses bbp_get_reply_edit_template() To get reply edit template
 * @uses bbp_set_theme_compat_template() To set the global theme compat template
 */
function bbp_template_include_theme_compat($template = '')
{
    // Bail if the template already matches a bbPress template. This includes
    // archive-* and single-* WordPress post_type matches (allowing
    // themes to use the expected format) as well as all bbPress-specific
    // template files for users, topics, forums, etc...
    if (!empty(bbpress()->theme_compat->bbpress_template)) {
        return $template;
    }
    /** Users *************************************************************/
    if (bbp_is_single_user_edit() || bbp_is_single_user()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'post_status' => bbp_get_public_status_id(), 'is_archive' => false, 'comment_status' => 'closed'));
        /** Forums ************************************************************/
        // Forum archive
    } elseif (bbp_is_forum_archive()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Forum
    } elseif (bbp_is_forum_edit() || bbp_is_single_forum()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_forum_id()), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed'));
        /** Topics ************************************************************/
        // Topic archive
    } elseif (bbp_is_topic_archive()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed'));
        // Single Topic
    } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_topic_id()), 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed'));
        /** Replies ***********************************************************/
        // Reply archive
    } elseif (is_post_type_archive(bbp_get_reply_post_type())) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        // Single Reply
    } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_reply_id()), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed'));
        /** Views *************************************************************/
    } elseif (bbp_is_single_view()) {
        // Reset post
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
        /** Topic Tags ********************************************************/
        // Topic Tag Edit
    } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) {
        // Stash the current term in a new var
        set_query_var('bbp_topic_tag', get_query_var('term'));
        // Reset the post with our new title
        bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed'));
    }
    /**
     * If we are relying on bbPress's built in theme compatibility to load
     * the proper content, we need to intercept the_content, replace the
     * output, and display ours instead.
     *
     * To do this, we first remove all filters from 'the_content' and hook
     * our own function into it, which runs a series of checks to determine
     * the context, and then uses the built in shortcodes to output the
     * correct results from inside an output buffer.
     *
     * Uses bbp_get_theme_compat_templates() to provide fall-backs that
     * should be coded without superfluous mark-up and logic (prev/next
     * navigation, comments, date/time, etc...)
     * 
     * Hook into the 'bbp_get_bbpress_template' to override the array of
     * possible templates, or 'bbp_bbpress_template' to override the result.
     */
    if (bbp_is_theme_compat_active()) {
        // Remove all filters from the_content
        bbp_remove_all_filters('the_content');
        // Add a filter on the_content late, which we will later remove
        add_filter('the_content', 'bbp_replace_the_content');
        // Find the appropriate template file
        $template = bbp_get_theme_compat_templates();
    }
    return apply_filters('bbp_template_include_theme_compat', $template);
}
/**
 * Unspams a reply
 *
 * @since bbPress (r2740)
 *
 * @param int $reply_id Reply id
 * @uses bbp_get_reply() To get the reply
 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
 * @uses get_post_meta() To get the previous status meta
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To insert the updated post
 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
 * @return mixed False or {@link WP_Error} on failure, reply id on success
 */
function bbp_unspam_reply($reply_id = 0)
{
    // Get reply
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return $reply;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() !== $reply->post_status) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_reply', $reply_id);
    // Get pre spam status
    $reply->post_status = get_post_meta($reply_id, '_bbp_spam_meta_status', true);
    // If no previous status, default to publish
    if (empty($reply->post_status)) {
        $reply->post_status = bbp_get_public_status_id();
    }
    // Delete pre spam meta
    delete_post_meta($reply_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the reply
    $reply_id = wp_update_post($reply);
    // Execute post unspam code
    do_action('bbp_unspammed_reply', $reply_id);
    // Return reply_id
    return $reply_id;
}
示例#11
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;
 }
示例#12
0
    /**
     * Displays the output, the replies list
     *
     * @since bbPress (r2653)
     *
     * @param mixed $args
     * @param array $instance
     * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
     * @uses bbp_get_reply_author_link() To get the reply author link
     * @uses bbp_get_reply_id() To get the reply id
     * @uses bbp_get_reply_url() To get the reply url
     * @uses bbp_get_reply_excerpt() To get the reply excerpt
     * @uses bbp_get_reply_topic_title() To get the reply topic title
     * @uses get_the_date() To get the date of the reply
     * @uses get_the_time() To get the time of the reply
     */
    public function widget($args, $instance)
    {
        // Get widget settings
        $settings = $this->parse_settings($instance);
        // Typical WordPress filter
        $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base);
        // bbPress filter
        $settings['title'] = apply_filters('bbp_replies_widget_title', $settings['title'], $instance, $this->id_base);
        // Note: private and hidden forums will be excluded via the
        // bbp_pre_get_posts_normalize_forum_visibility action and function.
        $widget_query = new WP_Query(array('post_type' => bbp_get_reply_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => (int) $settings['max_shown'], 'ignore_sticky_posts' => true, 'no_found_rows' => true));
        // Bail if no replies
        if (!$widget_query->have_posts()) {
            return;
        }
        echo $args['before_widget'];
        if (!empty($settings['title'])) {
            echo $args['before_title'] . $settings['title'] . $args['after_title'];
        }
        ?>

		<ul>

			<?php 
        while ($widget_query->have_posts()) {
            $widget_query->the_post();
            ?>

				<li>

					<?php 
            // Verify the reply ID
            $reply_id = bbp_get_reply_id($widget_query->post->ID);
            $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($reply_id)) . '" title="' . esc_attr(bbp_get_reply_excerpt($reply_id, 50)) . '">' . bbp_get_reply_topic_title($reply_id) . '</a>';
            // Only query user if showing them
            if (!empty($settings['show_user'])) {
                $author_link = bbp_get_reply_author_link(array('post_id' => $reply_id, 'type' => 'both', 'size' => 14));
            } else {
                $author_link = false;
            }
            // Reply author, link, and timestamp
            if (!empty($settings['show_date']) && !empty($author_link)) {
                // translators: 1: reply author, 2: reply link, 3: reply timestamp
                printf(_x('%1$s on %2$s %3$s', 'widgets', 'bbpress'), $author_link, $reply_link, '<div>' . bbp_get_time_since(get_the_time('U')) . '</div>');
                // Reply link and timestamp
            } elseif (!empty($settings['show_date'])) {
                // translators: 1: reply link, 2: reply timestamp
                printf(_x('%1$s %2$s', 'widgets', 'bbpress'), $reply_link, '<div>' . bbp_get_time_since(get_the_time('U')) . '</div>');
                // Reply author and title
            } elseif (!empty($author_link)) {
                // translators: 1: reply author, 2: reply link
                printf(_x('%1$s on %2$s', 'widgets', 'bbpress'), $author_link, $reply_link);
                // Only the reply title
            } else {
                // translators: 1: reply link
                printf(_x('%1$s', 'widgets', 'bbpress'), $reply_link);
            }
            ?>

				</li>

			<?php 
        }
        ?>

		</ul>

		<?php 
        echo $args['after_widget'];
        // Reset the $post global
        wp_reset_postdata();
    }
示例#13
0
 /**
  * @covers ::bbp_unspam_topic_replies
  */
 public function test_bbp_unspam_topic_replies()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80);
     $topic_time = '4 days, 4 hours ago';
     $reply_time = '3 days, 8 hours ago';
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_spam_topic_replies($t);
     bbp_unspam_topic_replies($t);
     $this->assertEquals('', get_post_meta($t, '_bbp_pre_spammed_replies', true));
     $this->assertEquals(array(), get_post_meta($t, '_bbp_pre_spammed_replies', false));
     foreach ($r as $reply) {
         $reply_status = get_post_status($reply);
         $this->assertSame(bbp_get_public_status_id(), $reply_status);
         $this->assertEquals('', get_post_meta($reply, '_wp_trash_meta_status', true));
         $this->assertEquals(array(), get_post_meta($reply, '_wp_trash_meta_status', false));
     }
     $count = bbp_get_forum_reply_count($f, false, true);
     $this->assertSame(2, $count);
     $last_reply_id = bbp_get_forum_last_reply_id($f);
     $this->assertSame($r[1], $last_reply_id);
     $last_active_id = bbp_get_forum_last_active_id($f);
     $this->assertSame($r[1], $last_active_id);
     $last_active_time = bbp_get_forum_last_active_time($f);
     $this->assertSame($reply_time, $last_active_time);
     $count = bbp_get_topic_reply_count($t, true, true);
     $this->assertSame(2, $count);
     $count = bbp_get_topic_reply_count_hidden($t, true, true);
     $this->assertSame(0, $count);
     $last_reply_id = bbp_get_topic_last_reply_id($t);
     $this->assertSame($r[1], $last_reply_id);
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r[1], $last_active_id);
     $last_active_time = bbp_get_topic_last_active_time($t);
     $this->assertSame($reply_time, $last_active_time);
 }
示例#14
0
 /**
  * Save the Group Forum data on create
  *
  * @since bbPress (r3465)
  */
 public function create_screen_save($group_id = 0)
 {
     // Nonce check
     if (!bbp_verify_nonce_request('groups_create_save_' . $this->slug)) {
         bbp_add_error('bbp_create_group_forum_screen_save', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
         return;
     }
     // Check for possibly empty group_id
     if (empty($group_id)) {
         $group_id = bp_get_new_group_id();
     }
     $create_forum = !empty($_POST['bbp-create-group-forum']) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids($group_id);
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             // Update forum active
             groups_update_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true);
             // Toggle forum on
             $this->toggle_group_forum(bp_get_new_group_id(), true);
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 // Delete the forum
                 wp_delete_post($forum_id, true);
                 // Delete meta values
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
                 groups_delete_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id);
                 // Toggle forum off
                 $this->toggle_group_forum(bp_get_new_group_id(), false);
             }
             break;
     }
 }
示例#15
0
 /**
  * Converts topic/reply data into Akismet comment checking format
  *
  * @since bbPress (r3277)
  *
  * @param string $post_data
  *
  * @uses get_userdata() To get the user data
  * @uses bbp_filter_anonymous_user_data() To get anonymous user data
  * @uses bbp_get_topic_permalink() To get the permalink of the topic
  * @uses bbp_get_reply_url() To get the permalink of the reply
  * @uses bbp_current_author_ip() To get the IP address of the current user
  * @uses BBP_Akismet::maybe_spam() To check if post is spam
  * @uses akismet_get_user_roles() To get the role(s) of the current user
  * @uses do_action() To call the 'bbp_akismet_spam_caught' hook
  * @uses add_filter() To call the 'bbp_new_reply_pre_set_terms' hook
  *
  * @return array Array of post data
  */
 public function check_post($post_data)
 {
     // Define local variables
     $user_data = array();
     $post_permalink = '';
     // Post is not published
     if (bbp_get_public_status_id() != $post_data['post_status']) {
         return $post_data;
     }
     // Cast the post_author to 0 if it's empty
     if (empty($post_data['post_author'])) {
         $post_data['post_author'] = 0;
     }
     /** Author ************************************************************/
     // Get user data
     $userdata = get_userdata($post_data['post_author']);
     $anonymous_data = bbp_filter_anonymous_post_data();
     // Author is anonymous
     if (!empty($anonymous_data)) {
         $user_data['name'] = $anonymous_data['bbp_anonymous_name'];
         $user_data['email'] = $anonymous_data['bbp_anonymous_name'];
         $user_data['website'] = $anonymous_data['bbp_anonymous_name'];
         // Author is logged in
     } elseif (!empty($userdata)) {
         $user_data['name'] = $userdata->display_name;
         $user_data['email'] = $userdata->user_email;
         $user_data['website'] = $userdata->user_url;
         // Missing author data, so set some empty strings
     } else {
         $user_data['name'] = '';
         $user_data['email'] = '';
         $user_data['website'] = '';
     }
     /** Post **************************************************************/
     // Use post parent for permalink
     if (!empty($post_data['post_parent'])) {
         $post_permalink = get_permalink($post_data['post_parent']);
     }
     // Put post_data back into usable array
     $_post = array('comment_author' => $user_data['name'], 'comment_author_email' => $user_data['email'], 'comment_author_url' => $user_data['website'], 'comment_content' => $post_data['post_content'], 'comment_post_ID' => $post_data['post_parent'], 'comment_type' => $post_data['post_type'], 'permalink' => $post_permalink, 'referrer' => $_SERVER['HTTP_REFERER'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'user_ID' => $post_data['post_author'], 'user_ip' => bbp_current_author_ip(), 'user_role' => akismet_get_user_roles($post_data['post_author']));
     // Check the post_data
     $_post = $this->maybe_spam($_post);
     // Get the result
     $post_data['bbp_akismet_result'] = $_post['bbp_akismet_result'];
     unset($_post['bbp_akismet_result']);
     // Store the data as submitted
     $post_data['bbp_post_as_submitted'] = $_post;
     // Allow post_data to be manipulated
     do_action_ref_array('bbp_akismet_check_post', $post_data);
     // Spam
     if ('true' == $post_data['bbp_akismet_result']) {
         // Let plugins do their thing
         do_action('bbp_akismet_spam_caught');
         // This is spam
         $post_data['post_status'] = bbp_get_spam_status_id();
         // We don't want your spam tags here
         add_filter('bbp_new_reply_pre_set_terms', array($this, 'filter_post_terms'), 1, 3);
         // @todo Spam counter?
     }
     // @todo Topic/reply moderation? No true/false response - 'pending' or 'draft'
     // @todo Auto-delete old spam?
     // Log the last post
     $this->last_post = $post_data;
     // Pass the data back to the filter
     return $post_data;
 }
/**
 * Maps topic capabilities
 *
 * @since bbPress (r4242)
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param mixed $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses apply_filters() Filter capability map results
 * @return array Actual capabilities for meta capability
 */
function bbp_map_topic_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        /** Reading ***********************************************************/
        case 'read_topic':
            // User cannot spectate
            if (!user_can($user_id, 'spectate')) {
                $caps = array('do_not_allow');
                // Do some post ID based logic
            } else {
                // Get the post
                $_post = get_post($args[0]);
                if (!empty($_post)) {
                    // Get caps for post type object
                    $post_type = get_post_type_object($_post->post_type);
                    // Post is public
                    if (bbp_get_public_status_id() === $_post->post_status) {
                        $caps = array('spectate');
                        // User is author so allow read
                    } elseif ((int) $user_id === (int) $_post->post_author) {
                        $caps = array('spectate');
                        // Unknown so map to private posts
                    } else {
                        $caps = array($post_type->cap->read_private_posts);
                    }
                }
            }
            break;
            /** Publishing ********************************************************/
        /** Publishing ********************************************************/
        case 'publish_topics':
            // Moderators can always publish
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
            }
            break;
            /** Editing ***********************************************************/
            // Used primarily in wp-admin
        /** Editing ***********************************************************/
        // Used primarily in wp-admin
        case 'edit_topics':
        case 'edit_others_topics':
            // Moderators can always edit
            if (user_can($user_id, 'moderate')) {
                $caps = array($cap);
                // Otherwise, block
            } else {
                $caps = array('do_not_allow');
            }
            break;
            // Used everywhere
        // Used everywhere
        case 'edit_topic':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // User is author so allow edit if not in admin
                } elseif (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps[] = $post_type->cap->edit_posts;
                    // Unknown, so map to edit_others_posts
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
            }
            break;
            /** Deleting **********************************************************/
        /** Deleting **********************************************************/
        case 'delete_topic':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // Moderators can always edit forum content
                } elseif (user_can($user_id, 'moderate')) {
                    $caps[] = 'moderate';
                    // Unknown so map to delete_others_posts
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
            }
            break;
            // Moderation override
        // Moderation override
        case 'delete_topics':
        case 'delete_others_topics':
            // Moderators can always delete
            if (user_can($user_id, 'moderate')) {
                $caps = array($cap);
            }
            break;
            /** Admin *************************************************************/
        /** Admin *************************************************************/
        case 'bbp_topics_admin':
            $caps = array('moderate');
            break;
    }
    return apply_filters('bbp_map_topic_meta_caps', $caps, $cap, $user_id, $args);
}
示例#17
0
 /**
  * Update the activity stream entry when a reply status changes
  *
  * @param int $post_id
  * @param obj $post
  * @uses get_post_type()
  * @uses bbp_get_reply_post_type()
  * @uses bbp_get_reply_id()
  * @uses bbp_is_reply_anonymous()
  * @uses bbp_get_public_status_id()
  * @uses bbp_get_closed_status_id()
  * @uses bbp_get_reply_topic_id()
  * @uses bbp_get_reply_forum_id()
  * @uses bbp_get_reply_author_id()
  * @return Bail early if not a reply, or reply is by anonymous user
  */
 public function reply_update($reply_id, $post)
 {
     // Bail early if not a reply
     if (get_post_type($post) != bbp_get_reply_post_type()) {
         return;
     }
     $reply_id = bbp_get_reply_id($reply_id);
     // Bail early if reply is by anonymous user
     if (bbp_is_reply_anonymous($reply_id)) {
         return;
     }
     $anonymous_data = array();
     // Action based on new status
     if ($post->post_status == bbp_get_public_status_id()) {
         // Validate reply data
         $topic_id = bbp_get_reply_topic_id($reply_id);
         $forum_id = bbp_get_reply_forum_id($reply_id);
         $reply_author_id = bbp_get_reply_author_id($reply_id);
         $this->reply_create($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id);
     } else {
         $this->reply_delete($reply_id);
     }
 }
示例#18
0
    /**
     * Displays the output, the replies list
     *
     * @since bbPress (r2653)
     *
     * @param mixed $args
     * @param array $instance
     * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
     * @uses bbp_get_reply_author_link() To get the reply author link
     * @uses bbp_get_reply_author() To get the reply author name
     * @uses bbp_get_reply_id() To get the reply id
     * @uses bbp_get_reply_url() To get the reply url
     * @uses bbp_get_reply_excerpt() To get the reply excerpt
     * @uses bbp_get_reply_topic_title() To get the reply topic title
     * @uses get_the_date() To get the date of the reply
     * @uses get_the_time() To get the time of the reply
     */
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('bbp_replies_widget_title', $instance['title']);
        $max_shown = !empty($instance['max_shown']) ? $instance['max_shown'] : '5';
        $show_date = !empty($instance['show_date']) ? 'on' : false;
        $show_user = !empty($instance['show_user']) ? 'on' : false;
        $post_types = !empty($instance['post_type']) ? array(bbp_get_topic_post_type(), bbp_get_reply_post_type()) : bbp_get_reply_post_type();
        // Note: private and hidden forums will be excluded via the
        // bbp_pre_get_posts_exclude_forums filter and function.
        $widget_query = new WP_Query(array('post_type' => $post_types, 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'posts_per_page' => $max_shown, 'meta_query' => array(bbp_exclude_forum_ids('meta_query'))));
        // Get replies and display them
        if ($widget_query->have_posts()) {
            echo $before_widget;
            echo $before_title . $title . $after_title;
            ?>

			<ul>

				<?php 
            while ($widget_query->have_posts()) {
                $widget_query->the_post();
                ?>

					<li>

						<?php 
                $reply_id = bbp_get_reply_id($widget_query->post->ID);
                $author_link = bbp_get_reply_author_link(array('post_id' => $reply_id, 'type' => 'both', 'size' => 14));
                $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($reply_id)) . '" title="' . bbp_get_reply_excerpt($reply_id, 50) . '">' . bbp_get_reply_topic_title($reply_id) . '</a>';
                // Reply author, link, and timestamp
                if ('on' == $show_date && 'on' == $show_user) {
                    // translators: 1: reply author, 2: reply link, 3: reply timestamp
                    printf(_x('%1$s on %2$s %3$s', 'widgets', 'bbpress'), $author_link, $reply_link, '<div>' . bbp_get_time_since(get_the_time('U')) . '</div>');
                    // Reply link and timestamp
                } elseif ($show_date == 'on') {
                    // translators: 1: reply link, 2: reply timestamp
                    printf(_x('%1$s %2$s', 'widgets', 'bbpress'), $reply_link, '<div>' . bbp_get_time_since(get_the_time('U')) . '</div>');
                    // Reply author and title
                } elseif ($show_user == 'on') {
                    // translators: 1: reply author, 2: reply link
                    printf(_x('%1$s on %2$s', 'widgets', 'bbpress'), $author_link, $reply_link);
                    // Only the reply title
                } else {
                    // translators: 1: reply link
                    printf(_x('%1$s', 'widgets', 'bbpress'), $reply_link);
                }
                ?>

					</li>

				<?php 
            }
            ?>

			</ul>

			<?php 
            echo $after_widget;
            // Reset the $post global
            wp_reset_postdata();
        }
    }
/**
 * Mark a users topics and replies as spam when the user is marked as spam
 *
 * @since bbPress (r3405)
 *
 * @global WPDB $wpdb
 * @param int $user_id Optional. User ID to spam. Defaults to displayed user.
 * @uses bbp_is_single_user()
 * @uses bbp_is_user_home()
 * @uses bbp_get_displayed_user_id()
 * @uses bbp_is_user_keymaster()
 * @uses get_blogs_of_user()
 * @uses get_current_blog_id()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @uses switch_to_blog()
 * @uses get_post_type()
 * @uses bbp_spam_topic()
 * @uses bbp_spam_reply()
 * @uses restore_current_blog()
 *
 * @return If no user ID passed
 */
function bbp_make_spam_user($user_id = 0)
{
    // Use displayed user if it's not yourself
    if (empty($user_id) && bbp_is_single_user() && !bbp_is_user_home()) {
        $user_id = bbp_get_displayed_user_id();
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return false;
    }
    // Bail if user ID is keymaster
    if (bbp_is_user_keymaster($user_id)) {
        return false;
    }
    // Arm the torpedos
    global $wpdb;
    // Get the blog IDs of the user to mark as spam
    $blogs = get_blogs_of_user($user_id, true);
    // If user has no blogs, they are a guest on this site
    if (empty($blogs)) {
        $blogs[$wpdb->blogid] = array();
    }
    // Make array of post types to mark as spam
    $post_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $post_types = "'" . implode("', '", $post_types) . "'";
    // Loop through blogs and remove their posts
    foreach ((array) array_keys($blogs) as $blog_id) {
        // Switch to the blog ID
        switch_to_blog($blog_id);
        // Get topics and replies
        $posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id()));
        // Loop through posts and spam them
        if (!empty($posts)) {
            foreach ($posts as $post_id) {
                // The routines for topics ang replies are different, so use the
                // correct one based on the post type
                switch (get_post_type($post_id)) {
                    case bbp_get_topic_post_type():
                        bbp_spam_topic($post_id);
                        break;
                    case bbp_get_reply_post_type():
                        bbp_spam_reply($post_id);
                        break;
                }
            }
        }
        // Switch back to current blog
        restore_current_blog();
    }
    // Success
    return true;
}
 /**
  * Un-reports a reply
  *
  * @@since 1.0.0
  *
  * @param int $reply_id Reply id
  * @uses bbp_get_reply() To get the reply
  * @uses do_action() Calls 'bbp_rc_unreport_reply' with the reply ID
  * @uses get_post_meta() To get the previous status meta
  * @uses delete_post_meta() To delete the previous status meta
  * @uses wp_update_post() To insert the updated post
  * @uses do_action() Calls 'bbp_rc_unreported_reply' with the reply ID
  * @return mixed False or {@link WP_Error} on failure, reply id on success
  */
 function unreport_reply($reply_id = 0)
 {
     // Get reply
     $reply = bbp_get_reply($reply_id);
     if (empty($reply)) {
         return $reply;
     }
     // Bail if already not reported
     if ($this->get_reported_status_id() !== $reply->post_status) {
         return false;
     }
     // Bail if user doesn't have moderate capability
     if (!current_user_can('moderate', $reply->ID)) {
         return false;
     }
     // Execute pre unreport code
     do_action('bbp_rc_unreport_reply', $reply_id);
     // Get pre report status
     $reply->post_status = get_post_meta($reply_id, '_bbp_report_meta_status', true);
     // If no previous status, default to publish
     if (empty($reply->post_status)) {
         $reply->post_status = bbp_get_public_status_id();
     }
     // Delete pre report meta
     delete_post_meta($reply_id, '_bbp_report_meta_status');
     // Add the user id of the user who reported
     delete_post_meta($reply_id, '_bbp_report_user_id');
     // No revisions
     remove_action('pre_post_update', 'wp_save_post_revision');
     // Update the reply
     $reply_id = wp_update_post($reply);
     // Execute post unreport code
     do_action('bbp_rc_unreported_reply', $reply_id);
     // Return reply_id
     return $reply_id;
 }
示例#21
0
/**
 * The main search loop. WordPress does the heavy lifting.
 *
 * @since bbPress (r4579)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses bbp_get_view_all() Are we showing all results?
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_get_closed_status_id() To get the closed status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_replies_per_page() To get the replies per page option
 * @uses bbp_get_paged() To get the current page value
 * @uses bbp_get_search_terms() To get the search terms
 * @uses WP_Query To make query and get the search results
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses bbp_get_search_url() To get the forum search url
 * @uses paginate_links() To paginate search results
 * @uses apply_filters() Calls 'bbp_has_search_results' with
 *                        bbPress::search_query::have_posts()
 *                        and bbPress::reply_query
 * @return object Multidimensional array of search information
 */
function bbp_has_search_results($args = '')
{
    global $wp_rewrite;
    /** Defaults **************************************************************/
    $default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type());
    // Default query args
    $default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms());
    // What are the default allowed statuses (based on user caps)
    if (bbp_get_view_all()) {
        // Default view=all statuses
        $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
        // Add support for private status
        if (current_user_can('read_private_topics')) {
            $post_statuses[] = bbp_get_private_status_id();
        }
        // Join post statuses together
        $default['post_status'] = implode(',', $post_statuses);
        // Lean on the 'perm' query var value of 'readable' to provide statuses
    } else {
        $default['perm'] = 'readable';
    }
    /** Setup *****************************************************************/
    // Parse arguments against default values
    $r = bbp_parse_args($args, $default, 'has_search_results');
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    if (!empty($r['s'])) {
        $bbp->search_query = new WP_Query($r);
    }
    // Add pagination values to query object
    $bbp->search_query->posts_per_page = $r['posts_per_page'];
    $bbp->search_query->paged = $r['paged'];
    // Never home, regardless of what parse_query says
    $bbp->search_query->is_home = false;
    // Only add pagination is query returned results
    if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) {
        // Array of arguments to add after pagination links
        $add_args = array();
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // Shortcode territory
            if (is_page() || is_single()) {
                $base = trailingslashit(get_permalink());
                // Default search location
            } else {
                $base = trailingslashit(bbp_get_search_results_url());
            }
            // Add pagination base
            $base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty permalinks
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Add args
        if (bbp_get_view_all()) {
            $add_args['view'] = 'all';
        }
        // Add pagination to query object
        $bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1, 'add_args' => $add_args)));
        // Remove first page from pagination
        if ($wp_rewrite->using_permalinks()) {
            $bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links);
        } else {
            $bbp->search_query->pagination_links = str_replace('&#038;paged=1', '', $bbp->search_query->pagination_links);
        }
    }
    // Return object
    return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query);
}
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
示例#23
0
/**
 * Output a select box allowing to pick which forum/topic a new
 * topic/reply belongs in.
 *
 * @since bbPress (r2746)
 *
 * @param mixed $args The function supports these args:
 *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
 *  - selected: Selected ID, to not have any value as selected, pass
 *               anything smaller than 0 (due to the nature of select
 *               box, the first value would of course be selected -
 *               though you can have that as none (pass 'show_none' arg))
 *  - sort_column: Sort by? Defaults to 'menu_order, post_title'
 *  - child_of: Child of. Defaults to 0
 *  - post_status: Which all post_statuses to find in? Can be an array
 *                  or CSV of publish, category, closed, private, spam,
 *                  trash (based on post type) - if not set, these are
 *                  automatically determined based on the post_type
 *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
 *                     all posts
 *  - walker: Which walker to use? Defaults to
 *             {@link BBP_Walker_Dropdown}
 *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
 *  - tab: Tabindex value. False or integer
 *  - options_only: Show only <options>? No <select>?
 *  - show_none: False or something like __( '(No Forum)', 'bbpress' ),
 *                will have value=""
 *  - none_found: False or something like
 *                 __( 'No forums to post to!', 'bbpress' )
 *  - disable_categories: Disable forum categories and closed forums?
 *                         Defaults to true. Only for forums and when
 *                         the category option is displayed.
 * @uses BBP_Walker_Dropdown() As the default walker to generate the
 *                              dropdown
 * @uses current_user_can() To check if the current user can read
 *                           private forums
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses walk_page_dropdown_tree() To generate the dropdown using the
 *                                  walker
 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
 *                        and args
 * @return string The dropdown
 */
function bbp_get_dropdown($args = '')
{
    /** Arguments *********************************************************/
    $defaults = array('post_type' => bbp_get_forum_post_type(), 'selected' => 0, 'sort_column' => 'menu_order', 'child_of' => '0', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true);
    $r = bbp_parse_args($args, $defaults, 'get_dropdown');
    if (empty($r['walker'])) {
        $r['walker'] = new BBP_Walker_Dropdown();
        $r['walker']->tree_type = $r['post_type'];
    }
    // Force 0
    if (is_numeric($r['selected']) && $r['selected'] < 0) {
        $r['selected'] = 0;
    }
    extract($r);
    // Unset the args not needed for WP_Query to avoid any possible conflicts.
    // Note: walker and disable_categories are not unset
    unset($r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found']);
    /** Post Status *******************************************************/
    // Define local variable(s)
    $post_stati = array();
    // Public
    $post_stati[] = bbp_get_public_status_id();
    // Forums
    if (bbp_get_forum_post_type() == $post_type) {
        // Private forums
        if (current_user_can('read_private_forums')) {
            $post_stati[] = bbp_get_private_status_id();
        }
        // Hidden forums
        if (current_user_can('read_hidden_forums')) {
            $post_stati[] = bbp_get_hidden_status_id();
        }
    }
    // Setup the post statuses
    $r['post_status'] = implode(',', $post_stati);
    /** Setup variables ***************************************************/
    $name = esc_attr($select_id);
    $select_id = $name;
    $tab = (int) $tab;
    $retval = '';
    $posts = get_posts($r);
    /** Drop Down *********************************************************/
    // Items found
    if (!empty($posts)) {
        if (empty($options_only)) {
            $tab = !empty($tab) ? ' tabindex="' . $tab . '"' : '';
            $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n";
        }
        $retval .= !empty($show_none) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : '';
        $retval .= walk_page_dropdown_tree($posts, 0, $r);
        if (empty($options_only)) {
            $retval .= '</select>';
        }
        // No items found - Display feedback if no custom message was passed
    } elseif (empty($none_found)) {
        // Switch the response based on post type
        switch ($post_type) {
            // Topics
            case bbp_get_topic_post_type():
                $retval = __('No topics available', 'bbpress');
                break;
                // Forums
            // Forums
            case bbp_get_forum_post_type():
                $retval = __('No forums available', 'bbpress');
                break;
                // Any other
            // Any other
            default:
                $retval = __('None available', 'bbpress');
                break;
        }
    }
    return apply_filters('bbp_get_dropdown', $retval, $args);
}
示例#24
0
/**
 * Get the forums the current user has the ability to see and post to
 *
 * @since 2.0.0 bbPress (r3127)
 *
 * @uses bbp_get_forum_post_type()
 * @uses get_posts()
 *
 * @param type $args
 * @return type
 */
function bbp_get_forums_for_current_user($args = array())
{
    // Setup arrays
    $private = $hidden = $exclude = array();
    // Private forums
    if (!current_user_can('read_private_forums')) {
        $private = bbp_get_private_forum_ids();
    }
    // Hidden forums
    if (!current_user_can('read_hidden_forums')) {
        $hidden = bbp_get_hidden_forum_ids();
    }
    // Merge private and hidden forums together and remove any empties
    $forum_ids = (array) array_filter(wp_parse_id_list(array_merge($private, $hidden)));
    // There are forums that need to be excluded
    if (!empty($forum_ids)) {
        $exclude = implode(',', $forum_ids);
    }
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'numberposts' => -1, 'exclude' => $exclude), 'get_forums_for_current_user');
    // Get the forums
    $forums = get_posts($r);
    // No availabe forums
    if (empty($forums)) {
        $forums = false;
    }
    return apply_filters('bbp_get_forums_for_current_user', $forums);
}
示例#25
0
/**
 * Maps forum/topic/reply caps to built in WordPress caps
 *
 * @since bbPress (r2593)
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param mixed $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses apply_filters() Calls 'bbp_map_meta_caps' with caps, cap, user id and
 *                        args
 * @return array Actual capabilities for meta capability
 */
function bbp_map_meta_caps($caps, $cap, $user_id, $args)
{
    // What capability is being checked?
    switch ($cap) {
        /** Reading ***********************************************************/
        case 'read_forum':
        case 'read_topic':
        case 'read_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Post is public
                if (bbp_get_public_status_id() == $_post->post_status) {
                    $caps[] = 'read';
                    // User is author so allow read
                } elseif ((int) $user_id == (int) $_post->post_author) {
                    $caps[] = 'read';
                    // Unknown so map to private posts
                } else {
                    $caps[] = $post_type->cap->read_private_posts;
                }
            }
            break;
            /** Publishing ********************************************************/
        /** Publishing ********************************************************/
        case 'publish_forums':
        case 'publish_topics':
        case 'publish_replies':
            // Add do_not_allow cap if user is spam or deleted
            if (bbp_is_user_inactive($user_id)) {
                $caps = array('do_not_allow');
            }
            break;
            /** Editing ***********************************************************/
            // Used primarily in wp-admin
        /** Editing ***********************************************************/
        // Used primarily in wp-admin
        case 'edit_forums':
        case 'edit_topics':
        case 'edit_replies':
            // Add do_not_allow cap if user is spam or deleted
            if (bbp_is_user_inactive($user_id)) {
                $caps = array('do_not_allow');
            }
            break;
            // Used everywhere
        // Used everywhere
        case 'edit_forum':
        case 'edit_topic':
        case 'edit_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // User is author so allow edit
                } elseif ((int) $user_id == (int) $_post->post_author) {
                    $caps[] = $post_type->cap->edit_posts;
                    // Unknown, so map to edit_others_posts
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
            }
            break;
            /** Deleting **********************************************************/
            // Allow forum authors to delete forums (for BuddyPress groups, etc)
        /** Deleting **********************************************************/
        // Allow forum authors to delete forums (for BuddyPress groups, etc)
        case 'delete_forum':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // User is author so allow to delete
                } elseif ((int) $user_id == (int) $_post->post_author) {
                    $caps[] = $post_type->cap->delete_posts;
                    // Unknown so map to delete_others_posts
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
            }
            break;
        case 'delete_topic':
        case 'delete_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get caps for post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // Unknown so map to delete_others_posts
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
            }
            break;
    }
    return apply_filters('bbp_map_meta_caps', $caps, $cap, $user_id, $args);
}
示例#26
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($args = '')
{
    // Backpat for handling passing of a forum ID
    if (is_int($args)) {
        $forum_id = (int) $args;
        $args = array();
    } else {
        $forum_id = 0;
    }
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_visibility', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select');
    // No specific selected value passed
    if (empty($r['selected'])) {
        // Post value is passed
        if (bbp_is_post_request() && isset($_POST[$r['select_id']])) {
            $r['selected'] = $_POST[$r['select_id']];
            // No Post value was passed
        } else {
            // Edit topic
            if (bbp_is_forum_edit()) {
                $r['forum_id'] = bbp_get_forum_id($r['forum_id']);
                $r['selected'] = bbp_get_forum_visibility($r['forum_id']);
                // New topic
            } else {
                $r['selected'] = bbp_get_public_status_id();
            }
        }
    }
    // Used variables
    $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    // Start an output buffer, we'll finish it after the select loop
    ob_start();
    ?>

		<select name="<?php 
    echo esc_attr($r['select_id']);
    ?>
" id="<?php 
    echo esc_attr($r['select_id']);
    ?>
_select"<?php 
    echo $tab;
    ?>
>

			<?php 
    foreach (bbp_get_forum_visibilities() as $key => $label) {
        ?>

				<option value="<?php 
        echo esc_attr($key);
        ?>
"<?php 
        selected($key, $r['selected']);
        ?>
><?php 
        echo esc_html($label);
        ?>
</option>

			<?php 
    }
    ?>

		</select>

		<?php 
    // Return the results
    return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r);
}
示例#27
0
 /**
  * Reply Row actions
  *
  * Remove the quick-edit action link under the reply title and add the
  * content and spam link
  *
  * @since 2.0.0 bbPress (r2577)
  *
  * @param array $actions Actions
  * @param array $reply Reply object
  * @uses bbp_get_reply_post_type() To get the reply post type
  * @uses bbp_reply_content() To output reply content
  * @uses bbp_get_reply_url() To get the reply link
  * @uses bbp_get_reply_title() To get the reply title
  * @uses current_user_can() To check if the current user can edit or
  *                           delete the reply
  * @uses bbp_is_reply_spam() To check if the reply is marked as spam
  * @uses get_post_type_object() To get the reply 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 reply
  * @return array $actions Actions
  */
 public function row_actions($actions, $reply)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Reply view links to topic
     $actions['view'] = '<a href="' . esc_url(bbp_get_reply_url($reply->ID)) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;', 'bbpress'), bbp_get_reply_title($reply->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>';
     // User cannot view replies in trash
     if (bbp_get_trash_status_id() === $reply->post_status && !current_user_can('view_trash')) {
         unset($actions['view']);
     }
     // Only show the actions if the user is capable of viewing them
     if (current_user_can('moderate', $reply->ID)) {
         // Show the 'approve' link on pending posts only and 'unapprove' on published posts only
         $approve_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_approve'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'approve-reply_' . $reply->ID);
         if (bbp_is_reply_published($reply->ID)) {
             $actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this reply', 'bbpress') . '">' . _x('Unapprove', 'Unapprove reply', 'bbpress') . '</a>';
         } elseif (!bbp_is_reply_private($reply->ID)) {
             $actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this reply', 'bbpress') . '">' . _x('Approve', 'Approve reply', 'bbpress') . '</a>';
         }
         // Show the 'spam' link on published and pending replies and 'not spam' on spammed replies
         if (in_array($reply->post_status, array(bbp_get_public_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id()))) {
             $spam_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'spam-reply_' . $reply->ID);
             if (bbp_is_reply_spam($reply->ID)) {
                 $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the reply as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>';
             } else {
                 $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this reply as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>';
             }
         }
     }
     // Trash
     if (current_user_can('delete_reply', $reply->ID)) {
         if (bbp_get_trash_status_id() === $reply->post_status) {
             $post_type_object = get_post_type_object(bbp_get_reply_post_type());
             $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_reply_post_type()), admin_url('edit.php'))), wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $reply->ID)), 'untrash-' . $reply->post_type . '_' . $reply->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_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>";
         }
         if (bbp_get_trash_status_id() === $reply->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_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>";
         } elseif (bbp_get_spam_status_id() === $reply->post_status) {
             unset($actions['trash']);
         }
     }
     return $actions;
 }
示例#28
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $forum_attr = apply_filters('bbp_forum_visibilities', array(bbp_get_public_status_id() => __('Public', 'bbpress'), bbp_get_private_status_id() => __('Private', 'bbpress'), bbp_get_hidden_status_id() => __('Hidden', 'bbpress')));
    $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n";
    foreach ($forum_attr as $value => $label) {
        $visibility_output .= "\t" . '<option value="' . $value . '"' . selected(bbp_get_forum_visibility($forum_id), $value, false) . '>' . esc_html($label) . '</option>' . "\n";
    }
    $visibility_output .= '</select>';
    return apply_filters('bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr);
}
示例#29
0
/**
 * Returns topic status downdown
 *
 * This dropdown is only intended to be seen by users with the 'moderate'
 * capability. Because of this, no additional capablitiy checks are performed
 * within this function to check available topic statuses.
 *
 * @since bbPress (r5059)
 *
 * @param $args This function supports these arguments:
 *  - select_id: Select id. Defaults to bbp_open_close_topic
 *  - tab: Tabindex
 *  - topic_id: Topic id
 *  - selected: Override the selected option
 */
function stachestack_bbp_get_form_topic_status_dropdown($args = '')
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('select_id' => 'bbp_topic_status', 'tab' => bbp_get_tab_index(), 'topic_id' => 0, 'selected' => false), 'topic_open_close_select');
    // No specific selected value passed
    if (empty($r['selected'])) {
        // Post value is passed
        if (bbp_is_post_request() && isset($_POST[$r['select_id']])) {
            $r['selected'] = $_POST[$r['select_id']];
            // No Post value was passed
        } else {
            // Edit topic
            if (bbp_is_topic_edit()) {
                $r['topic_id'] = bbp_get_topic_id($r['topic_id']);
                $r['selected'] = bbp_get_topic_status($r['topic_id']);
                // New topic
            } else {
                $r['selected'] = bbp_get_public_status_id();
            }
        }
    }
    // Used variables
    $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    // Start an output buffer, we'll finish it after the select loop
    ob_start();
    ?>

		<select class="form-control" name="<?php 
    echo esc_attr($r['select_id']);
    ?>
" id="<?php 
    echo esc_attr($r['select_id']);
    ?>
_select"<?php 
    echo $tab;
    ?>
>

			<?php 
    foreach (bbp_get_topic_statuses($r['topic_id']) as $key => $label) {
        ?>

				<option value="<?php 
        echo esc_attr($key);
        ?>
"<?php 
        selected($key, $r['selected']);
        ?>
><?php 
        echo esc_html($label);
        ?>
</option>

			<?php 
    }
    ?>

		</select>

		<?php 
    // Return the results
    return apply_filters('bbp_get_form_topic_status_dropdown', ob_get_clean(), $r);
}
示例#30
0
/**
 * This function is hooked into the WordPress 'request' action and is
 * responsible for sniffing out the query vars and serving up RSS2 feeds if
 * the stars align and the user has requested a feed of any bbPress type.
 *
 * @since 2.0.0 bbPress (r3171)
 *
 * @param array $query_vars
 * @return array
 */
function bbp_request_feed_trap($query_vars = array())
{
    // Looking at a feed
    if (isset($query_vars['feed'])) {
        // Forum/Topic/Reply Feed
        if (isset($query_vars['post_type'])) {
            // Matched post type
            $post_type = false;
            // Post types to check
            $post_types = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type());
            // Cast query vars as array outside of foreach loop
            $qv_array = (array) $query_vars['post_type'];
            // Check if this query is for a bbPress post type
            foreach ($post_types as $bbp_pt) {
                if (in_array($bbp_pt, $qv_array, true)) {
                    $post_type = $bbp_pt;
                    break;
                }
            }
            // Looking at a bbPress post type
            if (!empty($post_type)) {
                // Supported select query vars
                $select_query_vars = array('p' => false, 'name' => false, $post_type => false);
                // Setup matched variables to select
                foreach ($query_vars as $key => $value) {
                    if (isset($select_query_vars[$key])) {
                        $select_query_vars[$key] = $value;
                    }
                }
                // Remove any empties
                $select_query_vars = array_filter($select_query_vars);
                // What bbPress post type are we looking for feeds on?
                switch ($post_type) {
                    // Forum
                    case bbp_get_forum_post_type():
                        // Define local variable(s)
                        $meta_query = array();
                        // Single forum
                        if (!empty($select_query_vars)) {
                            // Load up our own query
                            query_posts(array_merge(array('post_type' => bbp_get_forum_post_type(), 'feed' => true), $select_query_vars));
                            // Restrict to specific forum ID
                            $meta_query = array(array('key' => '_bbp_forum_id', 'value' => bbp_get_forum_id(), 'type' => 'NUMERIC', 'compare' => '='));
                        }
                        // Only forum replies
                        if (!empty($_GET['type']) && bbp_get_reply_post_type() === $_GET['type']) {
                            // The query
                            $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_reply_post_type(), 'post_parent' => 'any', 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query);
                            // Output the feed
                            bbp_display_replies_feed_rss2($the_query);
                            // Only forum topics
                        } elseif (!empty($_GET['type']) && bbp_get_topic_post_type() === $_GET['type']) {
                            // The query
                            $the_query = array('author' => 0, 'feed' => true, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_forum_id(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_topics_per_rss_page(), 'order' => 'DESC');
                            // Output the feed
                            bbp_display_topics_feed_rss2($the_query);
                            // All forum topics and replies
                        } else {
                            // Exclude private/hidden forums if not looking at single
                            if (empty($select_query_vars)) {
                                $meta_query = array(bbp_exclude_forum_ids('meta_query'));
                            }
                            // The query
                            $the_query = array('author' => 0, 'feed' => true, 'post_type' => array(bbp_get_reply_post_type(), bbp_get_topic_post_type()), 'post_parent' => 'any', 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => bbp_get_replies_per_rss_page(), 'order' => 'DESC', 'meta_query' => $meta_query);
                            // Output the feed
                            bbp_display_replies_feed_rss2($the_query);
                        }
                        break;
                        // Topic feed - Show replies
                    // Topic feed - Show replies
                    case bbp_get_topic_post_type():
                        // Single topic
                        if (!empty($select_query_vars)) {
                            // Load up our own query
                            query_posts(array_merge(array('post_type' => bbp_get_topic_post_type(), 'feed' => true), $select_query_vars));
                            // Output the feed
                            bbp_display_replies_feed_rss2(array('feed' => true));
                            // All topics
                        } else {
                            // The query
                            $the_query = array('author' => 0, 'feed' => true, 'post_parent' => 'any', 'posts_per_page' => bbp_get_topics_per_rss_page(), 'show_stickies' => false);
                            // Output the feed
                            bbp_display_topics_feed_rss2($the_query);
                        }
                        break;
                        // Replies
                    // Replies
                    case bbp_get_reply_post_type():
                        // The query
                        $the_query = array('posts_per_page' => bbp_get_replies_per_rss_page(), 'meta_query' => array(array()), 'feed' => true);
                        // All replies
                        if (empty($select_query_vars)) {
                            bbp_display_replies_feed_rss2($the_query);
                        }
                        break;
                }
            }
            // Single Topic Vview
        } elseif (isset($query_vars[bbp_get_view_rewrite_id()])) {
            // Get the view
            $view = $query_vars[bbp_get_view_rewrite_id()];
            // We have a view to display a feed
            if (!empty($view)) {
                // Get the view query
                $the_query = bbp_get_view_query_args($view);
                // Output the feed
                bbp_display_topics_feed_rss2($the_query);
            }
        }
        // @todo User profile feeds
    }
    // No feed so continue on
    return $query_vars;
}