Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-forums.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums.php

    r3713 r3728  
    11<?php
    22
    3 /* Define the parent forum ID */
     3// Define the parent forum ID
    44if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
    55    define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
     
    1919function bp_forums_setup() {
    2020    global $bp;
    21        
    22         if ( !defined( 'BP_FORUMS_SLUG' ) )
    23                 define ( 'BP_FORUMS_SLUG', $bp->pages->forums->slug );
     21
     22    if ( !defined( 'BP_FORUMS_SLUG' ) )
     23        define ( 'BP_FORUMS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->forums->slug ) );
    2424
    2525    // For internal identification
    2626    $bp->forums->id = 'forums';
    2727
     28    // Slugs
     29    $bp->forums->slug      = BP_FORUMS_SLUG;
     30    $bp->forums->root_slug = $bp->pages->forums->slug;
     31
     32    // Images
    2833    $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
    29     $bp->forums->slug = BP_FORUMS_SLUG;
    3034
    3135    if ( isset( $bp->site_options['bb-config-location'] ) )
     
    8185        do_action( 'bbpress_init' );
    8286
    83         /* Check to see if the user has posted a new topic from the forums page. */
     87        // Check to see if the user has posted a new topic from the forums page.
    8488        if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
    85             /* Check the nonce */
    8689            check_admin_referer( 'bp_forums_new_topic' );
    8790
    8891            if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
    89                 /* Auto join this user if they are not yet a member of this group */
     92                // Auto join this user if they are not yet a member of this group
    9093                if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    9194                    groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
     
    134137    require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
    135138
    136     /* Add the administration tab under the "Site Admin" tab for site administrators */
     139    // Add the administration tab under the "Site Admin" tab for site administrators
    137140    add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
    138141}
    139142add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_forums_add_admin_menu' );
    140143
    141 /* Forum Functions */
     144/** Forum Functions ***********************************************************/
    142145
    143146function bp_forums_get_forum( $forum_id ) {
     
    150153
    151154    $defaults = array(
    152         'forum_name' => '',
    153         'forum_desc' => '',
    154         'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
    155         'forum_order' => false,
     155        'forum_name'        => '',
     156        'forum_desc'        => '',
     157        'forum_parent_id'   => BP_FORUMS_PARENT_FORUM_ID,
     158        'forum_order'       => false,
    156159        'forum_is_category' => 0
    157160    );
     
    182185}
    183186
    184 /* Topic Functions */
     187/** Topic Functions ***********************************************************/
    185188
    186189function bp_forums_get_forum_topics( $args = '' ) {
     
    207210            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
    208211            $topics =& $query->results;
    209         break;
     212            break;
    210213
    211214        case 'popular':
    212215            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
    213216            $topics =& $query->results;
    214         break;
     217            break;
    215218
    216219        case 'unreplied':
    217220            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
    218221            $topics =& $query->results;
    219         break;
     222            break;
    220223
    221224        case 'tags':
    222225            $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
    223226            $topics =& $query->results;
    224         break;
     227            break;
    225228    }
    226229
     
    247250
    248251    $defaults = array(
    249         'topic_title' => '',
    250         'topic_slug' => '',
    251         'topic_text' => '',
    252         'topic_poster' => $bp->loggedin_user->id, // accepts ids
    253         'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
    254         'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
     252        'topic_title'            => '',
     253        'topic_slug'             => '',
     254        'topic_text'             => '',
     255        'topic_poster'           => $bp->loggedin_user->id, // accepts ids
     256        'topic_poster_name'      => $bp->loggedin_user->fullname, // accept names
     257        'topic_last_poster'      => $bp->loggedin_user->id, // accepts ids
    255258        'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
    256         'topic_start_time' => bp_core_current_time(),
    257         'topic_time' => bp_core_current_time(),
    258         'topic_open' => 1,
    259         'topic_tags' => false, // accepts array or comma delim
    260         'forum_id' => 0 // accepts ids or slugs
     259        'topic_start_time'       => bp_core_current_time(),
     260        'topic_time'             => bp_core_current_time(),
     261        'topic_open'             => 1,
     262        'topic_tags'             => false, // accepts array or comma delim
     263        'forum_id'               => 0 // accepts ids or slugs
    261264    );
    262265
     
    275278        return false;
    276279
    277     /* Now insert the first post. */
     280    // Now insert the first post.
    278281    if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
    279282        return false;
     
    290293
    291294    $defaults = array(
     295        'topic_id'    => false,
     296        'topic_title' => '',
     297        'topic_text'  => ''
     298    );
     299
     300    $r = wp_parse_args( $args, $defaults );
     301    extract( $r, EXTR_SKIP );
     302
     303    if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
     304        return false;
     305
     306    if ( !$post = bb_get_first_post( $topic_id ) )
     307        return false;
     308
     309    // Update the first post
     310    if ( !$post = bp_forums_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 ) ) )
     311        return false;
     312
     313    return bp_forums_get_topic_details( $topic_id );
     314}
     315
     316function bp_forums_sticky_topic( $args = '' ) {
     317    global $bp;
     318
     319    do_action( 'bbpress_init' );
     320
     321    $defaults = array(
    292322        'topic_id' => false,
    293         'topic_title' => '',
    294         'topic_text' => ''
    295     );
    296 
    297     $r = wp_parse_args( $args, $defaults );
    298     extract( $r, EXTR_SKIP );
    299 
    300     if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
    301         return false;
    302 
    303     if ( !$post = bb_get_first_post( $topic_id ) )
    304         return false;
    305 
    306     /* Update the first post */
    307     if ( !$post = bp_forums_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 ) ) )
    308         return false;
    309 
    310     return bp_forums_get_topic_details( $topic_id );
    311 }
    312 
    313 function bp_forums_sticky_topic( $args = '' ) {
    314     global $bp;
    315 
    316     do_action( 'bbpress_init' );
    317 
    318     $defaults = array(
    319         'topic_id' => false,
    320         'mode' => 'stick' // stick/unstick
     323        'mode'     => 'stick' // stick/unstick
    321324    );
    322325
     
    339342    $defaults = array(
    340343        'topic_id' => false,
    341         'mode' => 'close' // stick/unstick
     344        'mode'     => 'close' // stick/unstick
    342345    );
    343346
     
    398401        return $topics;
    399402
    400     /* Get the topic ids */
     403    // Get the topic ids
    401404    foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
    402405    $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
    403406
    404     /* Fetch the topic's last poster details */
     407    // Fetch the topic's last poster details
    405408    $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
    406409    for ( $i = 0; $i < count( $topics ); $i++ ) {
    407410        foreach ( (array)$poster_details as $poster ) {
    408411            if ( $poster->topic_id == $topics[$i]->topic_id ) {
    409                 $topics[$i]->topic_last_poster_email = $poster->user_email;
    410                 $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
    411                 $topics[$i]->topic_last_poster_login = $poster->user_login;
     412                $topics[$i]->topic_last_poster_email       = $poster->user_email;
     413                $topics[$i]->topic_last_poster_nicename    = $poster->user_nicename;
     414                $topics[$i]->topic_last_poster_login       = $poster->user_login;
    412415                $topics[$i]->topic_last_poster_displayname = $poster->display_name;
    413416            }
     
    415418    }
    416419
    417     /* Fetch fullname for the topic's last poster */
     420    // Fetch fullname for the topic's last poster
    418421    if ( bp_is_active( 'xprofile' ) ) {
    419422        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
     
    429432}
    430433
    431 /* Post Functions */
     434/** Post Functions ************************************************************/
    432435
    433436function bp_forums_get_topic_posts( $args = '' ) {
     
    436439    $defaults = array(
    437440        'topic_id' => false,
    438         'page' => 1,
     441        'page'     => 1,
    439442        'per_page' => 15,
    440         'order' => 'ASC'
    441     );
    442 
    443     $args = wp_parse_args( $args, $defaults );
    444 
     443        'order'    => 'ASC'
     444    );
     445
     446    $args  = wp_parse_args( $args, $defaults );
    445447    $query = new BB_Query( 'post', $args, 'get_thread' );
     448
    446449    return bp_forums_get_post_extras( $query->results );
    447450}
     
    473476
    474477    $defaults = array(
    475         'post_id' => false,
    476         'topic_id' => false,
    477         'post_text' => '',
    478         'post_time' => bp_core_current_time(),
    479         'poster_id' => $bp->loggedin_user->id, // accepts ids or names
    480         'poster_ip' => $_SERVER['REMOTE_ADDR'],
    481         'post_status' => 0, // use bb_delete_post() instead
     478        'post_id'       => false,
     479        'topic_id'      => false,
     480        'post_text'     => '',
     481        'post_time'     => bp_core_current_time(),
     482        'poster_id'     => $bp->loggedin_user->id, // accepts ids or names
     483        'poster_ip'     => $_SERVER['REMOTE_ADDR'],
     484        'post_status'   => 0, // use bb_delete_post() instead
    482485        'post_position' => false
    483486    );
     
    503506    $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
    504507
    505     if ( $post_id )
     508    if ( !empty( $post_id ) )
    506509        do_action( 'bp_forums_new_post', $post_id );
    507510
     
    515518        return $posts;
    516519
    517     /* Get the user ids */
     520    // Get the user ids
    518521    foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
    519522    $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    520523
    521     /* Fetch the poster's user_email, user_nicename and user_login */
     524    // Fetch the poster's user_email, user_nicename and user_login
    522525    $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
    523526
     
    525528        foreach ( (array)$poster_details as $poster ) {
    526529            if ( $poster->user_id == $posts[$i]->poster_id ) {
    527                 $posts[$i]->poster_email = $poster->user_email;
    528                 $posts[$i]->poster_login = $poster->user_nicename;
     530                $posts[$i]->poster_email    = $poster->user_email;
     531                $posts[$i]->poster_login    = $poster->user_nicename;
    529532                $posts[$i]->poster_nicename = $poster->user_login;
    530                 $posts[$i]->poster_name = $poster->display_name;
     533                $posts[$i]->poster_name     = $poster->display_name;
    531534            }
    532535        }
    533536    }
    534537
    535     /* Fetch fullname for each poster. */
     538    // Fetch fullname for each poster.
    536539    if ( bp_is_active( 'xprofile' ) ) {
    537540        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
     
    552555    do_action( 'bbpress_init' );
    553556
    554     /* Need to find a bbPress function that does this */
     557    // Need to find a bbPress function that does this
    555558    return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
    556559}
     
    586589add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
    587590add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
    588 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
     591add_action( 'bp_forums_new_post',  'bp_core_clear_cache' );
     592
    589593?>
Note: See TracChangeset for help on using the changeset viewer.