Пример #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_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() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', '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('&paged=1', '', $bbp->reply_query->pagination_links);
            }
        }
    }
    // Return object
    return apply_filters('bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query);
}
Пример #2
0
/**
 * Output the link to the user's replies
 *
 * @since 2.2.0 bbPress (r4225)
 *
 * @param int $user_id Optional. User id
 * @uses bbp_get_favorites_permalink() To get the favorites permalink
 */
function bbp_user_replies_created_url($user_id = 0)
{
    echo esc_url(bbp_get_user_replies_created_url($user_id));
}
Пример #3
0
 /**
  * @covers ::bbp_get_user_replies_created_url
  */
 public function test_bbp_get_user_replies_created_url()
 {
     // Pretty permalinks
     $this->set_permalink_structure('/%postname%/');
     $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/forums/users/' . $this->keymaster_userdata->user_nicename . '/replies/';
     // String.
     $this->assertSame($replies_created_url, bbp_get_user_replies_created_url($this->keymaster_id));
     // Ugly permalinks
     $this->set_permalink_structure();
     $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user='******'&bbp_reps=1';
     // String.
     $this->assertSame($replies_created_url, bbp_get_user_replies_created_url($this->keymaster_id));
 }
Пример #4
0
 function cb_bbp_author_details($cb_author_id, $cb_desc = true)
 {
     $cb_author_email = get_the_author_meta('publicemail', $cb_author_id);
     $cb_author_name = get_the_author_meta('display_name', $cb_author_id);
     $cb_author_position = get_the_author_meta('position', $cb_author_id);
     $cb_author_tw = get_the_author_meta('twitter', $cb_author_id);
     $cb_author_go = get_the_author_meta('googleplus', $cb_author_id);
     $cb_author_www = get_the_author_meta('url', $cb_author_id);
     $cb_author_desc = get_the_author_meta('description', $cb_author_id);
     $cb_author_posts = count_user_posts($cb_author_id);
     $cb_author_output = NULL;
     $cb_author_output .= '<div class="cb-author-details cb-bbp clearfix"><div class="cb-mask"><a href="' . bbp_get_user_profile_url() . '" title="' . bbp_get_displayed_user_field('display_name') . '" rel="me">' . get_avatar(bbp_get_displayed_user_field('user_email', 'raw'), apply_filters('bbp_single_user_details_avatar_size', 150)) . '</a></div><div class="cb-meta"><h3><a href="' . bbp_get_user_profile_url() . '" title="' . bbp_get_displayed_user_field('display_name') . '">' . $cb_author_name . '</a></h3>';
     if ($cb_author_position != NULL) {
         $cb_author_output .= '<div class="cb-author-position">' . $cb_author_position . '</div>';
     }
     if ($cb_author_desc != NULL && $cb_desc == true) {
         $cb_author_output .= '<p class="cb-author-bio">' . $cb_author_desc . '</p>';
     }
     if ($cb_author_email != NULL || $cb_author_www != NULL || $cb_author_tw != NULL || $cb_author_go != NULL) {
         $cb_author_output .= '<div class="cb-author-page-contact">';
     }
     if ($cb_author_email != NULL) {
         $cb_author_output .= '<a href="mailto:' . $cb_author_email . '"><i class="icon-envelope-alt cb-tip-bot" title="' . __('Email', 'cubell') . '"></i></a>';
     }
     if ($cb_author_www != NULL) {
         $cb_author_output .= ' <a href="' . $cb_author_www . '" target="_blank"><i class="icon-link cb-tip-bot" title="' . __('Website', 'cubell') . '"></i></a> ';
     }
     if ($cb_author_tw != NULL) {
         $cb_author_output .= ' <a href="//www.twitter.com/' . $cb_author_tw . '" target="_blank" ><i class="icon-twitter cb-tip-bot" title="Twitter"></i></a>';
     }
     if ($cb_author_go != NULL) {
         $cb_author_output .= ' <a href="' . $cb_author_go . '" rel="publisher" target="_top" title="Google+" class="cb-googleplus cb-tip-bot" ><img src="//ssl.gstatic.com/images/icons/gplus-32.png"  data-src-retina="//ssl.gstatic.com/images/icons/gplus-64.png" alt="Google+" ></a>';
     }
     if ($cb_author_email != NULL || $cb_author_www != NULL || $cb_author_go != NULL || $cb_author_tw != NULL) {
         $cb_author_output .= '</div>';
     }
     $cb_author_output .= '<div id="cb-user-nav"><ul>';
     if (bbp_is_single_user_replies()) {
         $cb_user_current = 'current';
     }
     $cb_author_output .= '<li class="';
     if (bbp_is_single_user_topics()) {
         $cb_author_output .= 'current';
     }
     $cb_author_output .= '"><span class="bbp-user-topics-created-link"><a href="' . bbp_get_user_topics_created_url() . '">' . __('Topics Started', 'bbpress') . '</a></span></li>';
     $cb_author_output .= '<li class="';
     if (bbp_is_single_user_replies()) {
         $cb_author_output .= 'current';
     }
     $cb_author_output .= '"><span class="bbp-user-replies-created-link"><a href="' . bbp_get_user_replies_created_url() . '">' . __('Replies Created', 'bbpress') . '</a></span></li>';
     if (bbp_is_favorites_active()) {
         $cb_author_output .= '<li class="';
         if (bbp_is_favorites()) {
             $cb_author_output .= 'current';
         }
         $cb_author_output .= '"><span class="bbp-user-favorites-link"><a href="' . bbp_get_favorites_permalink() . '">' . __('Favorites', 'bbpress') . '</a></span></li>';
     }
     if (bbp_is_user_home() || current_user_can('edit_users')) {
         if (bbp_is_subscriptions_active()) {
             $cb_author_output .= '<li class="';
             if (bbp_is_subscriptions()) {
                 $cb_author_output .= 'current';
             }
             $cb_author_output .= '"><span class="bbp-user-subscriptions-link"><a href="' . bbp_get_subscriptions_permalink() . '">' . __('Subscriptions', 'bbpress') . '</a></span></li>';
         }
         $cb_author_output .= '<li class="';
         if (bbp_is_single_user_edit()) {
             $cb_author_output .= 'current';
         }
         $cb_author_output .= '"><span class="bbp-user-edit-link"><a href="' . bbp_get_user_profile_edit_url() . '">' . __('Edit', 'bbpress') . '</a></span></li>';
     }
     $cb_author_output .= '</ul></div><!-- #cb-user-nav -->';
     $cb_author_output .= '</div></div>';
     return $cb_author_output;
 }
