function bp_get_forum_topic_count_for_user( $user_id = false ) { return apply_filters( 'bp_get_forum_topic_count_for_user', bp_forums_total_topic_count_for_user( $user_id ) ); }
/** * Constructor method. * * @param string $type The 'type' is the sort order/kind. 'newest', * 'popular', 'unreplied', 'tags'. * @param int $forum_id The ID of the forum for which topics are being * queried. * @param int $user_id The ID of the user to whom topics should be * limited. Pass false to remove this filter. * @param int $page The number of the page being requested. * @param int $per_page The number of items being requested perpage. * @param string $no_stickies Requested sticky format. * @param string $search_terms Filter results by a string. * @param int $offset Optional. Offset results by a given numeric value. * @param int $number Optional. Total number of items to retrieve. */ function __construct($type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false) { global $bp; $this->pag_page = $page; $this->pag_num = $per_page; $this->type = $type; $this->search_terms = $search_terms; $this->forum_id = $forum_id; $this->offset = $offset; $this->number = $number; switch ($type) { case 'newest': default: $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number)); break; case 'popular': $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number)); break; case 'unreplied': $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number)); break; case 'tags': $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number)); break; } $this->topics = apply_filters('bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies); if (!(int) $this->topics) { $this->topic_count = 0; $this->total_topic_count = 0; } else { // Get a total topic count, for use in pagination. This value will differ // depending on scope if (!empty($forum_id)) { // Group forums $topic_count = bp_forums_get_forum($forum_id); $topic_count = (int) $topic_count->topics; } else { if (!empty($bp->groups->current_group)) { $topic_count = (int) groups_total_public_forum_topic_count($type); } else { if (bp_is_user_forums_started() || bp_is_directory() && $user_id) { // This covers the case of Profile > Forums > Topics Started, as // well as Forum Directory > My Topics $topic_count = bp_forums_total_topic_count_for_user(bp_displayed_user_id(), $type); } else { if (bp_is_user_forums_replied_to()) { // Profile > Forums > Replied To $topic_count = bp_forums_total_replied_count_for_user(bp_displayed_user_id(), $type); } else { if ('tags' == $type) { $tag = bb_get_tag($search_terms); $topic_count = $tag->count; } else { // For forum directories (All Topics), get a true count $status = bp_current_user_can('bp_moderate') ? 'all' : 'public'; // todo: member-of $topic_count = (int) groups_total_forum_topic_count($status, $search_terms); } } } } } if (!$max || $max >= $topic_count) { $this->total_topic_count = $topic_count; } else { $this->total_topic_count = (int) $max; } if ($max) { if ($max >= count($this->topics)) { $this->topic_count = count($this->topics); } else { $this->topic_count = (int) $max; } } else { $this->topic_count = count($this->topics); } } $this->topic_count = apply_filters_ref_array('bp_forums_template_topic_count', array($this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies)); $this->total_topic_count = apply_filters_ref_array('bp_forums_template_total_topic_count', array($this->total_topic_count, $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies)); // Fetch extra information for topics, so we don't have to query inside the loop $this->topics = bp_forums_get_topic_extras($this->topics); if ((int) $this->total_topic_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg(array('p' => '%#%', 'n' => $this->pag_num)), 'format' => '', 'total' => ceil((int) $this->total_topic_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Forum topic pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Forum topic pagination next text', 'buddypress'), 'mid_size' => 1)); } }
/** * User statistics function - gets member topics * * @since 1.0 */ function status_member_profile_stats_get_member_topics() { if (!bp_is_active('forums')) { return; } $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); $total_count = bp_forums_total_topic_count_for_user($user_id); if ($total_count == 0) { $content = '<li>' . __(' No forum topics', 'status') . '</li>'; } else { if ($total_count == 1) { $content = '<li><span class="topic-count">' . $total_count . '</span>' . __(' forum topic', 'status') . '</li>'; } else { $content = '<li><span class="topic-count">' . $total_count . '</span>' . __(' forum topics', 'status') . '</li>'; } } return apply_filters('status_member_profile_stats_get_member_posts', $content, $total_count); }