예제 #1
0
/**
 * The main reply loop. WordPress makes this easy for us
 *
 * @since bbPress (r2553)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses bbp_is_user_bozo() To add the bozo post status
 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_is_query_name() To check if we are getting replies for a widget
 * @uses get_option() To get the replies per page option
 * @uses bbp_get_paged() To get the current page value
 * @uses current_user_can() To check if the current user is capable of editing
 *                           others' replies
 * @uses WP_Query To make query and get the replies
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses get_permalink() To get the permalink
 * @uses add_query_arg() To add custom args to the url
 * @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args
 * @uses paginate_links() To paginate the links
 * @uses apply_filters() Calls 'bbp_has_replies' with
 *                        bbPres::reply_query::have_posts()
 *                        and bbPres::reply_query
 * @return object Multidimensional array of reply information
 */
function bbp_has_replies($args = '')
{
    global $wp_rewrite;
    // What are the default allowed statuses (based on user caps)
    if (bbp_get_view_all('edit_others_replies')) {
        $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
    } else {
        $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
    }
    // Add the bozo status if user is a bozo
    if (bbp_is_user_bozo()) {
        $post_statuses[] = bbp_get_bozo_status_id();
    }
    $default_reply_search = !empty($_REQUEST['rs']) ? $_REQUEST['rs'] : false;
    $default_post_parent = bbp_is_single_topic() ? bbp_get_topic_id() : 'any';
    $default_post_type = bbp_is_single_topic() && bbp_show_lead_topic() ? bbp_get_reply_post_type() : array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $default_post_status = join(',', $post_statuses);
    // Default query args
    $default = array('post_type' => $default_post_type, 'post_parent' => $default_post_parent, 'post_status' => $default_post_status, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'ASC', 's' => $default_reply_search);
    // Set up topic variables
    $bbp_r = bbp_parse_args($args, $default, 'has_replies');
    // Extract the query variables
    extract($bbp_r);
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    $bbp->reply_query = new WP_Query($bbp_r);
    // Add pagination values to query object
    $bbp->reply_query->posts_per_page = $posts_per_page;
    $bbp->reply_query->paged = $paged;
    // Only add pagination if query returned results
    if ((int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page) {
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // Page or single
            if (is_page() || is_single()) {
                $base = get_permalink();
                // Topic
            } else {
                $base = get_permalink(bbp_get_topic_id());
            }
            $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty permalinks
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Pagination settings with filter
        $bbp_replies_pagination = apply_filters('bbp_replies_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->reply_query->found_posts / (int) $posts_per_page), 'current' => (int) $bbp->reply_query->paged, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => bbp_get_view_all() ? array('view' => 'all') : false));
        // Add pagination to query object
        $bbp->reply_query->pagination_links = paginate_links($bbp_replies_pagination);
        // Remove first page from pagination
        if ($wp_rewrite->using_permalinks()) {
            $bbp->reply_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links);
        } else {
            $bbp->reply_query->pagination_links = str_replace('&paged=1', '', $bbp->reply_query->pagination_links);
        }
    }
    // Return object
    return apply_filters('bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query);
}
        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();
        }
예제 #4
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;
 }
예제 #5
0
/**
 * Is the topic closed to new replies?
 *
 * @since 2.0.0 bbPress (r2746)
 *
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_topic_status() To get the topic status
 * @uses apply_filters() Calls 'bbp_is_topic_closed' with the topic id
 *
 * @return bool True if closed, false if not.
 */
function bbp_is_topic_closed($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $status = bbp_get_closed_status_id();
    $topic_status = bbp_get_topic_status($topic_id) === $status;
    return (bool) apply_filters('bbp_is_topic_closed', (bool) $topic_status, $topic_id);
}
예제 #6
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);
}
예제 #7
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);
}
예제 #8
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;
}
        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 
            }
        }
예제 #10
0
/**
 * Return the raw database count of closed topics by a user
 *
 * @since 2.6.0 bbPress (r6113)
 *
 * @param int $user_id User ID to get count for
 *
 * @return int Raw DB count of user closed topics
 */
function bbp_get_user_closed_topic_count($user_id = 0)
{
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    $bbp_db = bbp_db();
    $count = (int) $bbp_db->get_var("SELECT COUNT(*)\n\t\tFROM {$bbp_db->posts}\n\t\tWHERE post_type = '" . bbp_get_topic_post_type() . "'\n\t\tAND post_status = '" . bbp_get_closed_status_id() . "'\n\t\tAND post_author = {$user_id};");
    return (int) apply_filters('bbp_get_user_closed_topic_count', $count, $user_id);
}
예제 #11
0
 /**
  * Forum Row actions
  *
  * Remove the quick-edit action link and display the description under
  * the forum title and add the open/close links
  *
  * @since 2.0.0 bbPress (r2577)
  *
  * @param array $actions Actions
  * @param array $forum Forum object
  * @uses bbp_get_public_status_id() To get the published forum id's
  * @uses bbp_get_private_status_id() To get the private forum id's
  * @uses bbp_get_hidden_status_id() To get the hidden forum id's
  * @uses bbp_get_closed_status_id() To get the closed forum id's
  * @uses wp_nonce_url() To nonce the url
  * @uses bbp_is_forum_open() To check if a forum is open
  * @uses bbp_forum_content() To output forum description
  * @return array $actions Actions
  */
 public function row_actions($actions, $forum)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Only show the actions if the user is capable of viewing them :)
     if (current_user_can('keep_gate', $forum->ID)) {
         // Show the 'close' and 'open' link on published, private, hidden and closed posts only
         if (in_array($forum->post_status, array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id()))) {
             $close_uri = wp_nonce_url(add_query_arg(array('forum_id' => $forum->ID, 'action' => 'bbp_toggle_forum_close'), remove_query_arg(array('bbp_forum_toggle_notice', 'forum_id', 'failed', 'super'))), 'close-forum_' . $forum->ID);
             if (bbp_is_forum_open($forum->ID)) {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this forum', 'bbpress') . '">' . _x('Close', 'Close a Forum', 'bbpress') . '</a>';
             } else {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this forum', 'bbpress') . '">' . _x('Open', 'Open a Forum', 'bbpress') . '</a>';
             }
         }
     }
     // simple hack to show the forum description under the title
     bbp_forum_content($forum->ID);
     return $actions;
 }
