Skip to:
Content

BuddyPress.org

Changeset 2194


Ignore:
Timestamp:
12/17/2009 12:24:10 PM (16 years ago)
Author:
apeatling
Message:

Fixing forum filtering and added "My Topics" tab to the forums directory.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums.php

    r2168 r2194  
    128128}
    129129
    130 function bp_forums_get_forum_topicpost_count( $forum_id ) {
    131     global $wpdb, $bbdb;
    132 
    133     do_action( 'bbpress_init' );
    134 
    135     /* Need to find a bbPress function that does this */
    136     return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
    137 }
    138 
    139130/* Topic Functions */
    140131
     
    147138        'type' => 'newest',
    148139        'forum_id' => false,
     140        'user_id' => false,
    149141        'page' => 1,
    150142        'per_page' => 15,
     
    159151    switch ( $type ) {
    160152        case 'newest':
    161             $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
    162             $topics = $query->results;
    163         break;
    164 
    165         case 'popular':
    166             $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
     153            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
    167154            $topics =& $query->results;
    168155        break;
    169156
    170         case 'unreplied':
    171             $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
     157        case 'popular':
     158            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
    172159            $topics =& $query->results;
    173160        break;
    174161
    175         case 'personal':
    176             $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'per_page' => $per_page, 'page' => $page, 'topic_author_id' => $bp->loggedin_user->id, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_recent_user_threads' );
     162        case 'unreplied':
     163            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
    177164            $topics =& $query->results;
    178165        break;
    179166
    180167        case 'tag':
    181             $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
     168            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
    182169            $topics =& $query->results;
    183170        break;
     
    319306}
    320307
     308function bp_forums_total_topic_count() {
     309    do_action( 'bbpress_init' );
     310
     311    $query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => false, 'count' => true ) );
     312    return $query->count;
     313}
     314
     315function bp_forums_total_topic_count_for_user( $user_id = false ) {
     316    global $bp;
     317
     318    do_action( 'bbpress_init' );
     319
     320    if ( !$user_id )
     321        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     322
     323    $query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => false, 'count' => true ) );
     324    return $query->count;
     325}
     326
    321327/* Post Functions */
    322328
  • trunk/bp-forums/bp-forums-templatetags.php

    r2168 r2194  
    1919    var $order;
    2020
    21     function BP_Forums_Template_Forum( $type, $forum_id, $page, $per_page, $max, $no_stickies, $filter ) {
     21    function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
    2222        global $bp;
    2323
     
    3131        switch ( $type ) {
    3232            case 'newest': default:
    33                 $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'filter' => $filter, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
     33                $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' => $show_stickies ) );
    3434                break;
    3535
    3636            case 'popular':
    37                 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'popular', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
     37                $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' => $show_stickies ) );
    3838                break;
    3939
    4040            case 'unreplied':
    41                 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'unreplied', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
     41                $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' => $show_stickies ) );
    4242                break;
    4343
    44             case 'personal':
    45                 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'personal', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
    46                 break;
    47 
    4844            case 'tag':
    49                 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'tag', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
     45                $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tag', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) );
    5046                break;
    5147        }
     
    158154        'type' => 'newest',
    159155        'forum_id' => false,
     156        'user_id' => false,
    160157        'page' => 1,
    161158        'per_page' => 15,
    162159        'max' => false,
    163160        'no_stickies' => false,
    164         'filter' => false
     161        'search_terms' => false
    165162    );
    166163
     
    170167    /* If we're in a single group, set this group's forum_id */
    171168    if ( !$forum_id && $bp->groups->current_group ) {
    172         $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
     169        $bp->groups->current_group->forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    173170
    174171        /* If it turns out there is no forum for this group, return false so we don't fetch all global topics */
    175         if ( !$forum_id )
     172        if ( !$bp->groups->current_group->forum_id )
    176173            return false;
    177174    }
     
    179176    /* If we're viewing a tag in the directory, let's auto set the filter to the tag name */
    180177    if ( $bp->is_directory && 'tag' == $type && !empty( $bp->action_variables[0] ) )
    181         $filter = $bp->action_variables[0];
    182 
    183     /* If $_GET['s'] is set, let's auto populate the filter var */
     178        $search_terms = $bp->action_variables[0];
     179
     180    /* If $_GET['fs'] is set, let's auto populate the search_terms var */
    184181    if ( $bp->is_directory && !empty( $_GET['fs'] ) )
    185         $filter = $_GET['fs'];
    186 
    187     $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $page, $per_page, $max, $no_stickies, $filter );
     182        $search_terms = $_GET['fs'];
     183
     184    $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
    188185
    189186    return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
     
    935932
    936933function bp_directory_forums_search_form() {
    937     global $bp; ?>
    938     <form action="<?php echo $bp->root_domain . '/' . $bp->forums->slug . '/'; ?>" method="get" id="search-forums-form">
    939         <label><input type="text" name="fs" id="forums_search" value="<?php if ( isset( $_GET['fs'] ) ) { echo attribute_escape( $_GET['fs'] ); } else { _e( 'Search anything...', 'buddypress' ); } ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
    940         <input type="submit" id="forums_search_submit" name="submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
     934    global $bp;
     935
     936    $search_value = __( 'Search anything...', 'buddypress' );
     937    if ( !empty( $_REQUEST['fs'] ) )
     938        $search_value = $_REQUEST['fs'];
     939
     940    else if ( !empty( $_COOKIE['bp-forums-search-terms'] ) && 'false' != $_COOKIE['bp-forums-search-terms'] )
     941        $search_value = $_COOKIE['bp-forums-search-terms'];
     942
     943?>
     944    <form action="" method="get" id="search-forums-form">
     945        <label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($search_value) ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
     946        <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
    941947    </form>
    942948<?php
    943949}
    944 
    945950function bp_forum_permalink() {
    946951    echo bp_get_forum_permalink();
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r2191 r2194  
    138138
    139139    /* Sort out type ordering */
    140     if ( 'active' != $filter && 'newest' != $filter && 'alphabetical' != $filter )
     140    if ( 'active' != $filter && 'popular' != $filter && 'unreplied' != $filter )
    141141        $type = 'active';
    142142
     
    146146        $bp->ajax_querystring .= '&search_terms=' . $search_terms;
    147147
    148     if ( !$type || ( 'all' != $type && 'myblogs' != $type ) )
     148    if ( !$type || ( 'all' != $type && 'mytopics' != $type ) )
    149149        $type = 'all';
    150150
    151     if ( ( 'myblogs' == $type ) && !is_user_logged_in() )
     151    if ( ( 'mytopics' == $type ) && !is_user_logged_in() )
    152152        $type = 'all';
    153153
    154     if ( 'my' == $type || $bp->displayed_user->id ) {
     154    if ( 'mytopics' == $type || $bp->displayed_user->id ) {
    155155        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
    156156        $bp->ajax_querystring .= '&user_id=' . $user_id;
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r2191 r2194  
    198198    width: 224px;
    199199    margin-left: -226px;
     200    margin-top: 1px;
    200201    border-left: 1px solid #e4e4e4;
     202    -moz-border-radius-topright: 3px;
     203    -webkit-border-top-right-radius: 3px;
     204    background: url( ../images/sidebar_back.gif ) top left repeat-x;
    201205}
    202206    div#sidebar div#sidebar-me img.avatar {
     
    480484    div.item-list-tabs#group-subnav {
    481485        background: #fff;
    482         margin: 0 -15px 20px -15px;
     486        margin: 0 -15px 0 -15px;
    483487        border-bottom: 1px solid #eaeaea;
    484488        min-height: 35px;
     489        overflow: hidden;
    485490    }
    486491
     
    519524        background: #f8f8f8;
    520525        border: none;
    521         margin-top: -20px;
    522526        padding: 8px 15px;
    523527    }
  • trunk/bp-themes/bp-default/forums/index.php

    r2170 r2194  
    1010
    1111            <div id="forums-dir-search" class="dir-search">
    12                 <?php bp_directory_groups_search_form() ?>
     12                <?php bp_directory_forums_search_form() ?>
    1313            </div>
    1414        </form>
     
    1717                <?php if ( is_user_logged_in() ) : ?>
    1818
    19                     <?php if ( bp_has_groups( 'user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=20&per_page=20' ) ) : ?>
     19                    <?php if ( bp_has_groups( 'user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=100&per_page=100' ) ) : ?>
    2020
    2121                        <form action="" method="post" id="forum-topic-form" class="standard-form">
     
    7070            <div class="item-list-tabs">
    7171                <ul>
    72                     <li class="selected" id="forums-all"><a href="<?php bp_root_domain() ?>"><?php _e( 'All Group Forums', 'buddypress' ) ?></a></li>
     72                    <li class="selected" id="forums-all"><a href="<?php bp_root_domain() ?>"><?php printf( __( 'All Topics (%d)', 'buddypress' ), bp_forums_total_topic_count() ) ?></a></li>
     73
     74                    <?php if ( is_user_logged_in() && bp_forums_total_topic_count_for_user( bp_loggedin_user_id() ) ) : ?>
     75                        <li id="forums-mytopics"><a href="<?php echo bp_loggedin_user_domain() . BP_GROUPS_SLUG . '/' ?>"><?php printf( __( 'My Topics (%d)', 'buddypress' ), bp_forums_total_topic_count_for_user( bp_loggedin_user_id() ) ) ?></a></li>
     76                    <?php endif; ?>
    7377
    7478                    <?php do_action( 'bp_members_directory_group_types' ) ?>
     
    8084                            <option value="active"><?php _e( 'Last Active', 'buddypress' ) ?></option>
    8185                            <option value="popular"><?php _e( 'Most Posts', 'buddypress' ) ?></option>
    82                             <option value="newest"><?php _e( 'Unreplied', 'buddypress' ) ?></option>
     86                            <option value="unreplied"><?php _e( 'Unreplied', 'buddypress' ) ?></option>
    8387
    8488                            <?php do_action( 'bp_groups_directory_order_options' ) ?>
  • trunk/bp-themes/bp-default/forums/topics-loop.php

    r2170 r2194  
    2323        <tr>
    2424            <th id="th-title"><?php _e( 'Topic Title', 'buddypress' ) ?></th>
    25             <th id="th-poster"><?php _e( 'Last Poster', 'buddypress' ) ?></th>
     25            <th id="th-poster"><?php _e( 'Latest Poster', 'buddypress' ) ?></th>
    2626
    2727            <?php if ( !bp_is_group_forum() ) : ?>
    28                 <th id="th-group"><?php _e( 'Posted In', 'buddypress' ) ?></th>
     28                <th id="th-group"><?php _e( 'Posted In Group', 'buddypress' ) ?></th>
    2929            <?php endif; ?>
    3030
Note: See TracChangeset for help on using the changeset viewer.