Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/11/2009 11:59:16 PM (17 years ago)
Author:
apeatling
Message:

Added support for global group forum listings and fixed a few forum admin glitches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-templatetags.php

    r1844 r1858  
    1919    var $order;
    2020   
    21     function BP_Forums_Template_Forum( $forum_id, $per_page, $max, $no_stickies ) {
    22         global $bp;
    23 
    24         $this->pag_page = isset( $_REQUEST['forum_page'] ) ? intval( $_REQUEST['forum_page'] ) : 1;
    25         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    26 
    27         $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
    28 
     21    function BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ) {
     22        global $bp;
     23
     24        $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1;
     25        $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
     26       
     27        /* Only show stickies if we are viewing a single group forum, otherwise we could end up with hundreds globally */
     28        if ( !$forum_id )
     29            $show_stickies = 'no'; // bbPress needs str 'no'
     30
     31        switch ( $type ) {
     32            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 ) );
     34                break;
     35           
     36            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 ) );
     38                break;
     39           
     40            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 ) );
     42                break;
     43               
     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               
     48            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 ) );
     50                break;
     51        }
     52
     53        $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
     54       
    2955        if ( !(int)$this->topics ) {
    3056            $this->topic_count = 0;
    3157            $this->total_topic_count = 0;
    3258        } else {
    33             $topic_count = bp_forums_get_forum( $forum_id );
    34             $topic_count = (int)$topic_count->topics;
     59            if ( $forum_id ) {
     60                $topic_count = bp_forums_get_forum( $forum_id );
     61                $topic_count = (int)$topic_count->topics;
     62            } else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) {
     63                $topic_count = (int)groups_total_public_forum_topic_count( $type );
     64            } else {
     65                $topic_count = count( $this->topics );             
     66            }
    3567           
    3668            if ( !$max || $max >= $topic_count )
     
    4880            }       
    4981        }
    50        
     82
     83        $this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
     84        $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 );
     85
    5186        if ( !$no_stickies) {
    5287            /* Place stickies at the top - not sure why bbPress doesn't do this? */
     
    6196
    6297        $this->pag_links = paginate_links( array(
    63             'base' => add_query_arg( array( 'forum_page' => '%#%', 'num' => $this->pag_num ) ),
     98            'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
    6499            'format' => '',
    65100            'total' => ceil($this->total_topic_count / $this->pag_num),
     
    117152}
    118153
    119 function bp_has_topics( $args = '' ) {
     154function bp_has_forum_topics( $args = '' ) {
    120155    global $forum_template, $bp;
    121156   
    122157    $defaults = array(
     158        'type' => 'newest',
    123159        'forum_id' => false,
    124160        'per_page' => 15,
    125161        'max' => false,
    126         'no_stickies' => false
     162        'no_stickies' => false,
     163        'filter' => false
    127164    );
    128165
     
    130167    extract( $r, EXTR_SKIP );
    131168
    132     if ( !$forum_id && $bp->current_component == $bp->groups->slug )
     169    /* If we're in a single group, set this group's forum_id */
     170    if ( !$forum_id && $bp->groups->current_group ) {
    133171        $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    134    
    135     if ( is_numeric( $forum_id ) )
    136         $forum_template = new BP_Forums_Template_Forum( (int)$forum_id, $per_page, $max, $no_stickies );
    137     else
    138         return false;
    139 
    140     return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
    141 }
    142 
    143 function bp_topics() {
     172
     173        /* If it turns out there is no forum for this group, return false so we don't fetch all global topics */
     174        if ( !$forum_id )
     175            return false;
     176    }
     177   
     178    /* If we're viewing a tag in the directory, let's auto set the filter to the tag name */
     179    if ( $bp->is_directory && 'tag' == $type && !empty( $bp->action_variables[0] ) )
     180        $filter = $bp->action_variables[0];
     181
     182    /* If $_GET['s'] is set, let's auto populate the filter var */
     183    if ( $bp->is_directory && !empty( $_GET['s'] ) )
     184        $filter = $_GET['s'];
     185       
     186    $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter );
     187
     188    return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );   
     189}
     190    /* DEPRECATED use bp_has_forum_topics() */
     191    function bp_has_topics( $args = '' ) { return bp_has_forum_topics( $args ); }
     192
     193function bp_forum_topics() {
    144194    global $forum_template;
    145195    return $forum_template->user_topics();
    146196}
    147 
    148 function bp_the_topic() {
     197    /* DEPRECATED use bp_has_forum_topics() */
     198    function bp_topics() { return bp_forum_topics(); }
     199
     200function bp_the_forum_topic() {
    149201    global $forum_template;
    150202    return $forum_template->the_topic();
    151203}
     204    /* DEPRECATED use bp_the_forum_topic() */
     205    function bp_the_topic() { return bp_the_forum_topic(); }
    152206
    153207function bp_the_topic_id() {
     
    224278    }
    225279   
     280function bp_the_topic_object_id() {
     281    echo bp_get_the_topic_object_id();
     282}
     283    function bp_get_the_topic_object_id() {
     284        global $forum_template;
     285
     286        return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
     287    }
     288   
     289function bp_the_topic_object_name() {
     290    echo bp_get_the_topic_object_name();
     291}
     292    function bp_get_the_topic_object_name() {
     293        global $forum_template;
     294
     295        return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name );
     296    }
     297
     298function bp_the_topic_object_slug() {
     299    echo bp_get_the_topic_object_slug();
     300}
     301    function bp_get_the_topic_object_slug() {
     302        global $forum_template;
     303
     304        return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
     305    }
     306   
     307function bp_the_topic_object_permalink() {
     308    echo bp_get_the_topic_object_permalink();
     309}
     310    function bp_get_the_topic_object_permalink() {
     311        global $forum_template;
     312               
     313        /* Currently this will only work with group forums, extended support in the future */
     314        return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/' );
     315    }
     316   
    226317function bp_the_topic_last_poster_name() {
    227318    echo bp_get_the_topic_last_poster_name();
     
    233324    }
    234325
    235 function bp_the_topic_last_poster_avatar( $args = '' ) {
    236     echo bp_get_the_topic_last_poster_avatar( $args );
    237 }
    238     function bp_get_the_topic_last_poster_avatar( $args = '' ) {
     326function bp_the_topic_object_avatar( $args = '' ) {
     327    echo bp_get_the_topic_object_avatar( $args );
     328}
     329    function bp_get_the_topic_object_avatar( $args = '' ) {
    239330        global $forum_template;
    240331
     
    248339        extract( $r, EXTR_SKIP );
    249340
     341        return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) );       
     342    }
     343
     344function bp_the_topic_last_poster_avatar( $args = '' ) {
     345    echo bp_get_the_topic_last_poster_avatar( $args );
     346}
     347    function bp_get_the_topic_last_poster_avatar( $args = '' ) {
     348        global $forum_template;
     349
     350        $defaults = array(
     351            'type' => 'thumb',
     352            'width' => false,
     353            'height' => false,
     354        );
     355
     356        $r = wp_parse_args( $args, $defaults );
     357        extract( $r, EXTR_SKIP );
     358
    250359        return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
    251360    }
     
    325434            return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );       
    326435    }
    327 
     436   
     437function bp_the_topic_total_posts() {
     438    echo bp_get_the_topic_total_posts();
     439}
     440    function bp_get_the_topic_total_posts() {
     441        global $forum_template;
     442       
     443        return $forum_template->topic->topic_posts;
     444    }
     445   
    328446function bp_the_topic_tag_count() {
    329447    echo bp_get_the_topic_tag_count();
     
    341459        global $forum_template, $bp;
    342460       
    343         if ( $bp->is_single_item )
     461        if ( $forum_template->topic->object_slug )
     462            $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/';
     463        else if ( $bp->is_single_item )
    344464            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
    345465        else
    346             $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
     466            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/';
    347467           
    348         return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug );
     468        return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' );
    349469    }
    350470
     
    403523        extract( $r, EXTR_SKIP );
    404524
    405         $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
     525        $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
    406526
    407527        if ( 0 == (int)$forum_template->topic->topic_sticky )
    408             $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' ';
     528            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' ';
    409529        else
    410             $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' ';
     530            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' ';
    411531
    412532        if ( 0 == (int)$forum_template->topic->topic_open )
    413             $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' ';
     533            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' ';
    414534        else
    415             $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' ';
    416 
    417         $links .= '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
     535            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' ';
     536
     537        $links .= '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
    418538
    419539        return $links;
     
    429549        $class = false;
    430550   
    431         if ( 1 == (int)$forum_template->topic->topic_sticky ) {
    432             $class .= 'sticky';
    433         }
    434    
    435         if ( 0 == (int)$forum_template->topic->topic_open ) {
     551        if ( $forum_template->current_topic % 2 == 1 )
     552            $class .= 'alt';
     553       
     554        if ( 1 == (int)$forum_template->topic->topic_sticky )
     555            $class .= ' sticky';
     556   
     557        if ( 0 == (int)$forum_template->topic->topic_open )
    436558            $class .= ' closed';
    437         }
    438559   
    439560        return trim( $class );
    440561    }
    441562
     563function bp_my_forum_topics_link() {
     564    echo bp_get_my_forum_topics_link();
     565}
     566    function bp_get_my_forum_topics_link() {
     567        global $bp;
     568       
     569        return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' );
     570    }
     571
     572function bp_unreplied_forum_topics_link() {
     573    echo bp_get_unreplied_forum_topics_link();
     574}
     575    function bp_get_unreplied_forum_topics_link() {
     576        global $bp;
     577       
     578        return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' );
     579    }
     580
     581
     582function bp_popular_forum_topics_link() {
     583    echo bp_get_popular_forum_topics_link();
     584}
     585    function bp_get_popular_forum_topics_link() {
     586        global $bp;
     587       
     588        return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' );
     589    }
     590
     591function bp_newest_forum_topics_link() {
     592    echo bp_get_newest_forum_topics_link();
     593}
     594    function bp_get_newest_forum_topics_link() {
     595        global $bp;
     596       
     597        return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' );
     598    }
     599
     600function bp_forum_topic_type() {
     601    echo bp_get_forum_topic_type();
     602}
     603    function bp_get_forum_topic_type() {
     604        global $bp;
     605       
     606        if ( !$bp->is_directory || !$bp->current_action )
     607            return 'newest';
     608       
     609
     610        return apply_filters( 'bp_get_forum_topic_type', $bp->current_action );
     611    }
     612   
     613function bp_forums_tag_name() {
     614    echo bp_get_forums_tag_name();
     615}
     616    function bp_get_forums_tag_name() {
     617        global $bp;
     618       
     619        if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
     620            return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
     621    }
    442622
    443623function bp_forum_pagination() {
     
    580760}
    581761
    582 function bp_has_topic_posts( $args = '' ) {
     762function bp_has_forum_topic_posts( $args = '' ) {
    583763    global $topic_template, $bp;
    584764   
     
    602782    return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
    603783}
    604 
    605 function bp_topic_posts() {
     784    /* DEPRECATED use bp_has_forum_topic_posts() */
     785    function bp_has_topic_posts() { return bp_has_forum_topic_posts( $args ); }
     786
     787function bp_forum_topic_posts() {
    606788    global $topic_template;
    607789    return $topic_template->user_posts();
    608790}
    609 
    610 function bp_the_topic_post() {
     791    /* DEPRECATED use bp_forum_topic_posts() */
     792    function bp_topic_posts() { return bp_forum_topic_posts(); }
     793
     794function bp_the_forum_topic_post() {
    611795    global $topic_template;
    612796    return $topic_template->the_post();
    613797}
     798    /* DEPRECATED use bp_the_forum_topic_post() */
     799    function bp_the_topic_post() { return bp_the_forum_topic_post(); }
    614800
    615801function bp_the_topic_post_id() {
     
    695881        extract( $r, EXTR_SKIP );
    696882
    697         $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . '/post/' . $topic_template->post->post_id . '/edit/', 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
    698         $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/post/' . $topic_template->post->post_id . '/delete/', 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
     883        $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
     884        $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
    699885
    700886        return $links;
     
    707893        global $bp;
    708894       
    709         $post = bp_forums_get_post( $bp->action_variables[3] );
     895        $post = bp_forums_get_post( $bp->action_variables[4] );
    710896        return attribute_escape( $post->post_text );
    711897    }
     
    732918}
    733919
     920function bp_directory_forums_search_form() {
     921    global $bp; ?>
     922    <form action="<?php echo $bp->root_domain . '/' . $bp->forums->slug . '/'; ?>" method="get" id="search-forums-form">
     923        <label><input type="text" name="s" id="forums_search" value="<?php if ( isset( $_GET['s'] ) ) { echo attribute_escape( $_GET['s'] ); } 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>
     924        <input type="submit" id="forums_search_submit" name="submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
     925    </form>
     926<?php
     927}
     928
    734929function bp_forum_permalink() {
    735930    echo bp_get_forum_permalink();
     
    746941    }
    747942
     943function bp_forum_directory_permalink() {
     944    echo bp_get_forum_directory_permalink();
     945}
     946    function bp_get_forum_directory_permalink() {
     947        global $bp;
     948       
     949        return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug );
     950    }
     951
     952function bp_forums_tag_heat_map( $args = '' ) {
     953    $defaults = array(
     954        'smallest' => '10',
     955        'largest' => '42',
     956        'sizing' => 'px',
     957        'limit' => '50'
     958    );
     959
     960    $r = wp_parse_args( $args, $defaults );
     961    extract( $r, EXTR_SKIP );
     962
     963    bb_tag_heat_map( $smallest, $largest, $sizing, $limit );
     964}
     965
    748966function bp_forum_action() {
    749967    echo bp_get_forum_action();
Note: See TracChangeset for help on using the changeset viewer.