예제 #12
0
    public function widget($args, $instance)
    {
        extract($args);
        $instance['title'] ? NULL : ($instance['title'] = '');
        $title = apply_filters('widget_title', $instance['title']);
        $output = $before_widget . "\n";
        if ($title) {
            $output .= $before_title . $title . $after_title;
        }
        ob_start();
        /*  Set tabs-nav order & output it
        /* ------------------------------------ */
        $tabs = array();
        $count = 0;
        $order = array('recent' => $instance['order_recent'], 'popular' => $instance['order_popular'], 'comments' => $instance['order_comments'], 'tags' => $instance['order_tags'], 'topics' => $instance['order_topics'], 'replies' => $instance['order_replies']);
        asort($order);
        foreach ($order as $key => $value) {
            if ($instance[$key . '_enable']) {
                $tabs[] = $key;
                $count++;
            }
        }
        if ($tabs && $count > 1) {
            $output .= $this->_create_tabs($tabs, $count);
        }
        ?>

    <div class="alx-tabs-container">


        <?php 
        if ($instance['recent_enable']) {
            // Recent posts enabled?
            ?>

            <?php 
            $recent = new WP_Query();
            ?>
            <?php 
            $recent->query('showposts=' . $instance["recent_num"] . '&cat=' . $instance["recent_cat_id"] . '&ignore_sticky_posts=1');
            ?>

            <ul id="tab-recent" class="alx-tab group <?php 
            if ($instance['recent_thumbs']) {
                echo 'thumbs-enabled';
            }
            ?>
">
                <?php 
            while ($recent->have_posts()) {
                $recent->the_post();
                ?>
                <li>

                    <?php 
                if ($instance['recent_thumbs']) {
                    // Thumbnails enabled?
                    ?>
                    <div class="tab-item-thumbnail">
                        <a href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    the_title();
                    ?>
">
                            <?php 
                    if (has_post_thumbnail()) {
                        ?>
                                <?php 
                        the_post_thumbnail('thumb-small');
                        ?>
                            <?php 
                    } else {
                        ?>
                                <img src="<?php 
                        echo get_template_directory_uri();
                        ?>
/img/thumb-small.png" alt="<?php 
                        the_title();
                        ?>
" />
                            <?php 
                    }
                    ?>
                            <?php 
                    if (has_post_format('video') && !is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-play"></i></span>';
                    }
                    ?>
                            <?php 
                    if (has_post_format('audio') && !is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>';
                    }
                    ?>
                            <?php 
                    if (is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-star"></i></span>';
                    }
                    ?>
                        </a>
                    </div>
                    <?php 
                }
                ?>

                    <div class="tab-item-inner group">
                        <?php 
                if ($instance['tabs_category']) {
                    ?>
<p class="tab-item-category"><?php 
                    the_category(' / ');
                    ?>
</p><?php 
                }
                ?>
                        <p class="tab-item-title"><a href="<?php 
                the_permalink();
                ?>
" rel="bookmark" title="<?php 
                the_title();
                ?>
"><?php 
                the_title();
                ?>
</a></p>
                        <?php 
                if ($instance['tabs_date']) {
                    ?>
<p class="tab-item-date"><?php 
                    the_time('j M, Y');
                    ?>
</p><?php 
                }
                ?>
                    </div>

                </li>
                <?php 
            }
            ?>
                <?php 
            wp_reset_postdata();
            ?>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>


        <?php 
        if ($instance['popular_enable']) {
            // Popular posts enabled?
            ?>

            <?php 
            $popular = new WP_Query(array('post_type' => array('post'), 'showposts' => $instance['popular_num'], 'cat' => $instance['popular_cat_id'], 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'dsc', 'date_query' => array(array('after' => $instance['popular_time']))));
            ?>
            <ul id="tab-popular" class="alx-tab group <?php 
            if ($instance['popular_thumbs']) {
                echo 'thumbs-enabled';
            }
            ?>
">

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

                    <?php 
                if ($instance['popular_thumbs']) {
                    // Thumbnails enabled?
                    ?>
                    <div class="tab-item-thumbnail">
                        <a href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    the_title();
                    ?>
">
                            <?php 
                    if (has_post_thumbnail()) {
                        ?>
                                <?php 
                        the_post_thumbnail('thumb-small');
                        ?>
                            <?php 
                    } else {
                        ?>
                                <img src="<?php 
                        echo get_template_directory_uri();
                        ?>
/img/thumb-small.png" alt="<?php 
                        the_title();
                        ?>
" />
                            <?php 
                    }
                    ?>
                            <?php 
                    if (has_post_format('video') && !is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-play"></i></span>';
                    }
                    ?>
                            <?php 
                    if (has_post_format('audio') && !is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>';
                    }
                    ?>
                            <?php 
                    if (is_sticky()) {
                        echo '<span class="thumb-icon small"><i class="fa fa-star"></i></span>';
                    }
                    ?>
                        </a>
                    </div>
                    <?php 
                }
                ?>

                    <div class="tab-item-inner group">
                        <?php 
                if ($instance['tabs_category']) {
                    ?>
<p class="tab-item-category"><?php 
                    the_category(' / ');
                    ?>
</p><?php 
                }
                ?>
                        <p class="tab-item-title"><a href="<?php 
                the_permalink();
                ?>
" rel="bookmark" title="<?php 
                the_title();
                ?>
"><?php 
                the_title();
                ?>
</a></p>
                        <?php 
                if ($instance['tabs_date']) {
                    ?>
<p class="tab-item-date"><?php 
                    the_time('j M, Y');
                    ?>
</p><?php 
                }
                ?>
                    </div>

                </li>
                <?php 
            }
            ?>
                <?php 
            wp_reset_postdata();
            ?>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>


        <?php 
        if ($instance['comments_enable']) {
            // Recent comments enabled?
            ?>

            <?php 
            $comments = get_comments(array('number' => $instance["comments_num"], 'status' => 'approve', 'post_status' => 'publish'));
            ?>

            <ul id="tab-comments" class="alx-tab group <?php 
            if ($instance['comments_avatars']) {
                echo 'avatars-enabled';
            }
            ?>
">
                <?php 
            foreach ($comments as $comment) {
                ?>
                <li>

                        <?php 
                if ($instance['comments_avatars']) {
                    // Avatars enabled?
                    ?>
                        <div class="tab-item-avatar">
                            <a href="<?php 
                    echo esc_url(get_comment_link($comment->comment_ID));
                    ?>
">
                                <?php 
                    echo get_avatar($comment->comment_author_email, $size = '96');
                    ?>
                            </a>
                        </div>
                        <?php 
                }
                ?>

                        <div class="tab-item-inner group">
                            <?php 
                $str = explode(' ', get_comment_excerpt($comment->comment_ID));
                $comment_excerpt = implode(' ', array_slice($str, 0, 11));
                if (count($str) > 11 && substr($comment_excerpt, -1) != '.') {
                    $comment_excerpt .= '...';
                }
                ?>
                            <div class="tab-item-name"><?php 
                echo esc_attr($comment->comment_author);
                ?>
 <?php 
                _e('says:', 'hueman');
                ?>
</div>
                            <div class="tab-item-comment"><a href="<?php 
                echo esc_url(get_comment_link($comment->comment_ID));
                ?>
"><?php 
                echo esc_attr($comment_excerpt);
                ?>
</a></div>

                        </div>

                </li>
                <?php 
            }
            ?>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>

        <?php 
        if ($instance['tags_enable']) {
            // Tags enabled?
            ?>

            <ul id="tab-tags" class="alx-tab group">
                <li>
                    <?php 
            wp_tag_cloud();
            ?>
                </li>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>

        <?php 
        if ($instance['topics_enable']) {
            // Recent posts enabled?
            ?>

            <?php 
            switch ($instance["topics_order"]) {
                // Order by most recent replies
                case 'freshness':
                    $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $instance['topics_parent'], 'posts_per_page' => (int) $instance["topics_num"], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC');
                    break;
                    // Order by total number of replies
                // Order by total number of replies
                case 'popular':
                    $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $instance['topics_parent'], 'posts_per_page' => (int) $instance["topics_num"], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_reply_count', 'orderby' => 'meta_value', 'order' => 'DESC');
                    break;
                    // Order by which topic was created most recently
                // Order by which topic was created most recently
                case 'newness':
                default:
                    $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $instance['topics_parent'], 'posts_per_page' => (int) $instance["topics_num"], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'order' => 'DESC');
                    break;
            }
            ?>
            <?php 
            $topics = new WP_Query($topics_query);
            ?>

            <ul id="tab-topics" class="alx-tab group">
                <?php 
            while ($topics->have_posts()) {
                $topics->the_post();
                ?>
                <li>

                    <div class="tab-item-inner group">
                        <?php 
                if ($instance['tabs_category']) {
                    ?>
<p class="tab-item-category"><?php 
                    the_category(' / ');
                    ?>
</p><?php 
                }
                ?>
                        <p class="tab-item-title"><a href="<?php 
                the_permalink();
                ?>
" rel="bookmark" title="<?php 
                the_title();
                ?>
"><?php 
                the_title();
                ?>
</a></p>
                        <?php 
                if ($instance['tabs_date']) {
                    ?>
<p class="tab-item-date"><?php 
                    the_time('j M, Y');
                    ?>
</p><?php 
                }
                ?>
                    </div>

                </li>
                <?php 
            }
            ?>
                <?php 
            wp_reset_postdata();
            ?>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>

        <?php 
        if ($instance['replies_enable']) {
            // Recent posts enabled?
            ?>

            <?php 
            $replies_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) $instance["replies_num"], 'ignore_sticky_posts' => true, 'no_found_rows' => true);
            ?>
            <?php 
            $replies = new WP_Query($replies_query);
            ?>

            <ul id="tab-replies" class="alx-tab group">
                <?php 
            while ($replies->have_posts()) {
                $replies->the_post();
                ?>
                <li>

                        <?php 
                if ($instance['replies_avatars']) {
                    // Avatars enabled?
                    ?>
                        <div class="tab-item-avatar">
                            <a href="">
                                <?php 
                    echo get_avatar($comment->comment_author_email, $size = '96');
                    ?>
                            </a>
                        </div>
                        <?php 
                }
                ?>

                        <div class="tab-item-inner group">
                            <?php 
                $str = explode(' ', get_comment_excerpt($comment->comment_ID));
                $comment_excerpt = implode(' ', array_slice($str, 0, 11));
                if (count($str) > 11 && substr($comment_excerpt, -1) != '.') {
                    $comment_excerpt .= '...';
                }
                ?>
                            <div class="tab-item-name"><?php 
                echo esc_attr($comment->comment_author);
                ?>
 <?php 
                _e('says:', 'hueman');
                ?>
</div>
                            <div class="tab-item-comment"><a href="<?php 
                echo esc_url(get_comment_link($comment->comment_ID));
                ?>
"><?php 
                echo esc_attr($comment_excerpt);
                ?>
</a></div>

                        </div>

                </li>

                <?php 
            }
            ?>
                <?php 
            wp_reset_postdata();
            ?>
            </ul><!--/.alx-tab-->

        <?php 
        }
        ?>

    </div>

<?php 
        $output .= ob_get_clean();
        $output .= $after_widget . "\n";
        echo $output;
    }
예제 #13
0
// How do we want to order our results?
switch ($order_by) {
    // Order by most recent replies
    case 'freshness':
        $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => (int) $max_shown, 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC');
        break;
        // Order by total number of replies
    // Order by total number of replies
    case 'popular':
        $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => (int) $max_shown, 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_reply_count', 'orderby' => 'meta_value', 'order' => 'DESC');
        break;
        // Order by which topic was created most recently
    // Order by which topic was created most recently
    case 'newness':
    default:
        $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => (int) $max_shown, 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'order' => 'DESC');
        break;
}
// 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($topics_query);
?>
 	<div class="topics-thread">

		<?php 