Пример #5
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 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());
    }
    $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;
    // 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 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();
                // User's replies
            } elseif (bbp_is_single_user_replies()) {
                $base = bbp_get_user_replies_created_url(bbp_get_displayed_user_id());
                // 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', '%#%');
        }
        // Add pagination to query object
        $bbp->reply_query->pagination_links = paginate_links(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' => '&larr;', 'next_text' => '&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);
}
Пример #6
0
 /**
  * Set up the admin bar
  *
  * @since 2.1.0 bbPress (r3552)
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // If BuddyPress is network activated and bbPress is
         // not activated on a the root blog but on any child one
         if (!bp_is_root_blog()) {
             $user_id = bbp_get_current_user_id();
             $my_account_link = bbp_get_user_profile_url($user_id);
             $my_topics_link = bbp_get_user_topics_created_url($user_id);
             $my_replies_link = bbp_get_user_replies_created_url($user_id);
             $my_favorites_link = bbp_get_favorites_permalink($user_id);
             $my_subscriptions_link = bbp_get_subscriptions_permalink($user_id);
         } else {
             // Setup the logged in user variables
             $user_domain = bp_loggedin_user_domain();
             $forums_link = trailingslashit($user_domain . $this->slug);
             $my_account_link = trailingslashit($forums_link);
             $my_topics_link = trailingslashit($forums_link . bbp_get_topic_archive_slug());
             $my_replies_link = trailingslashit($forums_link . bbp_get_reply_archive_slug());
             $my_favorites_link = trailingslashit($forums_link . bbp_get_user_favorites_slug());
             $my_subscriptions_link = trailingslashit($forums_link . bbp_get_user_subscriptions_slug());
         }
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Forums', 'bbpress'), 'href' => $my_account_link);
         // Topics
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-topics', 'title' => __('Topics Started', 'bbpress'), 'href' => $my_topics_link);
         // Replies
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-replies', 'title' => __('Replies Created', 'bbpress'), 'href' => $my_replies_link);
         // Favorites
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorite Topics', 'bbpress'), 'href' => $my_favorites_link);
         // Subscriptions
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-subscriptions', 'title' => __('Subscribed Topics', 'bbpress'), 'href' => $my_subscriptions_link);
     }
     parent::setup_admin_bar($wp_admin_nav);
 }