/** * 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)); } }
function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) { global $bp; $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page; $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page; $this->type = $type; $this->search_terms = $search_terms; $this->forum_id = $forum_id; 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 ) ); 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 ) ); 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 ) ); 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 ) ); 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 { if ( $forum_id ) { $topic_count = bp_forums_get_forum( $forum_id ); $topic_count = (int)$topic_count->topics; } else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) { $topic_count = (int)groups_total_public_forum_topic_count( $type ); } else { $topic_count = count( $this->topics ); } 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( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies ); $this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies ); if ( !$no_stickies ) { // Place stickies at the top - not sure why bbPress doesn't do this? foreach( (array)$this->topics as $topic ) { if ( 1 == (int)$topic->topic_sticky ) { $stickies[] = $topic; } else { $standard[] = $topic; } } $this->topics = array_merge( (array)$stickies, (array)$standard ); } // 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' => '←', 'next_text' => '→', 'mid_size' => 1 ) ); } }