while ($widget_query->have_posts()) {
    $widget_query->the_post();
    $topic_id = bbp_get_topic_id($widget_query->post->ID);
    $author_link = '';
    // Maybe get the topic author
    $author_link = bbp_get_topic_author_link(array('post_id' => $topic_id, 'type' => 'both', 'size' => 50));
예제 #14
0
파일: group.php 프로젝트: hscale/webento
        /**
         * Output the forums for a group in the edit screens
         *
         * @since bbPress (r3653)
         * @uses bp_get_current_group_id()
         * @uses bbp_get_group_forum_ids()
         * @uses bbp_has_forums()
         * @uses bbp_get_template_part()
         */
        public function display_forums($offset = 0)
        {
            // Allow actions immediately before group forum output
            do_action('bbp_before_group_forum_display');
            // Load up bbPress once
            $bbp = bbpress();
            // Forum data
            $forum_slug = bp_action_variable($offset);
            $forum_ids = bbp_get_group_forum_ids(bp_get_current_group_id());
            $forum_args = array('post__in' => $forum_ids, 'post_parent' => null);
            // Unset global queries
            $bbp->forum_query = new stdClass();
            $bbp->topic_query = new stdClass();
            $bbp->reply_query = new stdClass();
            // Unset global ID's
            $bbp->current_forum_id = 0;
            $bbp->current_topic_id = 0;
            $bbp->current_reply_id = 0;
            $bbp->current_topic_tag_id = 0;
            // Reset the post data
            wp_reset_postdata();
            // Allow admins special views
            $post_status = array(bbp_get_closed_status_id(), bbp_get_public_status_id());
            if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) {
                $post_status = array_merge($post_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()));
            }
            ?>

		<div id="bbpress-forums">

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

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

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

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

						<?php 
                        } else {
                            ?>

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

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

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

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

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

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

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

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

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

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

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

						<?php 
                        } else {
                            ?>

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

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

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

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

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

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

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

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

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

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

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

		</div>

		<?php 
            // Allow actions immediately after group forum output
            do_action('bbp_after_group_forum_display');
        }
