Skip to:
Content

BuddyPress.org

Changeset 2077 for trunk/bp-forums.php


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.php

    r2033 r2077  
    44if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
    55    define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
    6    
     6
    77if ( !defined( 'BP_FORUMS_SLUG' ) )
    88    define( 'BP_FORUMS_SLUG', 'forums' );
     
    1919    /* For internal identification */
    2020    $bp->forums->id = 'forums';
    21        
     21
    2222    $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
    2323    $bp->forums->bbconfig = get_site_option( 'bb-config-location' );
    2424    $bp->forums->slug = BP_FORUMS_SLUG;
    25    
     25
    2626    /* Register this in the active components array */
    2727    $bp->active_components[$bp->forums->slug] = $bp->forums->id;
     
    3434function bp_forums_is_installed_correctly() {
    3535    global $bp;
    36    
     36
    3737    if ( file_exists( $bp->forums->bbconfig ) )
    3838        return true;
    39    
     39
    4040    return false;
    4141}
     
    5353        if ( (int) get_site_option( 'bp-disable-forum-directory' ) || !function_exists( 'groups_install' ) )
    5454            return false;
    55            
     55
    5656        if ( !bp_forums_is_installed_correctly() ) {
    5757            bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
    5858            bp_core_redirect( $bp->root_domain );
    5959        }
    60        
     60
    6161        $bp->is_directory = true;
    62        
    63         do_action( 'bbpress_init' ); 
     62
     63        do_action( 'bbpress_init' );
    6464        do_action( 'bp_forums_directory_forums_setup' );
    6565        bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'directories/forums/index' ) );
     
    7070function bp_forums_add_admin_menu() {
    7171    global $bp;
    72    
     72
    7373    if ( !is_site_admin() )
    7474        return false;
    7575
    7676    require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
    77    
     77
    7878    /* Add the administration tab under the "Site Admin" tab for site administrators */
    7979    add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
     
    9090function bp_forums_new_forum( $args = '' ) {
    9191    do_action( 'bbpress_init' );
    92    
    93     $defaults = array( 
    94         'forum_name' => '', 
    95         'forum_desc' => '', 
    96         'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID, 
    97         'forum_order' => false, 
     92
     93    $defaults = array(
     94        'forum_name' => '',
     95        'forum_desc' => '',
     96        'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
     97        'forum_order' => false,
    9898        'forum_is_category' => 0
    9999    );
     
    101101    $r = wp_parse_args( $args, $defaults );
    102102    extract( $r, EXTR_SKIP );
    103    
     103
    104104    return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
    105105}
     
    107107function bp_forums_get_forum_topicpost_count( $forum_id ) {
    108108    global $wpdb, $bbdb;
    109    
     109
    110110    do_action( 'bbpress_init' );
    111111
     
    118118function bp_forums_get_forum_topics( $args = '' ) {
    119119    global $bp;
    120    
    121     do_action( 'bbpress_init' );
    122    
     120
     121    do_action( 'bbpress_init' );
     122
    123123    $defaults = array(
    124124        'type' => 'newest',
    125         'forum_id' => false, 
    126         'page' => 1, 
    127         'per_page' => 15, 
     125        'forum_id' => false,
     126        'page' => 1,
     127        'per_page' => 15,
    128128        'exclude' => false,
    129129        'show_stickies' => 'all',
    130130        'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
    131131    );
    132    
     132
    133133    $r = wp_parse_args( $args, $defaults );
    134134    extract( $r, EXTR_SKIP );
     
    139139            $topics = $query->results;
    140140        break;
    141        
     141
    142142        case 'popular':
    143143            $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 ) );
    144144            $topics =& $query->results;
    145145        break;
    146        
     146
    147147        case 'unreplied':
    148148            $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 ) );
    149149            $topics =& $query->results;
    150         break; 
    151        
     150        break;
     151
    152152        case 'personal':
    153153            $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' );
    154154            $topics =& $query->results;
    155155        break;
    156        
     156
    157157        case 'tag':
    158158            $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 ) );
     
    167167    do_action( 'bbpress_init' );
    168168
    169     $query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ ); 
     169    $query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
    170170
    171171    return $query->results[0];
     
    179179function bp_forums_new_topic( $args = '' ) {
    180180    global $bp;
    181    
    182     do_action( 'bbpress_init' );
    183    
     181
     182    do_action( 'bbpress_init' );
     183
    184184    $defaults = array(
    185185        'topic_title' => '',
     
    198198    $r = wp_parse_args( $args, $defaults );
    199199    extract( $r, EXTR_SKIP );
    200    
     200
    201201    if ( empty( $topic_slug ) )
    202202        $topic_slug = sanitize_title( $topic_title );
    203        
     203
    204204    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 ) ) )
    205205        return false;
     
    208208    if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
    209209        return false;
    210    
     210
    211211    return $topic_id;
    212212}
     
    214214function bp_forums_update_topic( $args = '' ) {
    215215    global $bp;
    216    
    217     do_action( 'bbpress_init' );
    218    
     216
     217    do_action( 'bbpress_init' );
     218
    219219    $defaults = array(
    220220        'topic_id' => false,
     
    225225    $r = wp_parse_args( $args, $defaults );
    226226    extract( $r, EXTR_SKIP );
    227    
     227
    228228    if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
    229229        return false;
    230    
     230
    231231    if ( !$post = bb_get_first_post( $topic_id ) )
    232232        return false;
     
    235235    if ( !$post = bb_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) )
    236236        return false;
    237    
     237
    238238    return bp_forums_get_topic_details( $topic_id );
    239239}
     
    241241function bp_forums_sticky_topic( $args = '' ) {
    242242    global $bp;
    243    
    244     do_action( 'bbpress_init' );
    245    
     243
     244    do_action( 'bbpress_init' );
     245
    246246    $defaults = array(
    247247        'topic_id' => false,
     
    251251    $r = wp_parse_args( $args, $defaults );
    252252    extract( $r, EXTR_SKIP );
    253    
     253
    254254    if ( 'stick' == $mode )
    255255        return bb_stick_topic( $topic_id );
     
    262262function bp_forums_openclose_topic( $args = '' ) {
    263263    global $bp;
    264    
    265     do_action( 'bbpress_init' );
    266    
     264
     265    do_action( 'bbpress_init' );
     266
    267267    $defaults = array(
    268268        'topic_id' => false,
     
    272272    $r = wp_parse_args( $args, $defaults );
    273273    extract( $r, EXTR_SKIP );
    274    
     274
    275275    if ( 'close' == $mode )
    276276        return bb_close_topic( $topic_id );
     
    283283function bp_forums_delete_topic( $args = '' ) {
    284284    global $bp;
    285    
    286     do_action( 'bbpress_init' );
    287    
     285
     286    do_action( 'bbpress_init' );
     287
    288288    $defaults = array(
    289289        'topic_id' => false
     
    296296}
    297297
    298 /* Post Functions */ 
     298/* Post Functions */
    299299
    300300function bp_forums_get_topic_posts( $args = '' ) {
    301301    do_action( 'bbpress_init' );
    302    
    303     $defaults = array( 
    304         'topic_id' => false, 
     302
     303    $defaults = array(
     304        'topic_id' => false,
    305305        'page' => 1,
    306306        'per_page' => 15,
     
    321321function bp_forums_delete_post( $args = '' ) {
    322322    global $bp;
    323    
    324     do_action( 'bbpress_init' );
    325    
     323
     324    do_action( 'bbpress_init' );
     325
    326326    $defaults = array(
    327327        'post_id' => false
     
    331331    extract( $r, EXTR_SKIP );
    332332
    333     return bb_delete_post( $post_id, 1 );   
     333    return bb_delete_post( $post_id, 1 );
    334334}
    335335
    336336function bp_forums_insert_post( $args = '' ) {
    337337    global $bp;
    338    
    339     do_action( 'bbpress_init' );
    340 
    341     $defaults = array(
    342         'post_id' => false, 
     338
     339    do_action( 'bbpress_init' );
     340
     341    $defaults = array(
     342        'post_id' => false,
    343343        'topic_id' => false,
    344344        'post_text' => '',
     
    352352    $r = wp_parse_args( $args, $defaults );
    353353    extract( $r, EXTR_SKIP );
    354    
     354
    355355    if ( !$post = bp_forums_get_post( $post_id ) )
    356356        $post_id = false;
     
    358358    if ( !isset( $topic_id ) )
    359359        $topic_id = $post->topic_id;
    360    
     360
    361361    if ( empty( $post_text ) )
    362362        $post_text = $post->post_text;
    363    
     363
    364364    if ( !isset( $post_time ) )
    365365        $post_time = $post->post_time;
     
    378378function bp_forums_filter_caps( $allcaps ) {
    379379    global $bp, $wp_roles, $bb_table_prefix;
    380    
     380
    381381    $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' );
    382382
    383383    if ( empty( $bb_cap ) )
    384384        return $allcaps;
    385    
     385
    386386    $bb_cap = array_keys($bb_cap);
    387387    $bb_cap = $wp_roles->get_role( $bb_cap[0] );
    388388    $bb_cap = $bb_cap->capabilities;
    389    
     389
    390390    return array_merge( (array) $allcaps, (array) $bb_cap );
    391391}
Note: See TracChangeset for help on using the changeset viewer.