Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (16 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

File:
1 edited

Legend:

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

    r2012 r2077  
    66    var $topics;
    77    var $topic;
    8    
     8
    99    var $in_the_loop;
    10    
     10
    1111    var $pag_page;
    1212    var $pag_num;
    1313    var $pag_links;
    1414    var $total_topic_count;
    15    
     15
    1616    var $single_topic = false;
    17    
     17
    1818    var $sort_by;
    1919    var $order;
    20    
     20
    2121    function BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ) {
    2222        global $bp;
     
    2424        $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1;
    2525        $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
    26        
     26
    2727        /* Only show stickies if we are viewing a single group forum, otherwise we could end up with hundreds globally */
    2828        if ( $no_stickies )
     
    3333                $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 ) );
    3434                break;
    35            
     35
    3636            case 'popular':
    3737                $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 ) );
    3838                break;
    39            
     39
    4040            case 'unreplied':
    4141                $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 ) );
    4242                break;
    43                
     43
    4444            case 'personal':
    4545                $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 ) );
    4646                break;
    47                
     47
    4848            case 'tag':
    4949                $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; 
     50                break;
    5151        }
    5252
    5353        $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
    54        
     54
    5555        if ( !(int)$this->topics ) {
    5656            $this->topic_count = 0;
     
    6363                $topic_count = (int)groups_total_public_forum_topic_count( $type );
    6464            } else {
    65                 $topic_count = count( $this->topics );             
     65                $topic_count = count( $this->topics );
    6666            }
    67            
     67
    6868            if ( !$max || $max >= $topic_count )
    6969                $this->total_topic_count = $topic_count;
     
    7878            } else {
    7979                $this->topic_count = count( $this->topics );
    80             }       
     80            }
    8181        }
    8282
     
    9090                    $stickies[] = $topic;
    9191                else
    92                     $standard[] = $topic; 
     92                    $standard[] = $topic;
    9393            }
    9494            $this->topics = array_merge( (array)$stickies, (array)$standard );
     
    105105        ));
    106106    }
    107    
     107
    108108    function has_topics() {
    109109        if ( $this->topic_count )
    110110            return true;
    111        
     111
    112112        return false;
    113113    }
    114    
     114
    115115    function next_topic() {
    116116        $this->current_topic++;
    117117        $this->topic = $this->topics[$this->current_topic];
    118            
     118
    119119        return $this->topic;
    120120    }
    121    
     121
    122122    function rewind_topics() {
    123123        $this->current_topic = -1;
     
    126126        }
    127127    }
    128    
    129     function user_topics() { 
     128
     129    function user_topics() {
    130130        if ( $this->current_topic + 1 < $this->topic_count ) {
    131131            return true;
     
    139139        return false;
    140140    }
    141    
     141
    142142    function the_topic() {
    143143        global $topic;
     
    146146        $this->topic = $this->next_topic();
    147147        $this->topic = (object)$this->topic;
    148        
     148
    149149        if ( $this->current_topic == 0 ) // loop has just started
    150150            do_action('loop_start');
     
    154154function bp_has_forum_topics( $args = '' ) {
    155155    global $forum_template, $bp;
    156    
     156
    157157    $defaults = array(
    158158        'type' => 'newest',
     
    175175            return false;
    176176    }
    177    
     177
    178178    /* If we're viewing a tag in the directory, let's auto set the filter to the tag name */
    179179    if ( $bp->is_directory && 'tag' == $type && !empty( $bp->action_variables[0] ) )
     
    183183    if ( $bp->is_directory && !empty( $_GET['fs'] ) )
    184184        $filter = $_GET['fs'];
    185        
     185
    186186    $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter );
    187187
    188     return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );   
     188    return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
    189189}
    190190    /* DEPRECATED use bp_has_forum_topics() */
     
    213213        return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id );
    214214    }
    215    
     215
    216216function bp_the_topic_title() {
    217217    echo bp_get_the_topic_title();
     
    256256    function bp_get_the_topic_poster_avatar( $args = '' ) {
    257257        global $forum_template;
    258    
     258
    259259        $defaults = array(
    260260            'type' => 'thumb',
     
    266266        extract( $r, EXTR_SKIP );
    267267
    268         return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 
     268        return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
    269269    }
    270270
     
    277277        return apply_filters( 'bp_get_the_topic_poster_name', bp_core_get_userlink( $forum_template->topic->topic_poster ) );
    278278    }
    279    
     279
    280280function bp_the_topic_object_id() {
    281281    echo bp_get_the_topic_object_id();
     
    286286        return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
    287287    }
    288    
     288
    289289function bp_the_topic_object_name() {
    290290    echo bp_get_the_topic_object_name();
     
    295295        return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name );
    296296    }
    297    
     297
    298298function bp_the_topic_object_slug() {
    299299    echo bp_get_the_topic_object_slug();
     
    304304        return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
    305305    }
    306    
     306
    307307function bp_the_topic_object_permalink() {
    308308    echo bp_get_the_topic_object_permalink();
     
    310310    function bp_get_the_topic_object_permalink() {
    311311        global $bp, $forum_template;
    312        
     312
    313313        /* Currently this will only work with group forums, extended support in the future */
    314314        return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/forum/' );
    315315    }
    316    
     316
    317317function bp_the_topic_last_poster_name() {
    318318    echo bp_get_the_topic_last_poster_name();
     
    323323        return apply_filters( 'bp_get_the_topic_last_poster_name', bp_core_get_userlink( $forum_template->topic->topic_last_poster ) );
    324324    }
    325    
     325
    326326function bp_the_topic_object_avatar( $args = '' ) {
    327327    echo bp_get_the_topic_object_avatar( $args );
     
    339339        extract( $r, EXTR_SKIP );
    340340
    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    
     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
    344344function bp_the_topic_last_poster_avatar( $args = '' ) {
    345345    echo bp_get_the_topic_last_poster_avatar( $args );
     
    357357        extract( $r, EXTR_SKIP );
    358358
    359         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 ) ) ); 
     359        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 ) ) );
    360360    }
    361361
     
    368368        return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time );
    369369    }
    370    
     370
    371371function bp_the_topic_time() {
    372372    echo bp_get_the_topic_time();
     
    432432            return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d post', 'buddypress' ), $forum_template->topic->topic_posts ) );
    433433        else
    434             return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );       
    435     }
    436    
     434            return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );
     435    }
     436
    437437function bp_the_topic_total_posts() {
    438438    echo bp_get_the_topic_total_posts();
     
    440440    function bp_get_the_topic_total_posts() {
    441441        global $forum_template;
    442        
     442
    443443        return $forum_template->topic->topic_posts;
    444444    }
    445    
     445
    446446function bp_the_topic_tag_count() {
    447447    echo bp_get_the_topic_tag_count();
     
    458458    function bp_get_the_topic_permalink() {
    459459        global $forum_template, $bp;
    460        
     460
    461461        if ( $forum_template->topic->object_slug )
    462462            $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/';
     
    465465        else
    466466            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/';
    467            
     467
    468468        return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' );
    469469    }
     
    477477        return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) );
    478478    }
    479    
     479
    480480function bp_the_topic_latest_post_excerpt( $args = '' ) {
    481481    echo bp_get_the_topic_latest_post_excerpt( $args );
     
    498498function bp_the_topic_time_since_last_post( $deprecated = true ) {
    499499    global $forum_template;
    500    
     500
    501501    if ( !$deprecated )
    502502        return bp_get_the_topic_time_since_last_post();
     
    515515    function bp_get_the_topic_is_mine() {
    516516        global $bp, $forum_template;
    517    
     517
    518518        return $bp->loggedin_user->id == $forum_template->topic->topic_poster;
    519519    }
     
    523523}
    524524    function bp_get_the_topic_admin_links( $args = '' ) {
    525         global $bp, $forum_template;   
    526        
     525        global $bp, $forum_template;
     526
    527527        $defaults = array(
    528528            'seperator' => '|'
     
    533533
    534534        $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a>';
    535        
     535
    536536        if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
    537537            if ( 0 == (int)$forum_template->topic->topic_sticky )
     
    547547            $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>';
    548548        }
    549        
     549
    550550        return implode( ' ' . $seperator . ' ', (array) $links );
    551551    }
     
    557557    function bp_get_the_topic_css_class() {
    558558        global $forum_template;
    559    
     559
    560560        $class = false;
    561    
     561
    562562        if ( $forum_template->current_topic % 2 == 1 )
    563563            $class .= 'alt';
    564        
     564
    565565        if ( 1 == (int)$forum_template->topic->topic_sticky )
    566566            $class .= ' sticky';
    567    
     567
    568568        if ( 0 == (int)$forum_template->topic->topic_open )
    569569            $class .= ' closed';
    570    
     570
    571571        return trim( $class );
    572572    }
     
    577577    function bp_get_my_forum_topics_link() {
    578578        global $bp;
    579        
     579
    580580        return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' );
    581581    }
     
    586586    function bp_get_unreplied_forum_topics_link() {
    587587        global $bp;
    588        
     588
    589589        return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' );
    590590    }
     
    596596    function bp_get_popular_forum_topics_link() {
    597597        global $bp;
    598        
     598
    599599        return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' );
    600600    }
     
    605605    function bp_get_newest_forum_topics_link() {
    606606        global $bp;
    607        
     607
    608608        return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' );
    609609    }
     
    614614    function bp_get_forum_topic_type() {
    615615        global $bp;
    616        
     616
    617617        if ( !$bp->is_directory || !$bp->current_action )
    618618            return 'newest';
    619        
     619
    620620
    621621        return apply_filters( 'bp_get_forum_topic_type', $bp->current_action );
    622622    }
    623    
     623
    624624function bp_forums_tag_name() {
    625625    echo bp_get_forums_tag_name();
     
    627627    function bp_get_forums_tag_name() {
    628628        global $bp;
    629        
     629
    630630        if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
    631             return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] ); 
     631            return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
    632632    }
    633633
     
    643643function bp_forum_pagination_count() {
    644644    global $bp, $forum_template;
    645    
     645
    646646    $from_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
    647     $to_num = ( $from_num + ( $forum_template->pag_num - 1  ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 ); 
    648    
     647    $to_num = ( $from_num + ( $forum_template->pag_num - 1  ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 );
     648
    649649    echo apply_filters( 'bp_forum_pagination_count', sprintf( __( 'Viewing topic %d to %d (%d total topics)', 'buddypress' ), $from_num, $to_num, $forum_template->total_topic_count ) );
    650650?>
     
    655655function bp_is_edit_topic() {
    656656    global $bp;
    657    
     657
    658658    if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) )
    659659        return false;
    660    
     660
    661661    return true;
    662662}
     
    668668    var $posts;
    669669    var $post;
    670    
     670
    671671    var $topic_id;
    672672    var $topic;
    673    
     673
    674674    var $in_the_loop;
    675    
     675
    676676    var $pag_page;
    677677    var $pag_num;
    678678    var $pag_links;
    679679    var $total_post_count;
    680    
     680
    681681    var $single_post = false;
    682    
     682
    683683    var $sort_by;
    684684    var $order;
    685    
     685
    686686    function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {
    687687        global $bp, $current_user, $forum_template;
    688        
     688
    689689        $this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
    690690        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    691    
     691
    692692        $this->topic_id = $topic_id;
    693693        $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
    694694
    695695        $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
    696        
     696
    697697        if ( !$this->posts ) {
    698698            $this->post_count = 0;
     
    724724        ));
    725725    }
    726    
     726
    727727    function has_posts() {
    728728        if ( $this->post_count )
    729729            return true;
    730        
     730
    731731        return false;
    732732    }
    733    
     733
    734734    function next_post() {
    735735        $this->current_post++;
    736736        $this->post = $this->posts[$this->current_post];
    737            
     737
    738738        return $this->post;
    739739    }
    740    
     740
    741741    function rewind_posts() {
    742742        $this->current_post = -1;
     
    745745        }
    746746    }
    747    
    748     function user_posts() { 
     747
     748    function user_posts() {
    749749        if ( $this->current_post + 1 < $this->post_count ) {
    750750            return true;
     
    758758        return false;
    759759    }
    760    
     760
    761761    function the_post() {
    762762        global $post;
     
    765765        $this->post = $this->next_post();
    766766        $this->post = (object)$this->post;
    767        
     767
    768768        if ( $this->current_post == 0 ) // loop has just started
    769769            do_action('loop_start');
     
    773773function bp_has_forum_topic_posts( $args = '' ) {
    774774    global $topic_template, $bp;
    775    
     775
    776776    $defaults = array(
    777777        'topic_id' => false,
     
    815815    function bp_get_the_topic_post_id() {
    816816        global $topic_template;
    817        
     817
    818818        return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id );
    819819    }
     
    843843        extract( $r, EXTR_SKIP );
    844844
    845         return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 
     845        return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
    846846    }
    847847
     
    855855        global $topic_template;
    856856
    857         return apply_filters( 'bp_get_the_topic_post_poster_name', bp_core_get_userlink( $topic_template->post->poster_id ) );     
     857        return apply_filters( 'bp_get_the_topic_post_poster_name', bp_core_get_userlink( $topic_template->post->poster_id ) );
    858858    }
    859859
     
    875875    function bp_get_the_topic_post_is_mine() {
    876876        global $bp, $topic_template;
    877        
     877
    878878        return $bp->loggedin_user->id == $topic_template->post->poster_id;
    879879    }
     
    883883}
    884884    function bp_get_the_topic_post_admin_links( $args = '' ) {
    885         global $topic_template; 
    886        
     885        global $topic_template;
     886
    887887        /* Never show for the first post in a topic. */
    888888        if ( 0 == $topic_template->current_post )
    889889            return;
    890        
     890
    891891        $defaults = array(
    892892            'seperator' => '|'
     
    907907    function bp_get_the_topic_post_edit_text() {
    908908        global $bp;
    909        
     909
    910910        $post = bp_forums_get_post( $bp->action_variables[4] );
    911911        return attribute_escape( $post->post_text );
     
    923923function bp_the_topic_pagination_count() {
    924924    global $bp, $topic_template;
    925    
     925
    926926    $from_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
    927     $to_num = ( $from_num + ( $topic_template->pag_num - 1  ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 ); 
    928    
     927    $to_num = ( $from_num + ( $topic_template->pag_num - 1  ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 );
     928
    929929    echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %d to %d (%d total posts)', 'buddypress' ), $from_num, $to_num, $topic_template->total_post_count ) );
    930930?>
     
    947947    function bp_get_forum_permalink() {
    948948        global $bp;
    949        
     949
    950950        if ( $bp->is_single_item )
    951951            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
     
    961961    function bp_get_forum_directory_permalink() {
    962962        global $bp;
    963        
     963
    964964        return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug );
    965965    }
    966966
    967 function bp_forums_tag_heat_map( $args = '' ) { 
     967function bp_forums_tag_heat_map( $args = '' ) {
    968968    $defaults = array(
    969969        'smallest' => '10',
     
    985985        global $topic_template;
    986986
    987         return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 
     987        return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
    988988    }
    989989
     
    993993    function bp_get_forum_topic_action() {
    994994        global $bp;
    995        
    996         return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );   
     995
     996        return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
    997997    }
    998998
Note: See TracChangeset for help on using the changeset viewer.