Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/21/2009 09:45:28 PM (15 years ago)
Author:
apeatling
Message:

Completely re-wrote the forums component. No longer needs an external setup of bbPress. bbPress is included as an external that can be set up with one click for new installations. Existing bbPress installs, or BuddyPress upgrades can use the "use existing install" option and provide the location of their bb-config.php file.

Added complete forum management for group mods and admins (sticky/delete/close/edit) and edit/delete for group members on their own posts. Make sure you update your theme with the new template files in the /groups/ directory to get access to these features.

The "use existing install" option needs testing before it can become reliable. Expect changes.

Location:
trunk/bp-forums
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums

    • Property svn:externals set to
  • trunk/bp-forums/bp-forums-templatetags.php

    r1538 r1621  
    1919    var $order;
    2020   
    21     function BP_Forums_Template_Forum( $forum_id, $per_page, $max ) {
    22         global $bp, $current_user;
     21    function BP_Forums_Template_Forum( $forum_id, $per_page, $max, $no_stickies ) {
     22        global $bp;
    2323
    2424        $this->pag_page = isset( $_REQUEST['forum_page'] ) ? intval( $_REQUEST['forum_page'] ) : 1;
    2525        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    2626
    27         $this->topics = bp_forums_get_topics( $forum_id, $this->pag_num, $this->pag_page );
    28        
    29         if ( !$this->topics ) {
     27        $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
     28
     29        if ( !(int)$this->topics ) {
    3030            $this->topic_count = 0;
    3131            $this->total_topic_count = 0;
    3232        } else {
    33             $forum_count = count( bp_forums_get_topics( $forum_id ) );
     33            $topic_count = bp_forums_get_forum( $forum_id );
     34            $topic_count = (int)$topic_count->topics;
    3435           
    35             if ( !$max || $max >= $forum_count )
    36                 $this->total_topic_count = $forum_count;
     36            if ( !$max || $max >= $topic_count )
     37                $this->total_topic_count = $topic_count;
    3738            else
    3839                $this->total_topic_count = (int)$max;
     
    4647                $this->topic_count = count( $this->topics );
    4748            }       
     49        }
     50       
     51        if ( !$no_stickies) {
     52            /* Place stickies at the top - not sure why bbPress doesn't do this? */
     53            foreach( (array)$this->topics as $topic ) {
     54                if ( 1 == (int)$topic->topic_sticky )
     55                    $stickies[] = $topic;
     56                else
     57                    $standard[] = $topic;
     58            }
     59            $this->topics = array_merge( (array)$stickies, (array)$standard );
    4860        }
    4961
     
    107119function bp_has_topics( $args = '' ) {
    108120    global $forum_template, $bp;
    109     global $group_obj;
    110121   
    111122    $defaults = array(
    112123        'forum_id' => false,
    113         'per_page' => 10,
    114         'max' => false
     124        'per_page' => 15,
     125        'max' => false,
     126        'no_stickies' => false
    115127    );
    116128
     
    118130    extract( $r, EXTR_SKIP );
    119131
    120     if ( !$forum_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action )
    121         $forum_id = groups_get_groupmeta( $group_obj->id, 'forum_id' );
     132    if ( !$forum_id && $bp->current_component == $bp->groups->slug )
     133        $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    122134   
    123135    if ( is_numeric( $forum_id ) )
    124         $forum_template = new BP_Forums_Template_Forum( $forum_id, $per_page, $max );
     136        $forum_template = new BP_Forums_Template_Forum( (int)$forum_id, $per_page, $max, $no_stickies );
    125137    else
    126138        return false;
     
    166178    }
    167179
     180function bp_the_topic_text() {
     181    echo bp_get_the_topic_text();
     182}
     183    function bp_get_the_topic_text() {
     184        global $forum_template;
     185
     186        $post = bb_get_first_post( $forum_template->topic->topic_id );
     187        return apply_filters( 'bp_get_the_topic_text', $post->post_text );
     188    }
     189
    168190function bp_the_topic_poster_id() {
    169191    echo bp_get_the_topic_poster_id();
     
    175197    }
    176198
    177 function bp_the_topic_poster_avatar() {
    178     echo bp_get_the_topic_poster_avatar();
    179 }
    180     function bp_get_the_topic_poster_avatar() {
    181         global $forum_template;
    182 
    183         return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_get_avatar( $forum_template->topic->topic_poster, 1 ) );
     199function bp_the_topic_poster_avatar( $args = '' ) {
     200    echo bp_get_the_topic_poster_avatar( $args );
     201}
     202    function bp_get_the_topic_poster_avatar( $args = '' ) {
     203        global $forum_template;
     204   
     205        $defaults = array(
     206            'type' => 'thumb',
     207            'width' => false,
     208            'height' => false,
     209        );
     210
     211        $r = wp_parse_args( $args, $defaults );
     212        extract( $r, EXTR_SKIP );
     213
     214        if ( 'thumb' == $type )
     215            $size = 1;
     216        else
     217            $size = 2;
     218
     219        if ( $width && $height )
     220            $av = bp_core_get_avatar( $forum_template->topic->topic_poster, $size, $width, $height );
     221        else
     222            $av = bp_core_get_avatar( $forum_template->topic->topic_poster, $size );
     223
     224        return apply_filters( 'bp_get_the_topic_poster_avatar', $av );
    184225    }
    185226
     
    202243    }
    203244
    204 function bp_the_topic_last_poster_avatar() {
    205     echo bp_get_the_topic_last_poster_avatar();
    206 }
    207     function bp_get_the_topic_last_poster_avatar() {
    208         global $forum_template;
    209 
    210         return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_get_avatar( $forum_template->topic->topic_last_poster, 1 ) );
     245function bp_the_topic_last_poster_avatar( $args = '' ) {
     246    echo bp_get_the_topic_last_poster_avatar( $args );
     247}
     248    function bp_get_the_topic_last_poster_avatar( $args = '' ) {
     249        global $forum_template;
     250
     251        $defaults = array(
     252            'type' => 'thumb',
     253            'width' => false,
     254            'height' => false,
     255        );
     256
     257        $r = wp_parse_args( $args, $defaults );
     258        extract( $r, EXTR_SKIP );
     259
     260        if ( 'thumb' == $type )
     261            $size = 1;
     262        else
     263            $size = 2;
     264
     265        if ( $width && $height )
     266            $av = bp_core_get_avatar( $forum_template->topic->topic_last_poster, $size, $width, $height );
     267        else
     268            $av = bp_core_get_avatar( $forum_template->topic->topic_last_poster, $size );
     269
     270        return apply_filters( 'bp_get_the_topic_last_poster_avatar', $av );
    211271    }
    212272
     
    299359}
    300360    function bp_get_the_topic_permalink() {
    301         global $forum_template, $bbpress_live, $group_obj;
    302 
    303         $target_uri = $bbpress_live->fetch->options['target_uri'];
    304 
    305         return apply_filters( 'bp_get_the_topic_permalink', bp_get_group_permalink( $group_obj ) . '/forum/topic/' . $forum_template->topic->topic_id );
     361        global $forum_template, $bp;
     362       
     363        if ( $bp->is_single_item )
     364            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
     365        else
     366            $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
     367           
     368        return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug );
    306369    }
    307370
     
    312375        global $forum_template;
    313376
    314         return apply_filters( 'bp_get_the_topic_time_since_created', $forum_template->topic->topic_start_time_since );
    315     }
    316    
    317 function bp_the_topic_latest_post_excerpt() {
    318     echo bp_get_the_topic_latest_post_excerpt();
    319 }
    320     function bp_get_the_topic_latest_post_excerpt() {
    321         global $forum_template;
     377        return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( bb_gmtstrtotime( $forum_template->topic->topic_start_time ) ) );
     378    }
     379   
     380function bp_the_topic_latest_post_excerpt( $args = '' ) {
     381    echo bp_get_the_topic_latest_post_excerpt( $args );
     382}
     383    function bp_get_the_topic_latest_post_excerpt( $args = '' ) {
     384        global $forum_template;
     385
     386        $defaults = array(
     387            'length' => 10
     388        );
     389
     390        $r = wp_parse_args( $args, $defaults );
     391        extract( $r, EXTR_SKIP );
    322392
    323393        $post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
    324         return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post['post_text'] );
     394        $post = bp_create_excerpt( $post->post_text, $length );
     395        return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post );
    325396    }
    326397
     
    336407        global $forum_template;
    337408
    338         return apply_filters( 'bp_get_the_topic_time_since_last_post', $forum_template->topic->topic_time_since );
    339     }
     409        return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( bb_gmtstrtotime( $forum_template->topic->topic_time ) ) );
     410    }
     411
     412function bp_the_topic_admin_links( $args = '' ) {
     413    echo bp_get_the_topic_admin_links( $args );
     414}
     415    function bp_get_the_topic_admin_links( $args = '' ) {
     416        global $forum_template;
     417       
     418        $defaults = array(
     419            'seperator' => '|'
     420        );
     421
     422        $r = wp_parse_args( $args, $defaults );
     423        extract( $r, EXTR_SKIP );
     424
     425        $links  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
     426
     427        if ( 0 == (int)$forum_template->topic->topic_sticky )
     428            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' ';
     429        else
     430            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' ';
     431
     432        if ( 0 == (int)$forum_template->topic->topic_open )
     433            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' ';
     434        else
     435            $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' ';
     436
     437        $links .= '<a id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';
     438
     439        return $links;
     440    }
     441
     442function bp_the_topic_css_class() {
     443    echo bp_get_the_topic_css_class();
     444}
     445
     446    function bp_get_the_topic_css_class() {
     447        global $forum_template;
     448   
     449        $class = false;
     450   
     451        if ( 1 == (int)$forum_template->topic->topic_sticky ) {
     452            $class .= 'sticky';
     453        }
     454   
     455        if ( 0 == (int)$forum_template->topic->topic_open ) {
     456            $class .= ' closed';
     457        }
     458   
     459        return trim( $class );
     460    }
     461
    340462
    341463function bp_forum_pagination() {
     
    358480    <img id="ajax-loader-groups" src="<?php echo $bp->core->image_base ?>/ajax-loader.gif" height="7" alt="<?php _e( "Loading", "buddypress" ) ?>" style="display: none;" />
    359481<?php
     482}
     483
     484function bp_is_edit_topic() {
     485    global $bp;
     486   
     487    if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) )
     488        return false;
     489   
     490    return true;
    360491}
    361492
     
    391522        $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
    392523
    393         $this->posts = bp_forums_get_posts( $this->topic_id, $this->pag_num, $this->pag_page );
     524        $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
    394525       
    395526        if ( !$this->posts ) {
     
    474605    $defaults = array(
    475606        'topic_id' => false,
    476         'per_page' => 10,
     607        'per_page' => 15,
    477608        'max' => false
    478609    );
     
    482613
    483614    if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
    484         $topic_id = $bp->action_variables[1];
     615        $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );
    485616
    486617    if ( is_numeric( $topic_id ) )
     
    520651    }
    521652
    522 function bp_the_topic_post_poster_avatar() {
    523     echo bp_get_the_topic_post_poster_avatar();
    524 }
    525     function bp_get_the_topic_post_poster_avatar() {
     653function bp_the_topic_post_poster_avatar( $args = '' ) {
     654    echo bp_get_the_topic_post_poster_avatar( $args );
     655}
     656    function bp_get_the_topic_post_poster_avatar( $args = '' ) {
    526657        global $topic_template;
    527658
    528         return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_get_avatar( $topic_template->post->poster_id, 1, 20, 20 ) );
     659        $defaults = array(
     660            'type' => 'thumb',
     661            'width' => 20,
     662            'height' => 20,
     663        );
     664
     665        $r = wp_parse_args( $args, $defaults );
     666        extract( $r, EXTR_SKIP );
     667
     668        if ( 'thumb' == $type )
     669            $size = 1;
     670        else
     671            $size = 2;
     672
     673        if ( $width && $height )
     674            $av = bp_core_get_avatar( $topic_template->post->poster_id, $size, $width, $height );
     675        else
     676            $av = bp_core_get_avatar( $topic_template->post->poster_id, $size );
     677
     678        return apply_filters( 'bp_get_the_topic_post_poster_avatar', $av );
    529679    }
    530680
     
    550700        global $topic_template;
    551701
    552         return apply_filters( 'bp_get_the_topic_post_time_since', $topic_template->post->post_time_since );
     702        return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( bb_gmtstrtotime( $topic_template->post->post_time ) ) );
     703    }
     704
     705function bp_the_topic_post_is_mine() {
     706    echo bp_the_topic_post_is_mine();
     707}
     708    function bp_get_the_topic_post_is_mine() {
     709        global $bp, $topic_template;
     710       
     711        return $bp->loggedin_user->id == $topic_template->post->poster_id;
     712    }
     713
     714function bp_the_topic_post_admin_links( $args = '' ) {
     715    echo bp_get_the_topic_post_admin_links( $args );
     716}
     717    function bp_get_the_topic_post_admin_links( $args = '' ) {
     718        global $topic_template;
     719       
     720        $defaults = array(
     721            'seperator' => '|'
     722        );
     723
     724        $r = wp_parse_args( $args, $defaults );
     725        extract( $r, EXTR_SKIP );
     726
     727        $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 . ' ';
     728        $links .= '<a 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>';
     729
     730        return $links;
     731    }
     732
     733function bp_the_topic_post_edit_text() {
     734    echo bp_get_the_topic_post_edit_text();
     735}
     736    function bp_get_the_topic_post_edit_text() {
     737        global $bp;
     738       
     739        $post = bp_forums_get_post( $bp->action_variables[3] );
     740        return attribute_escape( $post->post_text );
    553741    }
    554742
     
    578766}
    579767    function bp_get_forum_permalink() {
    580         global $group_obj;
    581 
    582         return apply_filters( 'bp_get_forum_permalink', bp_get_group_permalink( $group_obj ) . '/forum' );
     768        global $bp;
     769       
     770        if ( $bp->is_single_item )
     771            $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
     772        else
     773            $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
     774
     775        return apply_filters( 'bp_get_forum_permalink', $permalink . 'forum' );
    583776    }
    584777
     
    589782        global $topic_template;
    590783
    591         return apply_filters( 'bp_get_forum_action', bp_get_group_permalink( $group_obj ) . '/forum' );
     784        return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 
    592785    }
    593786
     
    596789}
    597790    function bp_get_forum_topic_action() {
    598         global $topic_template;
    599 
    600         return apply_filters( 'bp_get_forum_topic_action', bp_get_group_permalink( $group_obj ) . '/forum/topic/' . $topic_template->topic_id );   
     791        global $bp;
     792       
     793        return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );   
    601794    }
    602795
Note: See TracChangeset for help on using the changeset viewer.