Skip to:
Content

BuddyPress.org

Changeset 1858


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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums.php

    r1834 r1858  
    3838}
    3939
     40function bp_forums_setup_root_component() {
     41        /* Register 'forums' as a root component */
     42        bp_core_add_root_component( BP_FORUMS_SLUG );
     43}
     44add_action( 'plugins_loaded', 'bp_forums_setup_root_component', 2 );
     45
     46function bp_forums_directory_forums_setup() {
     47        global $bp;
     48
     49        if ( $bp->current_component == $bp->forums->slug ) {
     50                $bp->is_directory = true;
     51               
     52                do_action( 'bp_forums_directory_forums_setup' );
     53                bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'directories/forums/index' ) );
     54        }
     55}
     56add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
     57
    4058function bp_forums_add_admin_menu() {
    4159        global $bp;
    … …  
    5775
    5876function bp_forums_get_forum_topics( $args = '' ) {
    59         do_action( 'bbpress_init' );
    60        
    61         $defaults = array(
     77        global $bp;
     78       
     79        do_action( 'bbpress_init' );
     80       
     81        $defaults = array(
     82                'type' => 'newest',
    6283                'forum_id' => false,
    6384                'page' => 1,
    6485                'per_page' => 15,
    65                 'exclude' => false
    66         );
    67 
    68         $r = wp_parse_args( $args, $defaults );
    69         extract( $r, EXTR_SKIP );
    70        
    71         return get_latest_topics( array( 'forum' => $forum_id, 'page' => $page_num, 'number' => $per_page, 'exclude' => $exclude ) );
     86                'exclude' => false,
     87                'show_stickies' => 'all',
     88                'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
     89        );
     90       
     91        $r = wp_parse_args( $args, $defaults );
     92        extract( $r, EXTR_SKIP );
     93
     94        switch ( $type ) {
     95                case 'newest':
     96                        $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' );
     97                        $topics = $query->results;
     98                break;
     99               
     100                case 'popular':
     101                        $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 ) );
     102                        $topics =& $query->results;
     103                break;
     104               
     105                case 'unreplied':
     106                        $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 ) );
     107                        $topics =& $query->results;
     108                break; 
     109               
     110                case 'personal':
     111                        $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' );
     112                        $topics =& $query->results;
     113                break;
     114               
     115                case 'tag':
     116                        $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 ) );
     117                        $topics =& $query->results;
     118                break;
     119        }
     120
     121        return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
    72122}
    73123
    … …  
    135185                'topic_time' => date( 'Y-m-d H:i:s' ),
    136186                'topic_open' => 1,
     187                'topic_tags' => false, // accepts array or comma delim
    137188                'forum_id' => 0 // accepts ids or slugs
    138189        );
    … …  
    144195                $topic_slug = sanitize_title( $topic_title );
    145196               
    146         if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id ) ) )
     197        if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id, 'tags' => $topic_tags ) ) )
    147198                return false;
    148199       
    … …  
    236287
    237288        return bb_delete_topic( $topic_id, 1 );
     289}
     290
     291function bp_forums_delete_post( $args = '' ) {
     292        global $bp;
     293       
     294        do_action( 'bbpress_init' );
     295       
     296        $defaults = array(
     297                'post_id' => false
     298        );
     299
     300        $r = wp_parse_args( $args, $defaults );
     301        extract( $r, EXTR_SKIP );
     302
     303        return bb_delete_post( $post_id, 1 );   
    238304}
    239305
  • trunk/bp-forums/bp-forums-bbpress.php

    r1812 r1858  
    158158}
    159159
     160/* BBPress needs this function to convert vars */
     161function backpress_convert_object( &$object, $output ) {
     162        if ( is_array( $object ) ) {
     163                foreach ( array_keys( $object ) as $key )
     164                        backpress_convert_object( $object[$key], $output );
     165        } else {
     166                switch ( $output ) {
     167                        case OBJECT  : break;
     168                        case ARRAY_A : $object = get_object_vars($object); break;
     169                        case ARRAY_N : $object = array_values(get_object_vars($object)); break;
     170                }
     171        }
     172}
     173
     174
    160175
    161176?>
  • trunk/bp-forums/bp-forums-filters.php

    r1759 r1858  
    44add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
    55add_filter( 'bp_forums_bbconfig_location', 'attribute_escape', 1 );
     6
     7add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
     8add_filter( 'bp_get_the_topic_post_content', 'wp_filter_kses', 1 );
     9add_filter( 'bp_get_the_topic_title', 'attribute_escape' );
     10add_filter( 'bp_get_the_topic_post_content', 'attribute_escape' );
    611
    712add_filter( 'bp_get_the_topic_title', 'wptexturize' );
    … …  
    3641add_filter( 'edit_allowedtags', 'bp_forums_add_allowed_tags' );
    3742
     43function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
     44        global $bp;
     45       
     46        return apply_filters( 'bp_forums_filter_tag_link', $bp->root_domain . '/' . $bp->forums->slug . '/tag/' . $tag . '/' );
     47}
     48add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
     49
    3850?>
  • 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();
  • trunk/bp-groups.php

    r1852 r1858  
    581581               
    582582                if ( $topic_slug && $topic_id ) {
    583                        
     583
    584584                        /* Posting a reply */
    585585                        if ( !$bp->action_variables[2] && isset( $_POST['submit_reply'] ) ) {
    586586                                /* Check the nonce */
    587587                                check_admin_referer( 'bp_forums_new_reply' );
    588                
     588                               
     589                                /* Auto join this user if they are not yet a member of this group */
     590                                if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     591                                        groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
     592                               
    589593                                if ( !groups_new_group_forum_post( $_POST['reply_text'], $topic_id ) )
    590594                                        bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' );
    … …  
    593597                               
    594598                                if ( $_SERVER['QUERY_STRING'] )
    595                                         $query_vars = '?' . $_SERVER['QUERY_STRING'];
    596                                        
     599                                        $query_vars = '?' . $_SERVER['QUERY_STRING'];                   
     600                               
    597601                                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' . $query_vars );
    598602                        }
    … …  
    609613                       
    610614                                do_action( 'groups_stick_topic', $topic_id );
    611                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     615                                bp_core_redirect( wp_get_referer() );
    612616                        }
    613617                       
    … …  
    623627                       
    624628                                do_action( 'groups_unstick_topic', $topic_id );
    625                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     629                                bp_core_redirect( wp_get_referer() );
    626630                        }
    627631                       
    … …  
    637641                       
    638642                                do_action( 'groups_close_topic', $topic_id );
    639                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     643                                bp_core_redirect( wp_get_referer() );
    640644                        }
    641645
    … …  
    651655                       
    652656                                do_action( 'groups_open_topic', $topic_id );
    653                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     657                                bp_core_redirect( wp_get_referer() );
    654658                        }
    655659
    656660                        /* Delete a topic */
    657                         else if ( 'delete' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     661                        else if ( 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
    658662                                /* Check the nonce */
    659663                                check_admin_referer( 'bp_forums_delete_topic' );
    660664       
    661                                 if ( !groups_delete_forum_topic( $topic_id ) )
     665                                if ( !groups_delete_group_forum_topic( $topic_id ) )
    662666                                        bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
    663667                                else
    664668                                        bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
    665                                                                
    666                                 do_action( 'groups_delete_topic', $topic_id );
    667                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     669
     670                                bp_core_redirect( wp_get_referer() );
    668671                        }
    669672                       
    670673                        /* Editing a topic */
    671                         else if ( 'edit' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     674                        else if ( 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
    672675                                if ( isset( $_POST['save_changes'] ) ) {
    673676                                        /* Check the nonce */
    … …  
    691694                       
    692695                        /* Delete a post */
    693                         else if ( 'delete' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     696                       
     697                        else if ( 'delete' == $bp->action_variables[2] && $bp->action_variables[4] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
    694698                                /* Check the nonce */
    695                                 check_admin_referer( 'bp_forums_delete_topic' );
    696        
    697                                 if ( !groups_delete_forum_topic( $topic_id ) )
    698                                         bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
     699                                check_admin_referer( 'bp_forums_delete_post' );
     700       
     701                                if ( !groups_delete_group_forum_post( $bp->action_variables[3], $topic_id ) )
     702                                        bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' );
    699703                                else
    700                                         bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
    701 
    702                                 do_action( 'groups_delete_topic', $topic_id );
    703                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
    704                         }
    705                        
    706                                                
     704                                        bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
     705
     706                                bp_core_redirect( wp_get_referer() );
     707                        }
     708                               
    707709                        /* Editing a post */
    708                         else if ( 'edit' == $bp->action_variables[4] && $post_id = $bp->action_variables[3] ) {
     710                        else if ( 'edit' == $bp->action_variables[2] && $post_id = $bp->action_variables[4] ) {
    709711                                if ( isset( $_POST['save_changes'] ) ) {
    710712                                        /* Check the nonce */
    711713                                        check_admin_referer( 'bp_forums_edit_post' );
    712                
     714                                                       
    713715                                        if ( !groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id ) )
    714716                                                bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
    … …  
    741743                                check_admin_referer( 'bp_forums_new_topic' );
    742744                               
    743                                 if ( !groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
     745                                /* Auto join this user if they are not yet a member of this group */
     746                                if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
     747                                        groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
     748
     749                                if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
    744750                                        bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    745751                                else
    746752                                        bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    747753                                       
    748                                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     754                                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
    749755                        }
    750756                       
    … …  
    20282034                $group_desc = $bp->groups->current_group->description;
    20292035       
    2030         $forum_id = bp_forums_new_forum( array( 'forum_name' => $group_name, 'forum_description' => $group_desc ) );
    2031        
     2036        $forum_id = bp_forums_new_forum( array( 'forum_name' => $group_name, 'forum_desc' => $group_desc ) );
     2037
    20322038        groups_update_groupmeta( $group_id, 'forum_id', $forum_id );
    20332039       
    … …  
    20372043function groups_new_group_forum_post( $post_text, $topic_id ) {
    20382044        global $bp;
     2045       
     2046        if ( empty( $post_text ) )
     2047                return false;
    20392048       
    20402049        if ( $forum_post = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
    … …  
    20632072function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) {
    20642073        global $bp;
     2074       
     2075        if ( empty( $topic_title ) || empty( $topic_text ) )
     2076                return false;
    20652077       
    20662078        if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
    … …  
    21162128}
    21172129
    2118 function groups_delete_forum_topic( $topic_id ) {
    2119         global $bp;
    2120        
    2121         if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
    2122                 /* Delete the activity stream item */
    2123                 if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    2124                         bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
    2125                         bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
    2126                 }
    2127 
    2128                 do_action( 'groups_delete_forum_topic', $topic_id );
    2129                
    2130                 return true;
    2131         }
    2132        
    2133         return false;
    2134 }
    2135 
    21362130function groups_update_group_forum_post( $post_id, $post_text, $topic_id ) {
    21372131        global $bp;
    … …  
    21662160}
    21672161
    2168 // function groups_delete_forum_post( $post_id, $topic_id ) {
    2169 //      global $bp;
    2170 //     
    2171 //      if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
    2172 //              /* Delete the activity stream item */
    2173 //              if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    2174 //                      bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'secondary_item_id' => $post_id 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
    2175 //              }
    2176 //
    2177 //              do_action( 'groups_delete_forum_topic', $topic_id );
    2178 //             
    2179 //              return true;
    2180 //      }
    2181 //     
    2182 //      return false;
    2183 // }
     2162function groups_delete_group_forum_topic( $topic_id ) {
     2163        global $bp;
     2164       
     2165        if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
     2166                /* Delete the activity stream item */
     2167                if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     2168                        bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2169                        bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
     2170                }
     2171
     2172                do_action( 'groups_delete_group_forum_topic', $topic_id );
     2173               
     2174                return true;
     2175        }
     2176       
     2177        return false;
     2178}
     2179
     2180function groups_delete_group_forum_post( $post_id, $topic_id ) {
     2181        global $bp;
     2182       
     2183        if ( bp_forums_delete_post( array( 'post_id' => $post_id ) ) ) {
     2184                /* Delete the activity stream item */
     2185                if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     2186                        bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_forum_post' ) );
     2187                }
     2188
     2189                do_action( 'groups_delete_group_forum_post', $post_id, $topic_id );
     2190               
     2191                return true;
     2192        }
     2193       
     2194        return false;
     2195}
     2196
     2197
     2198function groups_total_public_forum_topic_count( $type = 'newest' ) {
     2199        return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) );
     2200}
    21842201
    21852202/*** Group Invitations *********************************************************/
  • trunk/bp-groups/bp-groups-classes.php

    r1826 r1858  
    445445                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d AND invite_sent = 1", $group_id ) );
    446446        }
     447       
     448        function get_global_forum_topic_count( $type ) {
     449                global $bbdb, $wpdb, $bp;
     450               
     451                if ( 'unreplied' == $type )
     452                        $bp->groups->filter_sql = ' AND t.topic_posts = 1';
     453               
     454                $extra_sql = apply_filters( 'groups_total_public_forum_topic_count', $bp->groups->filter_sql, $type );
     455
     456                return $wpdb->get_var( "SELECT count(t.topic_id) FROM {$bbdb->topics} AS t, {$bp->groups->table_name} AS g LEFT JOIN {$bp->groups->table_name_groupmeta} AS gm ON g.id = gm.group_id WHERE (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND t.topic_status = '0' AND t.topic_sticky != '2' {$extra_sql} " );
     457        }
    447458}
    448459
  • trunk/bp-groups/bp-groups-filters.php

    r1608 r1858  
    5757add_filter( 'groups_group_news_before_save', 'force_balance_tags' );
    5858
     59/**** Filters for group forums ****/
     60function groups_add_forum_privacy_sql() {
     61        global $bp;
     62       
     63        if ( !$bp->groups->current_group ) {
     64                add_filter( 'get_topics_fields', 'groups_add_forum_fields_sql' );
     65                add_filter( 'get_topics_index_hint', 'groups_add_forum_tables_sql' );
     66                add_filter( 'get_topics_where', 'groups_add_forum_where_sql' );
     67        }
     68}
     69add_filter( 'bbpress_init', 'groups_add_forum_privacy_sql' );
     70
     71function groups_add_forum_fields_sql( $sql ) {
     72        return $sql . ', g.id as object_id, g.name as object_name, g.slug as object_slug';
     73}
     74
     75function groups_add_forum_tables_sql( $sql ) {
     76        global $bp;
     77        return ', ' . $bp->groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id ';
     78}
     79
     80function groups_add_forum_where_sql( $sql ) {
     81        global $bp;
     82       
     83        $bp->groups->filter_sql = ' AND ' . $sql;
     84        return "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND " . $sql;
     85}
     86
     87function groups_filter_bbpress_caps( $value, $cap, $args ) {
     88        global $bp;
     89
     90        if ( is_site_admin() )
     91                return true;
     92       
     93        if ( 'add_tag_to' == $cap )
     94                if ( $bp->groups->current_group->user_has_access ) return true;
     95       
     96        if ( 'manage_forums' == $cap && is_user_logged_in() )
     97                return true;
     98       
     99        return $value;
     100}
     101add_filter( 'bb_current_user_can', 'groups_filter_bbpress_caps', 10, 3 );
     102
    59103?>
  • trunk/bp-groups/bp-groups-templatetags.php

    r1844 r1858  
    405405
    406406                return apply_filters( 'bp_get_group_type', $type );     
     407        }
     408
     409function bp_group_status() {
     410        echo bp_get_group_status();
     411}
     412        function bp_get_group_status( $group = false ) {
     413                global $groups_template;
     414
     415                if ( !$group )
     416                        $group =& $groups_template->group;
     417
     418                return apply_filters( 'bp_get_group_status', $group->status ); 
    407419        }
    408420
Note: See TracChangeset for help on using the changeset viewer.