Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.