예제 #15
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();
        }
    }
예제 #16
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 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'])) {
            // What bbPress post type are we looking for feeds on?
            switch ($query_vars['post_type']) {
                // Forum
                case bbp_get_forum_post_type():
                    // Define local variable(s)
                    $meta_query = array();
                    // Single forum
                    if (isset($query_vars[bbp_get_forum_post_type()])) {
                        // Get the forum by the path
                        $forum = get_page_by_path($query_vars[bbp_get_forum_post_type()], OBJECT, bbp_get_forum_post_type());
                        $forum_id = $forum->ID;
                        // Load up our own query
                        query_posts(array('post_type' => bbp_get_forum_post_type(), 'ID' => $forum_id, 'feed' => true));
                        // Restrict to specific forum ID
                        $meta_query = array(array('key' => '_bbp_forum_id', 'value' => $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' => join(',', 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' => $forum_id, 'post_status' => join(',', 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($query_vars['forum'])) {
                            $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' => join(',', 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 (isset($query_vars[bbp_get_topic_post_type()])) {
                        // Load up our own query
                        query_posts(array('post_type' => bbp_get_topic_post_type(), 'name' => $query_vars[bbp_get_topic_post_type()], 'feed' => true));
                        // 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 (!isset($query_vars[bbp_get_reply_post_type()])) {
                        bbp_display_replies_feed_rss2($the_query);
                    }
                    break;
            }
            // Single Topic Vview
        } elseif (isset($query_vars['bbp_view'])) {
            // Get the view
            $view = $query_vars['bbp_view'];
            // 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;
}
예제 #17
0
/**
* Is the forum closed?
*
* @since 2.0.0 bbPress (r2746)
*
* @param int $forum_id Optional. Forum id
* @param bool $check_ancestors Check if the ancestors are closed (only
*                               if they're a category)
* @uses bbp_get_forum_id() To get the forum ID
* @uses bbp_is_forum_status() To check the forum status
* @return bool True if closed, false if not
*/
function bbp_is_forum_closed($forum_id = 0, $check_ancestors = true)
{
    // Get the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Check if the forum or one of it's ancestors is closed
    $retval = bbp_is_forum_status($forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR');
    return (bool) apply_filters('bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors);
}
    /**
     * 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)
    {
        // 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('pg_replies_widget_title', $settings['title'], $instance, $this->id_base);
        // Note: private and hidden forums will be excluded via the
        // bbp_pre_get_posts_exclude_forums filter and function.
        $query_data = array('post_type' => bbp_get_reply_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => '50');
        //PRIVATE GROUPS Get an array of IDs which the current user has permissions to view
        $allowed_posts = private_groups_get_permitted_post_ids(new WP_Query($query_data));
        // The default forum query with allowed forum ids array added
        $query_data['post__in'] = $allowed_posts;
        //now set max posts
        $query_data['posts_per_page'] = (int) $settings['max_shown'];
        $widget_query = new WP_Query($query_data);
        // 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 ('on' == $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 ('on' == $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 ('on' == $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();
    }
예제 #19
0
/**
 * Is the forum closed?
 *
 * @since bbPress (r2746)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are closed (only
 *                               if they're a category)
 * @uses bbp_get_forum_status() To get the forum status
 * @uses bbp_get_forum_ancestors() To get the forum ancestors
 * @uses bbp_is_forum_category() To check if the forum is a category
 * @uses bbp_is_forum_closed() To check if the forum is closed
 * @return bool True if closed, false if not
 */
function bbp_is_forum_closed($forum_id = 0, $check_ancestors = true)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $retval = bbp_get_closed_status_id() == bbp_get_forum_status($forum_id);
    if (!empty($check_ancestors)) {
        $ancestors = bbp_get_forum_ancestors($forum_id);
        foreach ((array) $ancestors as $ancestor) {
            if (bbp_is_forum_category($ancestor, false) && bbp_is_forum_closed($ancestor, false)) {
                $retval = true;
            }
        }
    }
    return (bool) apply_filters('bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors);
}
예제 #20
0
							<legend><?php 
    esc_html_e('Destination', 'bbpress');
    ?>
</legend>
							<div>
								<?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'post__not_in' => array(bbp_get_topic_id())))) {
        ?>

									<label for="bbp_destination_topic"><?php 
        esc_html_e('Merge with this topic:', 'bbpress');
        ?>
</label>

									<?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_topic_forum_id(bbp_get_topic_id()), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'selected' => -1, 'exclude' => bbp_get_topic_id(), 'select_id' => 'bbp_destination_topic'));
        ?>

								<?php 
    } else {
        ?>

									<label><?php 
        esc_html_e('There are no other topics in this forum to merge with.', 'bbpress');
        ?>
</label>

								<?php 
    }
    ?>
예제 #21
0
파일: activity.php 프로젝트: hscale/webento
 /**
  * Update the activity stream entry when a topic status changes
  *
  * @param int $post_id
  * @param obj $post
  * @uses get_post_type()
  * @uses bbp_get_topic_post_type()
  * @uses bbp_get_topic_id()
  * @uses bbp_is_topic_anonymous()
  * @uses bbp_get_public_status_id()
  * @uses bbp_get_closed_status_id()
  * @uses bbp_get_topic_forum_id()
  * @uses bbp_get_topic_author_id()
  * @return Bail early if not a topic, or topic is by anonymous user
  */
 public function topic_update($topic_id, $post)
 {
     // Bail early if not a topic
     if (get_post_type($post) != bbp_get_topic_post_type()) {
         return;
     }
     $topic_id = bbp_get_topic_id($topic_id);
     // Bail early if topic is by anonymous user
     if (bbp_is_topic_anonymous($topic_id)) {
         return;
     }
     $anonymous_data = array();
     // Action based on new status
     if (in_array($post->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) {
         // Validate topic data
         $forum_id = bbp_get_topic_forum_id($topic_id);
         $topic_author_id = bbp_get_topic_author_id($topic_id);
         $this->topic_create($topic_id, $forum_id, $anonymous_data, $topic_author_id);
     } else {
         $this->topic_delete($topic_id);
     }
 }
예제 #22
0
/**
 * Opens a topic
 *
 * @since 2.0.0 bbPress (r2740)
 *
 * @param int $topic_id Topic id
 * @uses bbp_get_topic() To get the topic
 * @uses do_action() Calls 'bbp_open_topic' with the topic id
 * @uses get_post_meta() To get the previous status
 * @uses delete_post_meta() To delete the previous status meta
 * @uses post_type_supports() To check if revisions are enabled
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses remove_post_type_support() To temporarily remove topic revisions
 * @uses wp_update_post() To update the topic with the new status
 * @uses add_post_type_support() To restore topic revisions
 * @uses do_action() Calls 'bbp_opened_topic' with the topic id
 * @return mixed False or {@link WP_Error} on failure, topic id on success
 */
function bbp_open_topic($topic_id = 0)
{
    // Get topic
    $topic = bbp_get_topic($topic_id);
    if (empty($topic)) {
        return $topic;
    }
    // Bail if not closed
    if (bbp_get_closed_status_id() !== $topic->post_status) {
        return false;
    }
    // Execute pre open code
    do_action('bbp_open_topic', $topic_id);
    // Get previous status
    $topic_status = get_post_meta($topic_id, '_bbp_status', true);
    // If no previous status, default to publish
    if (empty($topic_status)) {
        $topic_status = bbp_get_public_status_id();
    }
    // Set previous status
    $topic->post_status = $topic_status;
    // Remove old status meta
    delete_post_meta($topic_id, '_bbp_status');
    // Toggle revisions off as we are not altering content
    if (post_type_supports(bbp_get_topic_post_type(), 'revisions')) {
        $revisions_removed = true;
        remove_post_type_support(bbp_get_topic_post_type(), 'revisions');
    }
    // Update topic
    $topic_id = wp_update_post($topic);
    // Toggle revisions back on
    if (true === $revisions_removed) {
        $revisions_removed = false;
        add_post_type_support(bbp_get_topic_post_type(), 'revisions');
    }
    // Execute post open code
    do_action('bbp_opened_topic', $topic_id);
    // Return topic_id
    return $topic_id;
}
예제 #23
0
/**
 * The main reply loop. WordPress makes this easy for us
 *
 * @since bbPress (r2553)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses get_option() To get the replies per page option
 * @uses bbp_get_paged() To get the current page value
 * @uses current_user_can() To check if the current user is capable of editing
 *                           others' replies
 * @uses WP_Query To make query and get the replies
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses get_permalink() To get the permalink
 * @uses add_query_arg() To add custom args to the url
 * @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args
 * @uses paginate_links() To paginate the links
 * @uses apply_filters() Calls 'bbp_has_replies' with
 *                        bbPres::reply_query::have_posts()
 *                        and bbPres::reply_query
 * @return object Multidimensional array of reply information
 */
function bbp_has_replies($args = '')
{
    global $wp_rewrite;
    /** Defaults **************************************************************/
    // Other defaults
    $default_reply_search = !empty($_REQUEST['rs']) ? $_REQUEST['rs'] : false;
    $default_post_parent = bbp_is_single_topic() ? bbp_get_topic_id() : 'any';
    $default_post_type = bbp_is_single_topic() && bbp_show_lead_topic() ? bbp_get_reply_post_type() : array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $default_thread_replies = (bool) (bbp_is_single_topic() && bbp_thread_replies());
    // Default query args
    $default = array('post_type' => $default_post_type, 'post_parent' => $default_post_parent, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'ASC', 'hierarchical' => $default_thread_replies, 'ignore_sticky_posts' => true, 's' => $default_reply_search);
    // 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_replies')) {
            $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_replies');
    // Set posts_per_page value if replies are threaded
    $replies_per_page = $r['posts_per_page'];
    if (true === $r['hierarchical']) {
        $r['posts_per_page'] = -1;
    }
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    $bbp->reply_query = new WP_Query($r);
    // Add pagination values to query object
    $bbp->reply_query->posts_per_page = $replies_per_page;
    $bbp->reply_query->paged = $r['paged'];
    // Never home, regardless of what parse_query says
    $bbp->reply_query->is_home = false;
    // Reset is_single if single topic
    if (bbp_is_single_topic()) {
        $bbp->reply_query->is_single = true;
    }
    // Only add reply to if query returned results
    if ((int) $bbp->reply_query->found_posts) {
        // Get reply to for each reply
        foreach ($bbp->reply_query->posts as &$post) {
            // Check for reply post type
            if (bbp_get_reply_post_type() === $post->post_type) {
                $reply_to = bbp_get_reply_to($post->ID);
                // Make sure it's a reply to a reply
                if (empty($reply_to) || bbp_get_reply_topic_id($post->ID) === $reply_to) {
                    $reply_to = 0;
                }
                // Add reply_to to the post object so we can walk it later
                $post->reply_to = $reply_to;
            }
        }
    }
    // Only add pagination if query returned results
    if ((int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page) {
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // User's replies
            if (bbp_is_single_user_replies()) {
                $base = bbp_get_user_replies_created_url(bbp_get_displayed_user_id());
                // Root profile page
            } elseif (bbp_is_single_user()) {
                $base = bbp_get_user_profile_url(bbp_get_displayed_user_id());
                // Page or single post
            } elseif (is_page() || is_single()) {
                $base = get_permalink();
                // Single topic
            } else {
                $base = get_permalink(bbp_get_topic_id());
            }
            $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty permalinks
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Figure out total pages
        if (true === $r['hierarchical']) {
            $walker = new BBP_Walker_Reply();
            $total_pages = ceil((int) $walker->get_number_of_root_elements($bbp->reply_query->posts) / (int) $replies_per_page);
        } else {
            $total_pages = ceil((int) $bbp->reply_query->found_posts / (int) $replies_per_page);
            // Add pagination to query object
            $bbp->reply_query->pagination_links = paginate_links(apply_filters('bbp_replies_pagination', array('base' => $base, 'format' => '', 'total' => $total_pages, 'current' => (int) $bbp->reply_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1, 'add_args' => bbp_get_view_all() ? array('view' => 'all') : false)));
            // Remove first page from pagination
            if ($wp_rewrite->using_permalinks()) {
                $bbp->reply_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links);
            } else {
                $bbp->reply_query->pagination_links = str_replace('&#038;paged=1', '', $bbp->reply_query->pagination_links);
            }
        }
    }
    // Return object
    return apply_filters('bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query);
}
예제 #24
0
 /**
  * Register the post statuses used by bbPress
  *
  * We do some manipulation of the 'trash' status so trashed topics and
  * replies can be viewed from within the theme.
  *
  * @since bbPress (r2727)
  * @uses register_post_status() To register post statuses
  * @uses $wp_post_statuses To modify trash and private statuses
  * @uses current_user_can() To check if the current user is capable &
  *                           modify $wp_post_statuses accordingly
  */
 public static function register_post_statuses()
 {
     // Closed
     register_post_status(bbp_get_closed_status_id(), apply_filters('bbp_register_closed_post_status', array('label' => _x('Closed', 'post', 'bbpress'), 'label_count' => _nx_noop('Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress'), 'public' => true, 'show_in_admin_all' => true)));
     // Spam
     register_post_status(bbp_get_spam_status_id(), apply_filters('bbp_register_spam_post_status', array('label' => _x('Spam', 'post', 'bbpress'), 'label_count' => _nx_noop('Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Orphan
     register_post_status(bbp_get_orphan_status_id(), apply_filters('bbp_register_orphan_post_status', array('label' => _x('Orphan', 'post', 'bbpress'), 'label_count' => _nx_noop('Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Hidden
     register_post_status(bbp_get_hidden_status_id(), apply_filters('bbp_register_hidden_post_status', array('label' => _x('Hidden', 'post', 'bbpress'), 'label_count' => _nx_noop('Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress'), 'private' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true)));
     /**
      * Trash fix
      *
      * We need to remove the internal arg and change that to
      * protected so that the users with 'view_trash' cap can view
      * single trashed topics/replies in the front-end as wp_query
      * doesn't allow any hack for the trashed topics to be viewed.
      */
     global $wp_post_statuses;
     if (!empty($wp_post_statuses['trash'])) {
         // User can view trash so set internal to false
         if (current_user_can('view_trash')) {
             $wp_post_statuses['trash']->internal = false;
             $wp_post_statuses['trash']->protected = true;
             // User cannot view trash so set internal to true
         } else {
             $wp_post_statuses['trash']->internal = true;
         }
     }
 }
예제 #25
0
/**
 * Opens a topic
 *
 * @since bbPress (r2740)
 *
 * @param int $topic_id Topic id
 * @uses bbp_get_topic() To get the topic
 * @uses do_action() Calls 'bbp_open_topic' with the topic id
 * @uses get_post_meta() To get the previous status
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To update the topic with the new status
 * @uses do_action() Calls 'bbp_opened_topic' with the topic id
 * @return mixed False or {@link WP_Error} on failure, topic id on success
 */
function bbp_open_topic($topic_id = 0)
{
    // Get topic
    $topic = bbp_get_topic($topic_id);
    if (empty($topic)) {
        return $topic;
    }
    // Bail if already open
    if (bbp_get_closed_status_id() !== $topic->post_status) {
        return false;
    }
    // Execute pre open code
    do_action('bbp_open_topic', $topic_id);
    // Get previous status
    $topic_status = get_post_meta($topic_id, '_bbp_status', true);
    // Set previous status
    $topic->post_status = $topic_status;
    // Remove old status meta
    delete_post_meta($topic_id, '_bbp_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update topic
    $topic_id = wp_update_post($topic);
    // Execute post open code
    do_action('bbp_opened_topic', $topic_id);
    // Return topic_id
    return $topic_id;
}
예제 #26
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();
    }
예제 #27
0
파일: tools.php 프로젝트: joeyblake/bbpress
/**
 * Recount topic voices
 *
 * @since 2.0.0 bbPress (r2613)
 *
 * @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_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_get_closed_status_id() To get the closed status id
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_topic_voice_count()
{
    // Define variables
    $bbp_db = bbp_db();
    $statement = __('Counting the number of voices in each topic&hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_voice_count';";
    if (is_wp_error($bbp_db->query($sql_delete))) {
        return array(1, sprintf($statement, $result));
    }
    // Post types and status
    $tpt = bbp_get_topic_post_type();
    $rpt = bbp_get_reply_post_type();
    $pps = bbp_get_public_status_id();
    $cps = bbp_get_closed_status_id();
    $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (\n\t\t\tSELECT `postmeta`.`meta_value`, '_bbp_voice_count', COUNT(DISTINCT `post_author`) as `meta_value`\n\t\t\t\tFROM `{$bbp_db->posts}` AS `posts`\n\t\t\t\tLEFT JOIN `{$bbp_db->postmeta}` AS `postmeta`\n\t\t\t\t\tON `posts`.`ID` = `postmeta`.`post_id`\n\t\t\t\t\tAND `postmeta`.`meta_key` = '_bbp_topic_id'\n\t\t\t\tWHERE `posts`.`post_type` IN ( '{$tpt}', '{$rpt}' )\n\t\t\t\t\tAND `posts`.`post_status` IN ( '{$pps}', '{$cps}' )\n\t\t\t\t\tAND `posts`.`post_author` != '0'\n\t\t\t\tGROUP BY `postmeta`.`meta_value`);";
    if (is_wp_error($bbp_db->query($sql))) {
        return array(2, sprintf($statement, $result));
    }
    return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
function pg_get_user_unread($user_id = 0)
{
    // Default to the displayed user
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // If user has unread topics, load them
    $read_ids = (string) get_user_meta($user_id, '_bbp_mar_read_ids', true);
    $read_ids = (array) explode(',', $read_ids);
    $read_ids = array_filter($read_ids);
    if (!empty($read_ids)) {
        //so we have unreads, so need to create a list of unread that the user can see
        //so first we create a list of topics the user can see
        global $wpdb;
        $topic = bbp_get_topic_post_type();
        $post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$topic}'");
        //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
        $allowed_posts = check_private_groups_topic_ids($post_ids);
        //now we need to take out of that list all read topics for that user
        foreach ($read_ids as $read_id) {
            if (($key = array_search($read_id, $allowed_posts)) !== false) {
                unset($allowed_posts[$key]);
            }
        }
        //so now we have an allowed list that has only topics the user can see, but not topics the user has read
        //now we use the code from bbp_has_topics to run the list - we can't call it as PG already filters the original function
        global $wp_rewrite;
        /** Defaults **************************************************************/
        // Other defaults
        $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false;
        $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search;
        $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
        // Default argument array
        $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false, 'post__in' => $allowed_posts);
        // 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';
        }
        // Maybe query for topic tags
        if (bbp_is_topic_tag()) {
            $default['term'] = bbp_get_topic_tag_slug();
            $default['taxonomy'] = bbp_get_topic_tag_tax_id();
        }
        /** Setup *****************************************************************/
        // Parse arguments against default values
        //stopped to prevent parsing
        //$r = bbp_parse_args( $args, $default, 'has_topics' );
        // Get bbPress
        $bbp = bbpress();
        // Call the query
        //now query the original default
        $bbp->topic_query = new WP_Query($default);
        // Set post_parent back to 0 if originally set to 'any'
        if ('any' === $r['post_parent']) {
            $r['post_parent'] = 0;
        }
        // Limited the number of pages shown
        if (!empty($r['max_num_pages'])) {
            $bbp->topic_query->max_num_pages = $r['max_num_pages'];
        }
        /** Stickies **************************************************************/
        // Put sticky posts at the top of the posts array
        if (!empty($r['show_stickies']) && $r['paged'] <= 1) {
            // Get super stickies and stickies in this forum
            $stickies = bbp_get_super_stickies();
            // Get stickies for current forum
            if (!empty($r['post_parent'])) {
                $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent']));
            }
            // Remove any duplicate stickies
            $stickies = array_unique($stickies);
            // We have stickies
            if (is_array($stickies) && !empty($stickies)) {
                // Start the offset at -1 so first sticky is at correct 0 offset
                $sticky_offset = -1;
                // Loop over topics and relocate stickies to the front.
                foreach ($stickies as $sticky_index => $sticky_ID) {
                    // Get the post offset from the posts array
                    $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID');
                    // Continue if no post offsets
                    if (empty($post_offsets)) {
                        continue;
                    }
                    // Loop over posts in current query and splice them into position
                    foreach (array_keys($post_offsets) as $post_offset) {
                        $sticky_offset++;
                        $sticky = $bbp->topic_query->posts[$post_offset];
                        // Remove sticky from current position
                        array_splice($bbp->topic_query->posts, $post_offset, 1);
                        // Move to front, after other stickies
                        array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky));
                        // Cleanup
                        unset($stickies[$sticky_index]);
                        unset($sticky);
                    }
                    // Cleanup
                    unset($post_offsets);
                }
                // Cleanup
                unset($sticky_offset);
                // If any posts have been excluded specifically, Ignore those that are sticky.
                if (!empty($stickies) && !empty($r['post__not_in'])) {
                    $stickies = array_diff($stickies, $r['post__not_in']);
                }
                // Fetch sticky posts that weren't in the query results
                if (!empty($stickies)) {
                    // Query to use in get_posts to get sticky posts
                    $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies);
                    // Cleanup
                    unset($stickies);
                    // Conditionally exclude private/hidden forum ID's
                    $exclude_forum_ids = bbp_exclude_forum_ids('array');
                    if (!empty($exclude_forum_ids)) {
                        $sticky_query['post_parent__not_in'] = $exclude_forum_ids;
                    }
                    // What are the default allowed statuses (based on user caps)
                    if (bbp_get_view_all()) {
                        $sticky_query['post_status'] = $r['post_status'];
                        // Lean on the 'perm' query var value of 'readable' to provide statuses
                    } else {
                        $sticky_query['post_status'] = $r['perm'];
                    }
                    // Get all stickies
                    $sticky_posts = get_posts($sticky_query);
                    if (!empty($sticky_posts)) {
                        // Get a count of the visible stickies
                        $sticky_count = count($sticky_posts);
                        // Merge the stickies topics with the query topics .
                        $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts);
                        // Adjust loop and counts for new sticky positions
                        $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
                        $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
                        // Cleanup
                        unset($sticky_posts);
                    }
                }
            }
        }
        // If no limit to posts per page, set it to the current post_count
        if (-1 === $r['posts_per_page']) {
            $r['posts_per_page'] = $bbp->topic_query->post_count;
        }
        // Add pagination values to query object
        $bbp->topic_query->posts_per_page = $r['posts_per_page'];
        $bbp->topic_query->paged = $r['paged'];
        // Only add pagination if query returned results
        if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) {
            // Limit the number of topics shown based on maximum allowed pages
            if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) {
                $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
            }
            // If pretty permalinks are enabled, make our pagination pretty
            if ($wp_rewrite->using_permalinks()) {
                // User's topics
                if (bbp_is_single_user_topics()) {
                    $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id());
                    // User's favorites
                } elseif (bbp_is_favorites()) {
                    $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id());
                    // User's subscriptions
                } elseif (bbp_is_subscriptions()) {
                    $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id());
                    // Root profile page
                } elseif (bbp_is_single_user()) {
                    $base = bbp_get_user_profile_url(bbp_get_displayed_user_id());
                    // View
                } elseif (bbp_is_single_view()) {
                    $base = bbp_get_view_url();
                    // Topic tag
                } elseif (bbp_is_topic_tag()) {
                    $base = bbp_get_topic_tag_link();
                    // Page or single post
                } elseif (is_page() || is_single()) {
                    $base = get_permalink();
                    // Forum archive
                } elseif (bbp_is_forum_archive()) {
                    $base = bbp_get_forums_url();
                    // Topic archive
                } elseif (bbp_is_topic_archive()) {
                    $base = bbp_get_topics_url();
                    // Default
                } else {
                    $base = get_permalink((int) $r['post_parent']);
                }
                // Use pagination base
                $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
                // Unpretty pagination
            } else {
                $base = add_query_arg('paged', '%#%');
            }
            // Pagination settings with filter
            $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1));
            // Add pagination to query object
            $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination);
            // Remove first page from pagination
            $bbp->topic_query->pagination_links = str_replace($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links);
        }
        // Return object
        return apply_filters('pg_get_user_unread', $bbp->topic_query->have_posts(), $bbp->topic_query);
    }
    //if no unread
    return bbp_has_topics();
    // default query
}