Skip to:
Content

BuddyPress.org

Changeset 1621


Ignore:
Timestamp:
07/21/2009 09:45:28 PM (16 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
Files:
5 added
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r1599 r1621  
    189189    extract( $r, EXTR_SKIP );
    190190   
     191    /* Insert the "time-since" placeholder */
     192    if ( $content ) {
     193        if ( !$pos = strpos( $content, '<blockquote' ) ) {
     194            if ( !$pos = strpos( $content, '<div' ) ) {
     195                if ( !$pos = strpos( $content, '<ul' ) ) {
     196                    $content .= ' <span class="time-since">%s</span>';
     197                }
     198            }
     199        }
     200       
     201        if ( $pos ) {
     202            $before = substr( $content, 0, $pos );
     203            $after = substr( $content, $pos, strlen( $content ) );
     204           
     205            $content = $before . ' <span class="time-since">%s</span>' . $after;
     206        }
     207    }
     208
    191209    $activity = new BP_Activity_Activity;
    192210    $activity->user_id = $user_id;
     
    208226}
    209227
    210 function bp_activity_update( $args = '' ) {
    211     global $bp, $wpdb;
    212    
    213     extract( $args );
    214    
     228/* There are multiple ways to delete activity items, depending on the information you have at the time. */
     229
     230function bp_activity_delete_by_item_id( $args = '' ) {
     231    global $bp;
     232
    215233    $defaults = array(
    216         'user_id' => $bp->loggedin_user->id,
    217         'content' => false,
     234        'item_id' => false,
    218235        'component_name' => false,
    219236        'component_action' => false,
    220         'item_id' => false,
    221         'secondary_item_id' => false,
    222         'recorded_time' => time(),
    223         'hide_sitewide' => false
     237        'user_id' => false, // optional
     238        'secondary_item_id' => false // optional
    224239    );
    225240
    226241    $r = wp_parse_args( $args, $defaults );
    227242    extract( $r, EXTR_SKIP );
    228        
    229     $activity = new BP_Activity_Activity( $user_id, $component_name, $component_action, $item_id, $secondary_item_id );
    230     $activity->user_id = $user_id;
    231     $activity->content = $content;
    232     $activity->primary_link = $primary_link;
    233     $activity->component_name = $component_name;
    234     $activity->component_action = $component_action;
    235     $activity->item_id = $item_id;
    236     $activity->secondary_item_id = $secondary_item_id;
    237     $activity->date_recorded = $recorded_time;
    238     $activity->hide_sitewide = $hide_sitewide;
    239        
    240     if ( !$activity->save() )
    241         return false;
    242 
    243     do_action( 'bp_activity_update', $args );
    244    
    245     return true;
    246 }
    247 
    248 /* There are multiple ways to delete activity items, depending on the information you have at the time. */
    249 
    250 function bp_activity_delete_by_item_id( $user_id, $component_name, $component_action, $item_id, $secondary_item_id = false ) { 
    251     if ( !BP_Activity_Activity::delete_by_item_id( $user_id, $component_name, $component_action, $item_id, $secondary_item_id ) )
    252         return false;
    253 
    254     do_action( 'bp_activity_delete_by_item_id', $user_id, $component_name, $component_action, $item_id, $secondary_item_id );
     243
     244    if ( !BP_Activity_Activity::delete_by_item_id( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) )
     245        return false;
     246
     247    do_action( 'bp_activity_delete_by_item_id', $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    255248
    256249    return true;
     
    345338/* DEPRECATED - use bp_activity_delete_by_item_id() */
    346339function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) {
    347     if ( !bp_activity_delete_by_item_id( $user_id, $component_name, $component_action, $item_id, $secondary_item_id ) )
     340    if ( !bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component_name' => $component_name, 'component_action' => $component_action, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) ) )
    348341        return false;
    349342       
  • trunk/bp-activity/bp-activity-classes.php

    r1595 r1621  
    1515        global $bp;
    1616       
    17         if ( $args ) {
     17        if ( $args && is_array($args) ) {
    1818            extract( $args );
    1919           
     
    106106    /* Static Functions */
    107107
    108     function delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id = false ) {
    109         global $wpdb, $bp;
    110                
    111         if ( !$user_id )
    112             return false;
     108    function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
     109        global $wpdb, $bp;
    113110
    114111        if ( $secondary_item_id )
     
    116113       
    117114        if ( $component_action )
    118             $component_action_sql = $wpdb->prepare( "AND component_action = %s AND user_id = %d", $component_action, $user_id );
    119                
    120         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %d {$secondary_sql} AND component_name = %s {$cached_component_action_sql}", $user_id, $item_id, $component_name ) );
    121     }
    122    
    123     function delete_by_item_id( $user_id, $component_name, $component_action, $item_id, $secondary_item_id = false ) {
     115            $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
     116       
     117        if ( $user_id )
     118            $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id );
     119
     120        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
     121    }
     122   
     123    function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
    124124        return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    125125    }
  • trunk/bp-blogs.php

    r1599 r1621  
    408408            $recorded_post->blog_id = $blog_id;
    409409            $recorded_post->post_id = $post_id;
    410             $recorded_post->date_created = strtotime( $post->post_date );
     410            $recorded_post->date_created = strtotime( $post->post_date_gmt );
    411411           
    412412            $recorded_post_id = $recorded_post->save();
    413413           
    414414            bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', time() );
    415             bp_blogs_record_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime( $post->post_date ) ) );
     415            bp_blogs_record_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime( $post->post_date_gmt ) ) );
    416416        }
    417417    } else {
     
    439439        /* Delete and re-add the activity stream item to reflect potential content changes. */
    440440        bp_blogs_delete_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'user_id' => $recorded_post->user_id ) );
    441         bp_blogs_record_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime( $post->post_date ) ) );
     441        bp_blogs_record_activity( array( 'item_id' => $recorded_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post', 'is_private' => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), 'user_id' => $recorded_post->user_id, 'recorded_time' => strtotime( $post->post_date_gmt ) ) );
    442442    }
    443443
  • trunk/bp-core.php

    r1619 r1621  
    15401540    global $wpdb;
    15411541    ?>
    1542 <!-- Generated in <?php timer_stop(1); ?> seconds. -->
     1542<!-- Generated in <?php timer_stop(1); ?> seconds. <?php echo $wpdb->num_queries; ?> queries.-->
    15431543    <?php
    15441544}
  • trunk/bp-core/css/structure.css

    r1366 r1621  
    8585            }
    8686
    87             div.info-group h4 a {
     87            div.info-group h4 span {
    8888                position: absolute;
    8989                top: 0.31em;
  • trunk/bp-forums

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

    r1547 r1621  
    55    define ( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
    66
    7 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress-live.php' );
     7require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' );
     8require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-classes.php' );
    89require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-templatetags.php' );
    910require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-filters.php' );
    10 
    11 if ( is_admin() )
    12     require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
     11require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-cssjs.php' );
    1312
    1413function bp_forums_setup() {
    15     global $bp, $bbpress_live;
    16 
    17     if ( '' == get_usermeta( $bp->loggedin_user->id, 'bb_capabilities' ) )
    18         bp_forums_make_user_active_member( $bp->loggedin_user->id );
    19    
    20     $bp->version_numbers->forums = BP_FORUMS_VERSION;
     14    global $bp;
     15   
     16    $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
     17    $bp->forums->bbconfig = get_site_option( 'bb-config-location' );
    2118}
    2219add_action( 'plugins_loaded', 'bp_forums_setup', 5 );
     
    2421
    2522function bp_forums_is_installed_correctly() {
    26     global $bbpress_live;
    27    
    28     if ( !is_object( $bbpress_live ) ) {
    29         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    30         $bbpress_live = new bbPress_Live();
    31     }
    32    
    33     if ( !$bbpress_live->fetch->endpoint )
    34         return false;
    35    
    36     return true;
    37 }
    38 
    39 function bp_forums_get_forum( $parent = 0, $depth = 0 ) {
    40     global $bbpress_live;
    41    
    42     if ( !is_object( $bbpress_live ) ) {
    43         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    44         $bbpress_live = new bbPress_Live();
    45     }
    46    
    47     if ( $forum = $bbpress_live->get_forums( $parent, $depth ) ) {
    48         do_action( 'bp_forums_get_forum', $forum );
    49         return $forum;
    50     }
     23    global $bp;
     24   
     25    if ( file_exists( $bp->forums->bbconfig ) )
     26        return true;
    5127   
    5228    return false;
    5329}
    5430
    55 function bp_forums_get_topics( $forum_id = 0, $number = 0, $page = 1 ) {
    56     global $bbpress_live;
    57    
    58     if ( !is_object( $bbpress_live ) ) {
    59         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    60         $bbpress_live = new bbPress_Live();
    61     }
    62    
    63     if ( $topics = $bbpress_live->get_topics( $forum_id, $number, $page ) ) {
    64         do_action( 'bp_forums_get_topics', $topics );
    65         return $topics;
    66     }
    67    
     31function bp_forums_add_admin_menu() {
     32    global $bp;
     33   
     34    if ( !is_site_admin() )
     35        return false;
     36
     37    require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
     38   
     39    /* Add the administration tab under the "Site Admin" tab for site administrators */
     40    add_submenu_page( 'bp-core.php', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 2, __FILE__, "bp_forums_bbpress_admin" );
     41}
     42add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
     43
     44function bp_forums_get_forum( $forum_id ) {
     45    do_action( 'bbpress_init' );
     46    return bb_get_forum( $forum_id );
     47}
     48
     49function bp_forums_get_forum_topics( $args = '' ) {
     50    do_action( 'bbpress_init' );
     51   
     52    $defaults = array(
     53        'forum_id' => false,
     54        'page' => 1,
     55        'per_page' => 15,
     56        'exclude' => false
     57    );
     58
     59    $r = wp_parse_args( $args, $defaults );
     60    extract( $r, EXTR_SKIP );
     61   
     62    return get_latest_topics( array( 'forum' => $forum_id, 'page' => $page_num, 'number' => $per_page, 'exclude' => $exclude ) );
     63}
     64
     65function bp_forums_get_topic_details( $topic_id ) {
     66    do_action( 'bbpress_init' );
     67    return get_topic( $topic_id );
     68}
     69
     70function bp_forums_get_topic_id_from_slug( $topic_slug ) {
     71    do_action( 'bbpress_init' );   
     72    return bb_get_id_from_slug( 'topic', $topic_slug );
     73}
     74
     75function bp_forums_get_topic_posts( $args = '' ) {
     76    do_action( 'bbpress_init' );
     77   
     78    $defaults = array(
     79        'topic_id' => false,
     80        'page' => 1,
     81        'per_page' => 15,
     82        'order' => 'ASC'
     83    );
     84
     85    $args = wp_parse_args( $args, $defaults );
     86
     87    $query = new BB_Query( 'post', $args, 'get_thread' );
     88    return $query->results;
     89}
     90
     91function bp_forums_get_post( $post_id ) {
     92    do_action( 'bbpress_init' );
     93    return bb_get_post( $post_id );
     94}
     95
     96function bp_forums_new_forum( $args = '' ) {
     97    do_action( 'bbpress_init' );
     98   
     99    $defaults = array(
     100        'forum_name' => '',
     101        'forum_desc' => '',
     102        'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
     103        'forum_order' => false,
     104        'forum_is_category' => 0
     105    );
     106
     107    $r = wp_parse_args( $args, $defaults );
     108    extract( $r, EXTR_SKIP );
     109   
     110    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 ) );
     111}
     112
     113function bp_forums_new_topic( $args = '' ) {
     114    global $bp;
     115   
     116    do_action( 'bbpress_init' );
     117   
     118    $defaults = array(
     119        'topic_title' => '',
     120        'topic_slug' => '',
     121        'topic_poster' => $bp->loggedin_user->id, // accepts ids
     122        'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
     123        'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
     124        'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
     125        'topic_start_time' => bb_current_time( 'mysql' ),
     126        'topic_time' => bb_current_time( 'mysql' ),
     127        'topic_open' => 1,
     128        'forum_id' => 0 // accepts ids or slugs
     129    );
     130
     131    $r = wp_parse_args( $args, $defaults );
     132    extract( $r, EXTR_SKIP );
     133   
     134    if ( empty( $topic_slug ) )
     135        $topic_slug = sanitize_title( $topic_title );
     136       
     137    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 ) ) )
     138        return false;
     139   
     140    /* Now insert the first post. */
     141    if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
     142        return false;
     143   
     144    return $topic_id;
     145}
     146
     147function bp_forums_update_topic( $args = '' ) {
     148    global $bp;
     149   
     150    do_action( 'bbpress_init' );
     151   
     152    $defaults = array(
     153        'topic_id' => false,
     154        'topic_title' => '',
     155        'topic_text' => ''
     156    );
     157
     158    $r = wp_parse_args( $args, $defaults );
     159    extract( $r, EXTR_SKIP );
     160   
     161    if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
     162        return false;
     163   
     164    if ( !$post = bb_get_first_post( $topic_id ) )
     165        return false;
     166
     167    /* Update the first post */
     168    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 ) ) )
     169        return false;
     170   
     171    return bp_forums_get_topic_details( $topic_id );
     172}
     173
     174function bp_forums_sticky_topic( $args = '' ) {
     175    global $bp;
     176   
     177    do_action( 'bbpress_init' );
     178   
     179    $defaults = array(
     180        'topic_id' => false,
     181        'mode' => 'stick' // stick/unstick
     182    );
     183
     184    $r = wp_parse_args( $args, $defaults );
     185    extract( $r, EXTR_SKIP );
     186   
     187    if ( 'stick' == $mode )
     188        return bb_stick_topic( $topic_id );
     189    else if ( 'unstick' == $mode )
     190        return bb_unstick_topic( $topic_id );
     191
    68192    return false;
    69193}
    70194
    71 function bp_forums_get_topic_details( $topic_id = 0 ) {
    72     global $bbpress_live;
    73    
    74     if ( !is_object( $bbpress_live ) ) {
    75         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    76         $bbpress_live = new bbPress_Live();
    77     }
    78    
    79     if ( $topic = $bbpress_live->get_topic_details( $topic_id ) ) {
    80         do_action( 'bp_forums_get_topic_details', $topic );
    81         return $topic;
    82     }
    83    
     195function bp_forums_openclose_topic( $args = '' ) {
     196    global $bp;
     197   
     198    do_action( 'bbpress_init' );
     199   
     200    $defaults = array(
     201        'topic_id' => false,
     202        'mode' => 'close' // stick/unstick
     203    );
     204
     205    $r = wp_parse_args( $args, $defaults );
     206    extract( $r, EXTR_SKIP );
     207   
     208    if ( 'close' == $mode )
     209        return bb_close_topic( $topic_id );
     210    else if ( 'open' == $mode )
     211        return bb_open_topic( $topic_id );
     212
    84213    return false;
    85214}
    86215
    87 function bp_forums_get_posts( $topic_id = 0, $number = 0, $page = 1 ) {
    88     global $bbpress_live;
    89    
    90     if ( !is_object( $bbpress_live ) ) {
    91         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    92         $bbpress_live = new bbPress_Live();
    93     }
    94    
    95     if ( $posts = $bbpress_live->get_posts( $topic_id, $number, $page ) ) {
    96         do_action( 'bp_forums_get_posts', $posts );
    97         return $posts;
    98     }
    99 
    100     return false;
    101 }
    102 
    103 function bp_forums_get_post( $post_id = 0 ) {
    104     global $bbpress_live;
    105    
    106     if ( !is_object( $bbpress_live ) ) {
    107         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    108         $bbpress_live = new bbPress_Live();
    109     }
    110            
    111     if ( $post = $bbpress_live->get_post( $post_id ) ) {
    112         do_action( 'bp_forums_get_post', $post );
    113         return $post;
    114     }
    115 
    116     return false;
    117 }
    118 
    119 function bp_forums_new_forum( $name = '', $desc = '', $parent = BP_FORUMS_PARENT_FORUM_ID, $order = 0, $is_category = false ) {
    120     global $bbpress_live;
    121    
    122     if ( !is_object( $bbpress_live ) ) {
    123         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    124         $bbpress_live = new bbPress_Live();
    125     }
    126    
    127     if ( $forum = $bbpress_live->new_forum( $name, $desc, $parent, $order, $is_category ) ) {
    128         do_action( 'bp_forums_new_forum', $forum );
    129         return $forum;
    130     }
    131    
    132     return false;
    133 }
    134 
    135 function bp_forums_new_topic( $title = '', $topic_text = '', $topic_tags = '', $forum_id = 0 ) {
    136     global $bbpress_live;
    137    
    138     if ( !is_object( $bbpress_live ) ) {
    139         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    140         $bbpress_live = new bbPress_Live();
    141     }
    142    
    143     $topic_text = apply_filters( 'bp_forums_new_post_text', $topic_text );
    144     $title = apply_filters( 'bp_forums_new_post_title', $title );
    145     $topic_tags = apply_filters( 'bp_forums_new_post_tags', $topic_tags );
    146    
    147     if ( $topic = $bbpress_live->new_topic( $title, $topic_text, $topic_tags, (int)$forum_id ) ) {
    148         do_action( 'bp_forums_new_topic', $topic );
    149         return $topic;
    150     }
    151    
    152     return false;
    153 }
    154 
    155 function bp_forums_new_post( $post_text = '', $topic_id = 0 ) {
    156     global $bbpress_live;
    157    
    158     if ( !is_object( $bbpress_live ) ) {
    159         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    160         $bbpress_live = new bbPress_Live();
    161     }
    162    
    163     $post_text = apply_filters( 'bp_forums_new_post_text', $post_text );
    164    
    165     if ( $post = $bbpress_live->new_post( $post_text, (int)$topic_id ) ) {
    166         do_action( 'bp_forums_new_post', $post );
    167         return $post;
    168     }
    169    
    170     return false;
     216function bp_forums_delete_topic( $args = '' ) {
     217    global $bp;
     218   
     219    do_action( 'bbpress_init' );
     220   
     221    $defaults = array(
     222        'topic_id' => false
     223    );
     224
     225    $r = wp_parse_args( $args, $defaults );
     226    extract( $r, EXTR_SKIP );
     227
     228    return bb_delete_topic( $topic_id, 1 );
     229}
     230
     231function bp_forums_insert_post( $args = '' ) {
     232    global $bp;
     233   
     234    do_action( 'bbpress_init' );
     235
     236    $defaults = array(
     237        'post_id' => false,
     238        'topic_id' => false,
     239        'post_text' => '',
     240        'post_time' => bb_current_time( 'mysql' ),
     241        'poster_id' => $bp->loggedin_user->id, // accepts ids or names
     242        'poster_ip' => $_SERVER['REMOTE_ADDR'],
     243        'post_status' => 0, // use bb_delete_post() instead
     244        'post_position' => false
     245    );
     246
     247    $r = wp_parse_args( $args, $defaults );
     248    extract( $r, EXTR_SKIP );
     249   
     250    if ( !$post = bp_forums_get_post( $post_id ) )
     251        $post_id = false;
     252
     253    if ( !isset( $topic_id ) )
     254        $topic_id = $post->topic_id;
     255   
     256    if ( empty( $post_text ) )
     257        $post_text = $post->post_text;
     258   
     259    if ( !isset( $post_time ) )
     260        $post_time = $post->post_time;
     261
     262    if ( !isset( $post_position ) )
     263        $post_position = $post->post_position;
     264
     265    return bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( $post_text ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
    171266}
    172267
     
    189284add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
    190285
    191 
    192 
     286function bb_forums_filter_caps( $allcaps ) {
     287    global $bp, $wp_roles, $bb_table_prefix;
     288   
     289    $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' );
     290
     291    if ( empty( $bb_cap ) )
     292        return $allcaps;
     293   
     294    $bb_cap = array_keys($bb_cap);
     295    $bb_cap = $wp_roles->get_role( $bb_cap[0] );
     296    $bb_cap = $bb_cap->capabilities;
     297   
     298    return array_merge( (array) $allcaps, (array) $bb_cap );
     299}
     300add_filter( 'user_has_cap', 'bb_forums_filter_caps' );
    193301?>
  • trunk/bp-forums/bp-forums-admin.php

    r1366 r1621  
    11<?php
    2 function bp_forums_add_admin_menu() {
    3     global $wpdb, $bp;
    4 
    5     if ( is_site_admin() ) {
    6         /* Add the administration tab under the "Site Admin" tab for site administrators */
    7         add_submenu_page( 'bp-core.php', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 2, __FILE__, "bp_forums_bbpress_admin" );
    8     }
    9 }
    10 add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
    112
    123function bp_forums_bbpress_admin() {
    13     global $bp, $bbpress_live;
    14    
    15     if ( !is_object( $bbpress_live ) ) {
    16         include_once( ABSPATH . WPINC . '/class-IXR.php' );
    17         $bbpress_live = new bbPress_Live();
    18     }
    19    
    20     if ( isset( $_POST['submit'] ) ) {
    21         check_admin_referer('bbpress-settings');
    22 
    23         $_fetch_options = array(
    24             'target_uri' => stripslashes((string) $_POST['target_uri']),
    25             'username' => stripslashes((string) $_POST['username']),
    26             'password' => stripslashes((string) $_POST['password']),
    27             'always_use_auth' => (bool) $_POST['always_use_auth']
    28         );
    29         update_option( 'bbpress_live_fetch', $_fetch_options );
    30 
    31         $_options = array(
    32             'cache_enabled' => (bool) $_POST['cache_enabled'],
    33             'cache_timeout' => (int) $_POST['cache_timeout'],
    34             'widget_forums' => (bool) $_POST['widget_forums'],
    35             'widget_topics' => (bool) $_POST['widget_topics'],
    36             'post_to_topic' => (bool) $_POST['post_to_topic'],
    37             'post_to_topic_forum' => stripslashes((string) $_POST['post_to_topic_forum']),
    38             'post_to_topic_delay' => (int) $_POST['post_to_topic_delay']
    39         );
    40         update_option( 'bbpress_live', $_options );     
    41    
    42         $fetch_options = $_fetch_options;
    43         $options = $_options;
    44        
    45         do_action( 'bp_forums_bbpress_admin', $_fetch_options, $_options );
    46        
    47     } else {
    48         $fetch_options = $bbpress_live->fetch->options;
    49         $options = $bbpress_live->options;
    50     }
     4    global $bp;
    515?>
    526    <div class="wrap">
     
    5913            </div>
    6014        <?php endif; ?>
    61         <br />
     15
     16        <?php
    6217       
    63         <?php if ( isset($path_success) ) : ?><?php echo "<p id='message' class='updated fade'>$path_success</p>" ?><?php endif; ?>
    64            
    65         <p><?php _e( 'To enable forums for each group in a BuddyPress installation, you must first download, install, and setup bbPress and integrate it with WordPress MU.', 'buddypress' ) ?></p>
    66         <p><?php _e( 'Once you have bbPress set up correctly, enter the options below so that BuddyPress can connect.', 'buddypress' ) ?></p>
    67        
    68         <form action="<?php echo site_url() . '/wp-admin/admin.php?page=' . BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' ?>" name="bbpress-path-form" id="bbpress-path-form" method="post">             
    69             <input type="hidden" name="option_page" value="bbpress-live" />
    70            
    71             <table class="form-table">
    72                 <tr valign="top">
    73                     <th scope="row"><label for="target_uri"><?php _e( 'bbPress URL', 'buddypress' ) ?></label></th>
    74                     <td>
    75                         <input name="target_uri" type="text" id="target_uri" value="<?php echo attribute_escape( $fetch_options['target_uri'] ); ?>" size="60" /><br />
    76                         <?php _e( 'The URL of the location you installed bbPress. For example, http://example.com/forums/', 'buddypress' ); ?>
    77                     </td>
    78                 </tr>
    79                 <tr valign="top">
    80                     <th scope="row"><label for="username"><?php _e( 'bbPress username', 'buddypress' ) ?></label></th>
    81                     <td>
    82                         <input name="username" type="text" id="username" value="<?php echo attribute_escape( $fetch_options['username'] ); ?>" size="20" /><br />
    83                         <?php _e( 'The username for the user (with admin rights) that you created for BuddyPress integration', 'buddypress' ); ?>
    84                     </td>
    85                 </tr>
    86                 <tr valign="top">
    87                     <th scope="row"><label for="password"><?php _e( 'bbPress password', 'buddypress' ) ?></label></th>
    88                     <td>
    89                         <input name="password" type="password" id="password" value="<?php echo attribute_escape( $fetch_options['password'] ); ?>" size="20" /><br />
    90                         <?php _e( 'The password for the user (with admin rights) that you created for BuddyPress integration', 'buddypress' ); ?>
    91                     </td>
    92                 </tr>
    93             </table>
    94             <br />
    95             <h3><?php _e( 'Cache requests', 'buddypress' ) ?></h3>
    96             <table class="form-table">
    97                 <tr valign="top">
    98                     <th scope="row"><label for="cache_enabled"><?php _e( 'Caching enabled', 'buddypress' ) ?></label></th>
    99                     <td>
    100                         <input name="cache_enabled" type="checkbox" id="cache_enabled" value="1"<?php echo( $options['cache_enabled'] ? ' checked="checked"' : '' ); ?> />
    101                         <?php _e( 'Turn on caching of requests to reduce latency and load.', 'buddypress' ); ?>
    102                     </td>
    103                 </tr>
    104                 <tr valign="top">
    105                     <th scope="row"><label for="cache_timeout"><?php _e( 'Cache timeout', 'buddypress' ) ?></label></th>
    106                     <td>
    107                         <input name="cache_timeout" type="text" id="cache_timeout" value="<?php echo attribute_escape( $options['cache_timeout'] ); ?>" size="10" /> <?php _e( '(seconds)', 'buddypress' ) ?><br />
    108                         <?php _e( 'The amount of time in seconds that a cached request is valid for.', 'buddypress' ); ?>
    109                     </td>
    110                 </tr>
    111             </table>
    112             <br />
    113             <p class="submit">
    114                 <input class="button-primary" type="submit" name="submit" value="<?php _e('Save Settings', 'buddypress') ?>"/>
    115             </p>
    116             <?php wp_nonce_field('bbpress-settings') ?>
    117         </form>
     18        if ( !bp_forums_is_installed_correctly() )
     19            bp_forums_bbpress_install_wizard();
     20        else { ?>
     21           
     22            <p>In development:<br />This screen will allow you to manage the relationships between existing groups and forums.</p>
     23           
     24        <?php   
     25        }
     26        ?>
    11827    </div>
    11928<?php
    12029}
     30
     31function bp_forums_bbpress_install_wizard() {
     32    $post_url = site_url( 'wp-admin/admin.php?page=' . 'buddypress/bp-forums.php' );
     33
     34    switch( $_REQUEST['step'] ) {       
     35        case 'existing':
     36            if ( 1 == (int)$_REQUEST['doinstall'] ) {
     37                if ( !bp_forums_configure_existing_install() )
     38                    echo "no go";
     39            }
     40                ?>
     41                    <form action="" method="post">
     42                        <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
     43                        <p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
     44                        <p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
     45                        <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
     46                        <input type="hidden" name="step" value="existing" />
     47                        <input type="hidden" name="doinstall" value="1" />
     48                        <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
     49                    </form>
     50                <?php   
     51        break;
     52
     53        case 'new':
     54            if ( 1 == (int)$_REQUEST['doinstall'] ) {
     55                $result = bp_forums_bbpress_install();
     56           
     57                switch ( $result ) {
     58                    case 1:
     59                        _e( 'All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.' );
     60                        break;
     61                    default:
     62                        // Just write the contents to screen
     63                        _e( 'A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.' );
     64                        ?><code style="display:block; margin-top: 30px;"><pre><?php echo htmlspecialchars( $result ) ?></pre></code><?php
     65                        break;
     66                }
     67            } else {
     68            ?>
     69                <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
     70                <p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
     71                process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
     72                <p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
     73            <?php
     74            }
     75        break;
     76   
     77        default: ?>
     78            <p><?php _e( 'Forums in BuddyPress make use of a bbPress installation to function. You can choose to either let BuddyPress set up a new bbPress install, or use an already existing bbPress install. Please choose one of the options below.', 'buddypress' ) ?></p>
     79           
     80            <a class="button" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Set up a new bbPress installation', 'buddypress' ) ?></a> &nbsp;
     81            <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use an existing bbPress installation', 'buddypress' ) ?></a>
     82
     83        <?php
     84        break;
     85    }
     86}
     87
     88function bp_forums_configure_existing_install() {
     89    global $wpdb, $bbdb;
     90   
     91    check_admin_referer( 'bp_forums_existing_install_init' );
     92   
     93    if ( false === strpos( $_REQUEST['bbconfigloc'], 'bp-config.php' ) ) {
     94        if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
     95            $_REQUEST['bbconfigloc'] .= '/';
     96       
     97        $_REQUEST['bbconfigloc'] .= 'bp-config.php';
     98    }
     99
     100    var_dump( $_REQUEST['bbconfigloc'], file_exists( $_REQUEST['bbconfigloc'] ) );
     101
     102    if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
     103        return false;
     104
     105    update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
     106   
     107    return true;
     108}
     109
     110function bp_forums_bbpress_install() {
     111    global $wpdb, $bbdb;
     112   
     113    check_admin_referer( 'bp_forums_new_install_init' );
     114
     115    /* Create the bb-config.php file */
     116    $initial_write = bp_forums_bbpress_write(
     117        BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
     118        ABSPATH . 'bb-config.php',
     119        array(
     120            "define( 'BBDB_NAME',"          => array( "'bbpress'",                      "'" . DB_NAME . "'" ),
     121            "define( 'BBDB_USER',"          => array( "'username'",                     "'" . DB_USER . "'" ),
     122            "define( 'BBDB_PASSWO"          => array( "'password'",                     "'" . DB_PASSWORD . "'" ),
     123            "define( 'BBDB_HOST',"          => array( "'localhost'",                    "'" . DB_HOST . "'" ),
     124            "define( 'BBDB_CHARSE"          => array( "'utf8'",                         "'" . DB_CHARSET . "'" ),
     125            "define( 'BBDB_COLLAT"          => array( "''",                             "'" . DB_COLLATE . "'" ),
     126            "define( 'BB_AUTH_KEY"          => array( "'put your unique phrase here'",  "'" . AUTH_KEY . "'" ),
     127            "define( 'BB_SECURE_A"          => array( "'put your unique phrase here'",  "'" . SECURE_AUTH_KEY . "'" ),
     128            "define( 'BB_LOGGED_I"          => array( "'put your unique phrase here'",  "'" . LOGGED_IN_KEY . "'" ),
     129            "define( 'BB_NONCE_KE"          => array( "'put your unique phrase here'",  "'" . NONCE_KEY . "'" ),
     130            "\$bb_table_prefix = '"         => array( "'bb_'",                          "'" . $wpdb->base_prefix . "bb_'" ),
     131            "define( 'BB_LANG', '"          => array( "''",                             "'" . WPLANG . "'" )
     132        )
     133    );
     134   
     135    /* Add the custom user and usermeta entries to the config file */
     136    if ( $initial_write == 1 ) {
     137        $file = file_get_contents( ABSPATH . 'bb-config.php' );
     138    } else {
     139        $file = &$initial_write;
     140    }
     141
     142    $file = substr( $file, 0, -2 );
     143    $file .= "\n" .   '$bb->custom_user_table = "' . $wpdb->users . '";';
     144    $file .= "\n" .   '$bb->custom_user_meta_table = "' . $wpdb->usermeta . '";';
     145    $file .= "\n\n" . '$bb->uri = "' . BP_PLUGIN_URL . '/bp-forums/bbpress/";';
     146    $file .= "\n" .   '$bb->name = "' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '";';
     147    $file .= "\n" .   '$bb->wordpress_mu_primary_blog_id = ' . BP_ROOT_BLOG . ';';
     148    $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', "' . AUTH_SALT . '");';
     149    $file .= "\n" .   'define(\'BB_LOGGED_IN_SALT\', "' . LOGGED_IN_SALT . '");';   
     150    $file .= "\n" .   'define(\'BB_SECURE_AUTH_SALT\', "' . SECURE_AUTH_SALT . '");';   
     151    $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
     152    $file .= "\n\n" . '?>';
     153   
     154    if ( $initial_write == 1 ) {
     155        $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
     156        fwrite( $file_handle, $file );
     157        fclose( $file_handle );
     158    } else {
     159        $initial_write = $file;
     160    }
     161
     162    update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
     163    return $initial_write;
     164}
     165
     166function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
     167    if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) {
     168        return -1;
     169    }
     170
     171    if ( !$file_target ) {
     172        $file_target = $file_source;
     173    }
     174
     175    if ( !$alterations || !is_array( $alterations ) ) {
     176        return -2;
     177    }
     178   
     179    // Get the existing lines in the file
     180    $lines = file( $file_source );
     181
     182    // Initialise an array to store the modified lines
     183    $modified_lines = array();
     184
     185    // Loop through the lines and modify them
     186    foreach ( $lines as $line ) {
     187        if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
     188            $alteration = $alterations[substr( $line, 0, 20 )];
     189            $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
     190        } else {
     191            $modified_lines[] = $line;
     192        }
     193    }
     194   
     195    $writable = true;
     196    if ( file_exists( $file_target ) ) {
     197        if ( !is_writable( $file_target ) ) {
     198            $writable = false;
     199        }
     200    } else {
     201        $dir_target = dirname( $file_target );
     202
     203        if ( file_exists( $dir_target ) ) {
     204            @chmod( $dir_target, 0777 );
     205
     206            if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) {
     207                $writable = false;
     208            }
     209           
     210            @chmod( $dir_target, 0666 );
     211        } else {
     212            $writable = false;
     213        }
     214    }
     215
     216    if ( !$writable )
     217        return trim( join( null, $modified_lines ) );
     218
     219    // Open the file for writing - rewrites the whole file
     220    $file_handle = fopen( $file_target, 'w' );
     221
     222    // Write lines one by one to avoid OS specific newline hassles
     223    foreach ( $modified_lines as $modified_line ) {
     224        if ( false !== strpos( $modified_line, '?>' ) ) {
     225            $modified_line = '?>';
     226        }
     227        fwrite( $file_handle, $modified_line );
     228        if ( $modified_line == '?>' ) {
     229            break;
     230        }
     231    }
     232
     233    // Close the config file
     234    fclose( $file_handle );
     235
     236    @chmod( $file_target, 0666 );
     237
     238    return 1;
     239}
    121240?>
  • trunk/bp-forums/bp-forums-filters.php

    r1608 r1621  
    11<?php
    2 
    3 /* BuddyPress filters */
    4 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_create_excerpt' );
    52
    63/* Apply WordPress defined filters */
     
    2825add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
    2926
    30 add_filter( 'bp_get_activity_content', 'bp_forums_filter_decode' );
    31 add_filter( 'bp_forums_new_post_text', 'bp_forums_filter_encode' );
    32 
    33 add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_decode' );
    34 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_decode' );
    35 
    3627function bp_forums_add_allowed_tags( $allowedtags ) {
    3728    $allowedtags['p'] = array();
     
    4233add_filter( 'edit_allowedtags', 'bp_forums_add_allowed_tags' );
    4334
    44 function bp_forums_filter_encode( $content ) {
    45     $content = htmlentities( $content, ENT_COMPAT, "UTF-8" );
    46     $content = str_replace( '&', '/amp/', $content );
    47 
    48     return $content;
    49 }
    50 
    51 function bp_forums_filter_decode( $content ) {
    52     $content = str_replace( '/amp/', '&', $content );
    53     $content = @html_entity_decode( $content, ENT_COMPAT, "UTF-8" );
    54     $content = str_replace( '[', '<', $content );
    55     $content = str_replace( ']', '>', $content );
    56     $content = stripslashes( wp_filter_kses( $content ) );
    57 
    58     return $content;
    59 }
    60 
    6135?>
  • 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
  • trunk/bp-forums/installation-readme.txt

    r1608 r1621  
    22'''''''''''''''''''''''''''''''''''
    33
    4 The bp-forums component provides a link between bbPress and BuddyPress so forums can be
    5 created and manipulated directly in BuddyPress.
    6 
    7 Forum functionality is currently quite basic and limited to creating forums, creating topics and posting.
    8 More advanced integration including moderation, searching and tagging support will come in later
    9 versions of the component.
    10 
    11 *** Please Note ***
    12 
    13 You *must* be running the latest alpha of bbPress and at least WPMU version 2.7 for forum integration to
    14 work.
    15 
    16 ************************************************
    17 Follow these steps to get forums up and running:
    18 ************************************************
    19 
    20 1. Run the bbPress installer by browsing to the location that you uploaded bbPress.
    21 
    22 2. On Step 2 you will need to integrate bbPress with WordPress
    23 
    24    - Check the "Add integration settings" box
    25 
    26    - Leave "Add cookie integration settings" unchecked
    27 
    28    - Check the "Add user database integration settings" box
    29      - Add your table prefix (usually always 'wp_')
    30      - Add your WordPress database settings found in wp-config.php
    31      - You can usually ignore the "character set" and "collation" boxes
    32      - Leave the "Custom user tables" section blank.
    33 
    34 3. On Step 3 enter anything you like for your site name and first forum name. Select "Admin" from the
    35    dropdown to use as your keymaster user.
    36 
    37 4. Head to your new bbPress install and log in with your WordPress administrator account (admin).
    38 
    39 5. Head to the Admin area (/bb-admin) and then the settings menu. Check the "Enable XML-RPC" option.
    40    Also check the "Enable Pingbacks" option just below.
    41 
    42 6. In the bp-forums component there is a /bbpress-plugins/ folder. Copy the 'buddypress-enable.php'
    43    plugin file from that folder into your bbpress plugins folder (eg domain/bbpress/bb-plugins/)
    44 
    45 7. Enable the plugin in the bbPress admin area under the plugins menu.
    46 
    47 8. Head back to your BuddyPress installation and sign up as a new user. Once you have
    48    activated the new user, make a note of the username and password given.
    49 
    50 9. Log back into your bbPress installation as the administrator, and head back to the admin panel (/bb-admin).
    51    Go to the "Users" tab and look for the new user you signed up in step 8 in the list. Hit the "Edit"
    52    link for that user, on the end of the row.
    53 
    54 10. On the edit user screen there is a drop down menu called "User Type". Select "Administrator" as the user
    55     type for this user. Hit the "Update Profile" button.
    56 
    57 11. Enable user switching in bbPress by copying the following line of code into your bbPress bb-config.php
    58     file:
    59    
    60         $bb->bb_xmlrpc_allow_user_switching = true;
    61 
    62 12. Log into your WPMU admin interface and head to "BuddyPress > Forums Setup" fill in the details on that
    63     page. Make sure you don't leave out the ending slash on your bbPress URL. (http://example.com/bbpress/)
    64     Enter the username and password for the user that you signed up in step 8.
    65 
    66 13. Once you have saved those details you can create group forums. Existing groups you will need to head
    67     to the group admin settings page, disable then enable the group forum setting to generate a new forum.
    68     New groups will work fine.
    69 
    70 *** NOTE ***
    71 
    72 Group forums are public, even if a group is private its forum will be accessable through the bbPress interface.
    73 This will change eventually, but please be aware of the public status of forums before posting.
     4Please sign in to WordPress as a site admin and head to "BuddyPress > Forums Setup" to install.
  • trunk/bp-groups.php

    r1599 r1621  
    106106    $bp->groups->table_name_groupmeta = $wpdb->base_prefix . 'bp_groups_groupmeta';
    107107    $bp->groups->image_base = BP_PLUGIN_URL . '/bp-groups/images';
    108     $bp->groups->format_activity_function = 'groups_format_activity';
    109108    $bp->groups->format_notification_function = 'groups_format_notifications';
    110109    $bp->groups->slug = BP_GROUPS_SLUG;
     
    250249
    251250            if ( $bp->groups->current_group->enable_forum && function_exists('bp_forums_setup') )
    252                 bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'group-forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
     251                bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'group-forum' ) );
    253252
    254253            if ( $bp->groups->current_group->enable_wire && function_exists('bp_wire_install') )
    255                 bp_core_new_subnav_item( array( 'name' => __( 'Wire', 'buddypress' ), 'slug' => 'group-wire', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_wire', 'position' => 50, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
    256 
    257             bp_core_new_subnav_item( array( 'name' => __( 'Members', 'buddypress' ), 'slug' => 'group-members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
     254                bp_core_new_subnav_item( array( 'name' => __( 'Wire', 'buddypress' ), 'slug' => 'wire', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_wire', 'position' => 50, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'group-wire' ) );
     255
     256            bp_core_new_subnav_item( array( 'name' => __( 'Members', 'buddypress' ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'group-members' ) );
    258257           
    259258            if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
     
    319318           
    320319            /* Record this in activity streams */
    321             groups_record_activity( array( 'item_id' => $group_id, 'component_name' => $bp->groups->slug, 'component_action' => 'joined_group', 'is_private' => 0 ) );
     320            $group = new BP_Groups_Group( $group_id, false, false );
     321
     322            groups_record_activity( array(
     323                'content' => sprintf( __( '%s joined the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . attribute_escape( $group->name ) . '</a>' ),
     324                'primary_link' => bp_get_group_permalink( $group ),
     325                'component_action' => 'joined_group',
     326                'item_id' => $group->id
     327            ) );
    322328        }
    323329
     
    377383
    378384    /* Set the ID of the new group, if it has already been created in a previous step */
    379     if ( isset( $_COOKIE['bp_new_group_id'] ) )
     385    if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
    380386        $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
     387        $bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );
     388    }
    381389   
    382390    /* If the save button is hit, lets calculate what we need to save */
     
    424432            else if ( 'hidden' == $_POST['group-status'] )
    425433                $group_status = 'hidden';
    426 
     434           
     435            /* Once we get to the second step, record the group creation in the activity stream. As we now know the actual status of the group */
     436            groups_record_activity( array(
     437                'content' => sprintf( __( '%s created the group %s:', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' ),
     438                'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     439                'component_action' => 'created_group',
     440                'item_id' => $bp->groups->current_group->id,
     441                'user_id' => $user_id
     442            ) );
     443       
    427444            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_wire' => $group_enable_wire, 'enable_forum' => $group_enable_forum ) ) ) {
    428445                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
     
    475492            unset( $bp->groups->completed_create_steps );
    476493           
    477             $group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );
    478 
    479             bp_core_redirect( bp_get_group_permalink( $group ) );
     494            bp_core_redirect( bp_get_group_permalink( $bp->groups->new_group ) );
    480495        } else {
    481496            /**
     
    500515    }
    501516
    502     $bp->groups->new_group = new BP_Groups_Group( $bp->groups->new_group_id, false, false );
    503517    bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
    504518}
     519
    505520
    506521function groups_screen_group_home() {
     
    529544    global $bp;
    530545   
    531     if ( $bp->is_single_item ) {
    532         $topic_id = $bp->action_variables[1];
     546    if ( $bp->is_single_item && $bp->groups->current_group->user_has_access ) {
     547        $topic_slug = $bp->action_variables[1];
     548        $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug );
    533549        $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    534550       
    535         if ( $topic_id ) {
     551        if ( $topic_slug && $topic_id ) {
    536552           
    537553            /* Posting a reply */
    538             if ( isset( $_POST['submit_reply'] ) && function_exists( 'bp_forums_new_post') ) {
     554            if ( !$bp->action_variables[2] && isset( $_POST['submit_reply'] ) ) {
    539555                /* Check the nonce */
    540                 if ( !check_admin_referer( 'bp_forums_new_reply' ) )
    541                     return false;
    542        
    543                 groups_new_group_forum_post( $_POST['reply_text'], $topic_id );
    544                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_id );
    545             }
    546            
    547             do_action( 'groups_screen_group_forum_topic' );
    548            
    549             // If we are viewing a topic, load it.
    550             bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/forum/topic' ) );
     556                check_admin_referer( 'bp_forums_new_reply' );
     557       
     558                if ( !groups_new_group_forum_post( $_POST['reply_text'], $topic_id ) )
     559                    bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' );
     560                else
     561                    bp_core_add_message( __( 'Your reply was posted successfully', 'buddypress') );
     562               
     563                if ( $_SERVER['QUERY_STRING'] )
     564                    $query_vars = '?' . $_SERVER['QUERY_STRING'];
     565                   
     566                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' . $query_vars );
     567            }
     568           
     569            /* Sticky a topic */
     570            else if ( 'stick' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     571                /* Check the nonce */
     572                check_admin_referer( 'bp_forums_stick_topic' );
     573
     574                if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id ) ) )
     575                    bp_core_add_message( __( 'There was an error when making that topic a sticky', 'buddypress' ), 'error' );
     576                else
     577                    bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
     578           
     579                do_action( 'groups_stick_topic', $topic_id );
     580                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     581            }
     582           
     583            /* Un-Sticky a topic */
     584            else if ( 'unstick' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     585                /* Check the nonce */
     586                check_admin_referer( 'bp_forums_unstick_topic' );
     587   
     588                if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id, 'mode' => 'unstick' ) ) )
     589                    bp_core_add_message( __( 'There was an error when unsticking that topic', 'buddypress'), 'error' );
     590                else
     591                    bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
     592           
     593                do_action( 'groups_unstick_topic', $topic_id );
     594                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     595            }
     596           
     597            /* Close a topic */
     598            else if ( 'close' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     599                /* Check the nonce */
     600                check_admin_referer( 'bp_forums_close_topic' );
     601   
     602                if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id ) ) )
     603                    bp_core_add_message( __( 'There was an error when closing that topic', 'buddypress'), 'error' );
     604                else
     605                    bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
     606           
     607                do_action( 'groups_close_topic', $topic_id );
     608                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     609            }
     610
     611            /* Open a topic */
     612            else if ( 'open' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     613                /* Check the nonce */
     614                check_admin_referer( 'bp_forums_open_topic' );
     615   
     616                if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id, 'mode' => 'open' ) ) )
     617                    bp_core_add_message( __( 'There was an error when opening that topic', 'buddypress'), 'error' );
     618                else
     619                    bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
     620           
     621                do_action( 'groups_open_topic', $topic_id );
     622                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     623            }
     624
     625            /* Delete a topic */
     626            else if ( 'delete' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     627                /* Check the nonce */
     628                check_admin_referer( 'bp_forums_delete_topic' );
     629   
     630                if ( !groups_delete_forum_topic( $topic_id ) )
     631                    bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
     632                else
     633                    bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
     634                               
     635                do_action( 'groups_delete_topic', $topic_id );
     636                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     637            }
     638           
     639            /* Editing a topic */
     640            else if ( 'edit' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     641                if ( isset( $_POST['save_changes'] ) ) {
     642                    /* Check the nonce */
     643                    check_admin_referer( 'bp_forums_edit_topic' );
     644       
     645                    if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'] ) )
     646                        bp_core_add_message( __( 'There was an error when editing that topic', 'buddypress'), 'error' );
     647                    else
     648                        bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
     649               
     650                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
     651                }
     652
     653                /* Check that the user has access to edit this topic, if not, redirect. */
     654                $topic = bp_forums_get_topic_details( $topic_id );
     655                if ( ( !$bp->is_item_admin && !$bp->is_item_mod ) && $bp->loggedin_user->id != $topic->topic_poster )
     656                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
     657
     658                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
     659            }
     660           
     661            /* Delete a post */
     662            else if ( 'delete' == $bp->action_variables[2] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     663                /* Check the nonce */
     664                check_admin_referer( 'bp_forums_delete_topic' );
     665   
     666                if ( !groups_delete_forum_topic( $topic_id ) )
     667                    bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
     668                else
     669                    bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
     670
     671                do_action( 'groups_delete_topic', $topic_id );
     672                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
     673            }
     674           
     675                       
     676            /* Editing a post */
     677            else if ( 'edit' == $bp->action_variables[4] && $post_id = $bp->action_variables[3] ) {
     678                if ( isset( $_POST['save_changes'] ) ) {
     679                    /* Check the nonce */
     680                    check_admin_referer( 'bp_forums_edit_post' );
     681       
     682                    if ( !groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id ) )
     683                        bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
     684                    else
     685                        bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
     686               
     687                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
     688                }
     689               
     690                /* Check that the user has access to edit this post, if not, redirect. */
     691                $post = bp_forums_get_post( $post_id );
     692                if ( ( !$bp->is_item_admin && !$bp->is_item_mod ) && $bp->loggedin_user->id != $post->poster_id )
     693                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
     694
     695                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
     696            }
     697
     698            /* Standard topic display */
     699            else {
     700                if ( file_exists( TEMPLATEPATH . '/groups/single/forum/topic.php' ) )
     701                    bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/forum/topic' ) );
     702                else
     703                    bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/forum/topic' ) );
     704            }
    551705        } else {
    552706
     
    554708            if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic') ) {
    555709                /* Check the nonce */   
    556                 if ( !check_admin_referer( 'bp_forums_new_topic' ) )
    557                     return false;
     710                check_admin_referer( 'bp_forums_new_topic' );
    558711               
    559                 groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id );
     712                if ( !groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
     713                    bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
     714                else
     715                    bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
     716                   
    560717                bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/' );
    561718            }
     
    11811338 */
    11821339
    1183 function groups_record_activity( $args = true ) {
    1184     global $bp;
    1185    
    1186     if ( function_exists('bp_activity_record') ) {
    1187         extract($args);
    1188 
    1189         if ( !$bp->groups->current_group ) {
    1190             if ( !$bp->groups->current_group = wp_cache_get( 'groups_group_nouserdata_' . $item_id, 'bp' ) ) {
    1191                 $bp->groups->current_group = new BP_Groups_Group( $item_id, false, false );
    1192                 wp_cache_set( 'groups_group_nouserdata_' . $item_id, $bp->groups->current_group, 'bp' );
    1193             }
    1194         }
    1195 
    1196         if ( 'public' == $bp->groups->current_group->status )
    1197             bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
    1198     }
    1199 }
    1200 
    1201 function groups_delete_activity( $args = true ) {
    1202     if ( function_exists('bp_activity_delete') ) {
    1203         extract($args);
    1204         bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    1205     }
    1206 }
    1207 
    1208 function groups_format_activity( $item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false  ) {
    1209     global $bp;
    1210    
    1211     switch( $action ) {
    1212         case 'joined_group':
    1213             $group = new BP_Groups_Group( $item_id, false, false );
    1214            
    1215             if ( !$group )
    1216                 return false;
    1217                
    1218             $user_link = bp_core_get_userlink( $user_id );
    1219             $group_link = bp_get_group_permalink( $group );
    1220            
    1221             return array(
    1222                 'primary_link' => $group_link,
    1223                 'content' => apply_filters( 'bp_groups_joined_group_activity', sprintf( __('%s joined the group %s', 'buddypress'), $user_link,  '<a href="' . $group_link . '">' . $group->name . '</a>' ) . ' <span class="time-since">%s</span>', $user_link, $group_link, $group->name )
    1224             );             
    1225         break;
    1226         case 'created_group':
    1227             $group = new BP_Groups_Group( $item_id, false, false );
    1228 
    1229             if ( !$group )
    1230                 return false;
    1231            
    1232             $user_link = bp_core_get_userlink( $user_id );
    1233             $group_link = bp_get_group_permalink( $group );
    1234            
    1235             return array(
    1236                 'primary_link' => $group_link,
    1237                 'content' => apply_filters( 'bp_groups_created_group_activity', sprintf( __('%s created the group %s', 'buddypress'), $user_link, '<a href="' . $group_link . '">' . $group->name . '</a>') . ' <span class="time-since">%s</span>', $user_link, $group_link, $group->name )
    1238             );
    1239         break;
    1240         case 'new_wire_post':
    1241             $wire_post = new BP_Wire_Post( $bp->groups->table_name_wire, $item_id );
    1242             $group = new BP_Groups_Group( $wire_post->item_id, false, false );
    1243 
    1244             if ( !$group || !$wire_post || !$wire_post->content )
    1245                 return false;       
    1246 
    1247             $user_link = bp_core_get_userlink( $user_id );
    1248             $group_link = bp_get_group_permalink( $group );
    1249             $post_excerpt = bp_create_excerpt( $wire_post->content );
    1250                    
    1251             $content = sprintf ( __('%s wrote on the wire of the group %s', 'buddypress'), $user_link, '<a href="' . $group_link . '">' . $group->name . '</a>' ) . ' <span class="time-since">%s</span>';         
    1252             $content .= '<blockquote>' . $post_excerpt . '</blockquote>';
    1253            
    1254             $content = apply_filters( 'bp_groups_new_wire_post_activity', $content, $user_link, $group_link, $group->name, $post_excerpt );
    1255            
    1256             return array(
    1257                 'primary_link' => $group_link,
    1258                 'content' => $content
    1259             );
    1260         break;
    1261         case 'new_forum_post':
    1262             if ( function_exists('bp_forums_setup') ) {
    1263                 $group = new BP_Groups_Group( $item_id, false, false );
    1264                 $forum_post = bp_forums_get_post( $secondary_item_id );
    1265                 $forum_topic = bp_forums_get_topic_details( $forum_post['topic_id'] );
    1266 
    1267                 if ( !$group || !$forum_post || !$forum_topic )
    1268                     return false;
    1269 
    1270                 $user_link = bp_core_get_userlink($user_id);
    1271                 $group_link = bp_get_group_permalink( $group );
    1272 
    1273                 $post_content = apply_filters( 'bp_the_topic_post_content', bp_create_excerpt( stripslashes( $forum_post['post_text'] ), 55, false ) );
    1274            
    1275                 $content = sprintf ( __('%s posted on the forum topic %s in the group %s:', 'buddypress'), $user_link, '<a href="' . $group_link . '/forum/topic/' . $forum_topic['topic_id'] . '">' . $forum_topic['topic_title'] . '</a>', '<a href="' . $group_link . '">' . $group->name . '</a>' ) . ' <span class="time-since">%s</span>';           
    1276                 $content .= '<blockquote>' . $post_content . '</blockquote>';
    1277                
    1278                 $content = apply_filters( 'bp_groups_new_forum_post_activity', $content, $user_link, $group_link, $forum_topic['topic_id'], $forum_topic['topic_title'], $group_link, $group->name, $post_content );
    1279 
    1280                 return array(
    1281                     'primary_link' => $group_link,
    1282                     'content' => $content
    1283                 );
    1284             }
    1285         break;
    1286         case 'new_forum_topic':
    1287             if ( function_exists('bp_forums_setup') ) {
    1288                 $group = new BP_Groups_Group( $item_id, false, false );
    1289                 $forum_topic = bp_forums_get_topic_details( $secondary_item_id );
    1290                 $forum_post = bp_forums_get_post( $forum_topic['topic_last_post_id'] );
    1291 
    1292                 if ( !$group || !$forum_post || !$forum_topic )
    1293                     return false;
    1294                    
    1295                 $user_link = bp_core_get_userlink($user_id);
    1296                 $group_link = bp_get_group_permalink( $group );
    1297                
    1298                 $post_content = apply_filters( 'bp_the_topic_post_content', bp_create_excerpt( stripslashes( $forum_post['post_text'] ), 55, false ) );
    1299                
    1300                 $content = sprintf ( __('%s created the forum topic %s in the group %s:', 'buddypress'), $user_link, '<a href="' . $group_link . '/forum/topic/' . $forum_topic['topic_id'] . '">' . $forum_topic['topic_title'] . '</a>', '<a href="' . $group_link . '">' . $group->name . '</a>' ) . ' <span class="time-since">%s</span>';         
    1301                 $content .= '<blockquote>' . $post_content . '</blockquote>';
    1302                
    1303                 $content = apply_filters( 'bp_groups_new_forum_topic_activity', $content, $user_link, $group_link, $forum_topic['topic_id'], $forum_topic['topic_title'], $group_link, $group->name, $post_content );
    1304                
    1305                 return array(
    1306                     'primary_link' => $group_link,
    1307                     'content' => $content
    1308                 );
    1309             }
    1310         break;     
    1311     }
    1312    
    1313     do_action( 'groups_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user );
    1314    
    1315     return false;
     1340function groups_record_activity( $args = '' ) {
     1341    global $bp;
     1342   
     1343    if ( !function_exists( 'bp_activity_add' ) )
     1344        return false;
     1345       
     1346    if ( 'public' != $bp->groups->current_group->status )   
     1347        return false;
     1348       
     1349    $defaults = array(
     1350        'user_id' => $bp->loggedin_user->id,
     1351        'content' => false,
     1352        'primary_link' => false,
     1353        'component_name' => 'groups',
     1354        'component_action' => false,
     1355        'item_id' => false,
     1356        'secondary_item_id' => false,
     1357        'recorded_time' => time(),
     1358        'hide_sitewide' => false
     1359    );
     1360
     1361    $r = wp_parse_args( $args, $defaults );
     1362    extract( $r, EXTR_SKIP );   
     1363   
     1364    return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    13161365}
    13171366
     
    15871636    if ( !$group->delete() )
    15881637        return false;
    1589    
    1590     // Remove the activity stream item
    1591     groups_delete_activity( array( 'item_id' => $group_id, 'component_name' => $bp->groups->slug, 'component_action' => 'created_group', 'user_id' => $bp->loggedin_user->id ) );
     1638
     1639    /* Delete the activity stream item */
     1640    if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     1641        bp_activity_delete_by_item_id( array( 'item_id' => $group_id, 'component_name' => 'groups', 'component_action' => 'created_group' ) );
     1642    }   
    15921643 
    15931644    // Remove all outstanding invites for this group
     
    16791730
    16801731    /* Record this in activity streams */
    1681     groups_record_activity( array( 'item_id' => $new_member->group_id, 'component_name' => $bp->groups->slug, 'component_action' => 'joined_group', 'is_private' => 0 ) );
    1682    
     1732    groups_record_activity( array(
     1733        'content' => sprintf( __( '%s joined the group %s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' ),
     1734        'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     1735        'component_action' => 'joined_group',
     1736        'item_id' => $bp->groups->current_group->id
     1737    ) );
     1738
    16831739    /* Modify group meta */
    16841740    groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') + 1 );
     
    19111967
    19121968function groups_new_wire_post( $group_id, $content ) {
    1913      $bp;
    1914 
    1915     $private = false;
    1916     if ( $bp->groups->current_group->status != 'public' )
    1917         $private = true;
    1918    
    1919     if ( $wire_post_id = bp_wire_new_post( $group_id, $content, $bp->groups->slug, $private ) ) {
     1969    global $bp;
     1970   
     1971    if ( !function_exists( 'bp_wire_new_post' ) )
     1972        return false;
     1973   
     1974    if ( $wire_post_id = bp_wire_new_post( $group_id, $content, 'groups' ) ) {
     1975        $activity_content = sprintf( __( '%s wrote on the wire of the group %s:', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     1976        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $content ) ) . '</blockquote>';
     1977       
     1978        groups_record_activity( array(
     1979            'content' => $activity_content,
     1980            'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     1981            'component_action' => 'new_wire_post',
     1982            'item_id' => $wire_post_id,
     1983            'secondary_item_id' => $bp->groups->current_group->id
     1984        ) );
     1985
    19201986        do_action( 'groups_new_wire_post', $group_id, $wire_post_id );
    19211987       
     
    19271993
    19281994function groups_delete_wire_post( $wire_post_id, $table_name ) {
    1929     global $bp;
    1930        
    1931     if ( bp_wire_delete_post( $wire_post_id, $bp->groups->slug, $table_name ) ) {       
     1995    if ( bp_wire_delete_post( $wire_post_id, 'groups', $table_name ) ) {
     1996        /* Delete the activity stream item */
     1997        if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     1998            bp_activity_delete_by_item_id( array( 'item_id' => $wire_post_id, 'component_name' => 'groups', 'component_action' => 'new_wire_post' ) );
     1999        }
     2000           
    19322001        do_action( 'groups_deleted_wire_post', $wire_post_id );
    19332002        return true;
     
    19412010function groups_new_group_forum( $group_id = false, $group_name = false, $group_desc = false ) {
    19422011    global $bp;
    1943    
     2012
    19442013    if ( !$group_id )
    19452014        $group_id = $bp->groups->current_group->id;
     
    19512020        $group_desc = $bp->groups->current_group->description;
    19522021   
    1953     $forum = bp_forums_new_forum( apply_filters( 'groups_new_group_forum_name', $group_name . ' - ' . __( 'Forum', 'buddypress' ), $group_name ), apply_filters( 'groups_new_group_forum_desc', $group_desc ) );
    1954    
    1955     groups_update_groupmeta( $group_id, 'forum_id', $forum['forum_id'] );
     2022    $forum_id = bp_forums_new_forum( array( 'forum_name' => $group_name, 'forum_description' => $group_desc ) );
     2023   
     2024    groups_update_groupmeta( $group_id, 'forum_id', $forum_id );
    19562025   
    19572026    do_action( 'groups_new_group_forum', $forum, $group_id );
     
    19612030    global $bp;
    19622031   
    1963     if ( $forum_post = bp_forums_new_post( $post_text, $topic_id ) ) {
    1964         bp_core_add_message( __( 'Reply posted successfully!', 'buddypress') );
    1965 
    1966         /* Record in activity streams */
    1967         groups_record_activity( array( 'item_id' => $bp->groups->current_group->id, 'component_name' => $bp->groups->slug, 'component_action' => 'new_forum_post', 'is_private' => 0, 'secondary_item_id' => $forum_post['post_id'] ) );
    1968        
     2032    if ( $forum_post = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
     2033        $topic = bp_forums_get_topic_details( $topic_id );
     2034       
     2035        $activity_content = sprintf( __( '%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug .'">' . attribute_escape( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     2036        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $post_text ) ) . '</blockquote>';
     2037       
     2038        /* Record this in activity streams */
     2039        groups_record_activity( array(
     2040            'content' => $activity_content,
     2041            'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     2042            'component_action' => 'new_forum_post',
     2043            'item_id' => $topic_id,
     2044            'secondary_item_id' => $forum_post->id
     2045        ) );
     2046
    19692047        do_action( 'groups_new_forum_topic_post', $bp->groups->current_group->id, $forum_post );
    19702048       
     
    19722050    }
    19732051   
    1974     bp_core_add_message( __( 'There was an error posting that reply.', 'buddypress'), 'error' );                   
    19752052    return false;
    19762053}
     
    19792056    global $bp;
    19802057   
    1981     if ( $topic = bp_forums_new_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) ) {
    1982         bp_core_add_message( __( 'Topic posted successfully!', 'buddypress') );
    1983 
    1984         /* Record in activity streams */
    1985         groups_record_activity( array( 'item_id' => $bp->groups->current_group->id, 'component_name' => $bp->groups->slug, 'component_action' => 'new_forum_topic', 'is_private' => 0, 'secondary_item_id' => $topic['topic_id'] ) );
    1986        
    1987         do_action( 'groups_new_forum_topic', $bp->groups->current_group->id, $topic );
     2058    if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
     2059        $topic = bp_forums_get_topic_details( $topic_id );
     2060
     2061        $activity_content = sprintf( __( '%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug .'">' . attribute_escape( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     2062        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $topic_text ) ) . '</blockquote>';
     2063       
     2064        /* Record this in activity streams */
     2065        groups_record_activity( array(
     2066            'content' => $activity_content,
     2067            'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     2068            'component_action' => 'new_forum_topic',
     2069            'item_id' => $topic->topic_id,
     2070            'secondary_item_id' => $bp->groups->current_group->id
     2071        ) );
     2072       
     2073        do_action( 'groups_new_forum_topic', $bp->groups->current_group->id, &$topic );
    19882074       
    19892075        return $topic;
    19902076    }
    1991    
    1992     bp_core_add_message( __( 'There was an error posting that topic.', 'buddypress'), 'error' );                   
     2077                   
    19932078    return false;
    19942079}
     2080
     2081function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text ) {
     2082    global $bp;
     2083   
     2084    if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id ) ) ) {
     2085        /* Update the activity stream item */
     2086        bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2087       
     2088        $activity_content = sprintf( __( '%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug .'">' . attribute_escape( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     2089        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $topic_text ) ) . '</blockquote>';
     2090
     2091        /* Record this in activity streams */
     2092        groups_record_activity( array(
     2093            'content' => $activity_content,
     2094            'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     2095            'component_action' => 'new_forum_topic',
     2096            'item_id' => (int)$topic->topic_id,
     2097            'user_id' => (int)$topic->topic_poster,
     2098            'secondary_item_id' => $bp->groups->current_group->id,
     2099            'recorded_time' => bb_gmtstrtotime( $topic->topic_time )
     2100        ) );
     2101
     2102        do_action( 'groups_update_group_forum_topic', &$topic );
     2103       
     2104        return true;
     2105    }
     2106   
     2107    return false;
     2108}
     2109
     2110function groups_delete_forum_topic( $topic_id ) {
     2111    global $bp;
     2112   
     2113    if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
     2114        /* Delete the activity stream item */
     2115        if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     2116            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2117            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
     2118        }
     2119
     2120        do_action( 'groups_delete_forum_topic', $topic_id );
     2121       
     2122        return true;
     2123    }
     2124   
     2125    return false;
     2126}
     2127
     2128function groups_update_group_forum_post( $post_id, $post_text, $topic_id ) {
     2129    global $bp;
     2130   
     2131    $post = bp_forums_get_post( $post_id );
     2132       
     2133    if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id ) ) ) {
     2134        $topic = bp_forums_get_topic_details( $topic_id );
     2135
     2136        /* Update the activity stream item */
     2137        bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'secondary_item_id' => $post_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
     2138       
     2139        $activity_content = sprintf( __( '%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug .'">' . attribute_escape( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
     2140        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $post_text ) ) . '</blockquote>';
     2141       
     2142        /* Record this in activity streams */
     2143        groups_record_activity( array(
     2144            'content' => $activity_content,
     2145            'primary_link' => bp_get_group_permalink( $bp->groups->current_group ),
     2146            'component_action' => 'new_forum_post',
     2147            'item_id' => $topic_id,
     2148            'secondary_item_id' => $post_id,
     2149            'recorded_time' => bb_gmtstrtotime( $post->post_time )
     2150        ) );
     2151
     2152        do_action( 'groups_update_group_forum_post', &$post, &$topic );
     2153       
     2154        return true;
     2155    }
     2156   
     2157    return false;
     2158}
     2159
     2160// function groups_delete_forum_post( $post_id, $topic_id ) {
     2161//  global $bp;
     2162// 
     2163//  if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
     2164//      /* Delete the activity stream item */
     2165//      if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
     2166//          bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'secondary_item_id' => $post_id 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
     2167//      }
     2168//
     2169//      do_action( 'groups_delete_forum_topic', $topic_id );
     2170//     
     2171//      return true;
     2172//  }
     2173// 
     2174//  return false;
     2175// }
    19952176
    19962177/*** Group Invitations *********************************************************/
     
    22122393   
    22132394    /* Record this in activity streams */
    2214     groups_record_activity( array( 'item_id' => $membership->group_id, 'component_name' => $bp->groups->slug, 'component_action' => 'joined_group', 'is_private' => 0 ) );
     2395    $group = new BP_Groups_Group( $group_id, false, false );
     2396
     2397    groups_record_activity( array(
     2398        'content' => sprintf( __( '%s joined the group %s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . attribute_escape( $group->name ) . '</a>' ),
     2399        'primary_link' => bp_get_group_permalink( $group ),
     2400        'component_action' => 'joined_group',
     2401        'item_id' => $group->id,
     2402        'user_id' => $user_id
     2403    ) );
    22152404
    22162405    /* Send a notification to the user. */
  • trunk/bp-groups/bp-groups-cssjs.php

    r1599 r1621  
    11<?php
    2 /**************************************************************************
    3  groups_add_js()
    4  
    5  Inserts the Javascript needed for managing groups.
    6  **************************************************************************/   
    72
    83function groups_add_js() {
  • trunk/bp-groups/bp-groups-templatetags.php

    r1599 r1621  
    594594    }
    595595
     596function bp_group_is_admin() {
     597    global $bp;
     598   
     599    return $bp->is_item_admin;
     600}
     601
     602function bp_group_is_mod() {
     603    global $bp;
     604   
     605    return $bp->is_item_mod;
     606}
     607
    596608function bp_group_list_admins( $full_list = true, $group = false ) {
    597609    global $groups_template;
     
    689701    if ( $forum_id && $forum_id != '' ) {
    690702        if ( function_exists( 'bp_forums_setup' ) ) {
    691             $latest_topics = bp_forums_get_topics( $forum_id, $total_topics, 1 );
     703            $latest_topics = bp_forums_get_forum_topics( $forum_id );
    692704       
    693705            if ( $latest_topics ) { ?>
     
    16321644    function bp_get_new_group_name() {
    16331645        global $bp;
    1634         return apply_filters( 'bp_get_new_group_name', $bp->groups->new_group->name );
     1646        return apply_filters( 'bp_get_new_group_name', $bp->groups->current_group->name );
    16351647    }
    16361648
     
    16401652    function bp_get_new_group_description() {
    16411653        global $bp;
    1642         return apply_filters( 'bp_get_new_group_description', $bp->groups->new_group->name );
     1654        return apply_filters( 'bp_get_new_group_description', $bp->groups->current_group->name );
    16431655    }
    16441656
     
    16481660    function bp_get_new_group_news() {
    16491661        global $bp;
    1650         return apply_filters( 'bp_get_new_group_news', $bp->groups->new_group->name );
     1662        return apply_filters( 'bp_get_new_group_news', $bp->groups->current_group->name );
    16511663    }
    16521664
     
    16561668    function bp_get_new_group_enable_wire() {
    16571669        global $bp;
    1658         return (int) apply_filters( 'bp_get_new_group_enable_wire', $bp->groups->new_group->enable_wire );
     1670        return (int) apply_filters( 'bp_get_new_group_enable_wire', $bp->groups->current_group->enable_wire );
    16591671    }
    16601672
     
    16641676    function bp_get_new_group_enable_forum() {
    16651677        global $bp;
    1666         return (int) apply_filters( 'bp_get_new_group_enable_forum', $bp->groups->new_group->enable_forum );
     1678        return (int) apply_filters( 'bp_get_new_group_enable_forum', $bp->groups->current_group->enable_forum );
    16671679    }
    16681680
     
    16721684    function bp_get_new_group_status() {
    16731685        global $bp;
    1674         return apply_filters( 'bp_get_new_group_status', $bp->groups->new_group->status );
     1686        return apply_filters( 'bp_get_new_group_status', $bp->groups->current_group->status );
    16751687    }
    16761688
     
    16801692    function bp_get_new_group_avatar_thumb() {
    16811693        global $bp;
    1682         return apply_filters( 'bp_get_new_group_avatar_thumb', $bp->groups->new_group->avatar_thumb );
     1694        return apply_filters( 'bp_get_new_group_avatar_thumb', $bp->groups->current_group->avatar_thumb );
    16831695    }
    16841696
     
    16881700    function bp_get_new_group_avatar_full() {
    16891701        global $bp;
    1690         return apply_filters( 'bp_get_new_group_avatar_full', $bp->groups->new_group->avatar_full );
     1702        return apply_filters( 'bp_get_new_group_avatar_full', $bp->groups->current_group->avatar_full );
    16911703    }
    16921704
     
    17751787        }
    17761788       
    1777         return implode( "\n", $items );
     1789        return implode( "\n", (array)$items );
    17781790    }
    17791791
     
    25722584        return false;
    25732585
    2574         $friends = friends_get_friends_invite_list( $bp->loggedin_user->id, $bp->groups->new_group->id );
     2586        $friends = friends_get_friends_invite_list( $bp->loggedin_user->id, $bp->groups->current_group->id );
    25752587
    25762588        if ( $friends ) {
    2577             $invites = groups_get_invites_for_group( $bp->loggedin_user->id, $bp->groups->new_group->id );
     2589            $invites = groups_get_invites_for_group( $bp->loggedin_user->id, $bp->groups->current_group->id );
    25782590
    25792591    ?>
     
    26302642        case 'group-details': ?>
    26312643            <label for="group-name">* <?php _e('Group Name', 'buddypress') ?></label>
    2632             <input type="text" name="group-name" id="group-name" value="<?php echo attribute_escape( ( $bp->groups->new_group ) ? $bp->groups->new_group->name : $_POST['group-name'] ); ?>" />
     2644            <input type="text" name="group-name" id="group-name" value="<?php echo attribute_escape( ( $bp->groups->new_group ) ? $bp->groups->current_group->name : $_POST['group-name'] ); ?>" />
    26332645       
    26342646            <label for="group-desc">* <?php _e('Group Description', 'buddypress') ?></label>
    2635             <textarea name="group-desc" id="group-desc"><?php echo htmlspecialchars( ( $bp->groups->new_group ) ? $bp->groups->new_group->description : $_POST['group-desc'] ); ?></textarea>
     2647            <textarea name="group-desc" id="group-desc"><?php echo htmlspecialchars( ( $bp->groups->new_group ) ? $bp->groups->current_group->description : $_POST['group-desc'] ); ?></textarea>
    26362648       
    26372649            <label for="group-news"><?php _e('Recent News', 'buddypress') ?></label>
    2638             <textarea name="group-news" id="group-news"><?php echo htmlspecialchars( ( $bp->groups->new_group ) ? $bp->groups->new_group->news : $_POST['group-news'] ); ?></textarea>
     2650            <textarea name="group-news" id="group-news"><?php echo htmlspecialchars( ( $bp->groups->new_group ) ? $bp->groups->current_group->news : $_POST['group-news'] ); ?></textarea>
    26392651           
    26402652            <?php do_action( 'groups_custom_group_fields_editable' ) ?>
     
    26482660                <?php if ( function_exists('bp_wire_install') ) : ?>
    26492661                <div class="checkbox">
    2650                     <label><input type="checkbox" name="group-show-wire" id="group-show-wire" value="1"<?php if ( $bp->groups->new_group->enable_wire ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable comment wire', 'buddypress') ?></label>
     2662                    <label><input type="checkbox" name="group-show-wire" id="group-show-wire" value="1"<?php if ( $bp->groups->current_group->enable_wire ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable comment wire', 'buddypress') ?></label>
    26512663                </div>
    26522664                <?php endif; ?>
     
    26552667                    <?php if ( bp_forums_is_installed_correctly() ) { ?>
    26562668                        <div class="checkbox">
    2657                             <label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php if ( $bp->groups->new_group->enable_forum ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable discussion forum', 'buddypress') ?></label>
     2669                            <label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php if ( $bp->groups->current_group->enable_forum ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable discussion forum', 'buddypress') ?></label>
    26582670                        </div>
    26592671                    <?php } else {
     
    26702682                <?php if ( function_exists('bp_albums_install') ) : ?>
    26712683                <div class="checkbox with-suboptions">
    2672                     <label><input type="checkbox" name="group-show-photos" id="group-show-photos" value="1"<?php if ( $bp->groups->new_group->enable_photos ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable photo gallery', 'buddypress') ?></label>
    2673                     <div class="sub-options"<?php if ( !$bp->groups->new_group->enable_photos ) { ?> style="display: none;"<?php } ?>>
    2674                         <label><input type="radio" name="group-photos-status" value="all"<?php if ( !$bp->groups->new_group->photos_admin_only ) { ?> checked="checked"<?php } ?> /> <?php _e('All members can upload photos', 'buddypress') ?></label>
    2675                         <label><input type="radio" name="group-photos-status" value="admins"<?php if ( $bp->groups->new_group->photos_admin_only ) { ?> checked="checked"<?php } ?> /> <?php _e('Only group admins can upload photos', 'buddypress') ?></label>
     2684                    <label><input type="checkbox" name="group-show-photos" id="group-show-photos" value="1"<?php if ( $bp->groups->current_group->enable_photos ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable photo gallery', 'buddypress') ?></label>
     2685                    <div class="sub-options"<?php if ( !$bp->groups->current_group->enable_photos ) { ?> style="display: none;"<?php } ?>>
     2686                        <label><input type="radio" name="group-photos-status" value="all"<?php if ( !$bp->groups->current_group->photos_admin_only ) { ?> checked="checked"<?php } ?> /> <?php _e('All members can upload photos', 'buddypress') ?></label>
     2687                        <label><input type="radio" name="group-photos-status" value="admins"<?php if ( $bp->groups->current_group->photos_admin_only ) { ?> checked="checked"<?php } ?> /> <?php _e('Only group admins can upload photos', 'buddypress') ?></label>
    26762688                    </div>
    26772689                </div>
     
    26812693           
    26822694                <div class="radio">
    2683                     <label><input type="radio" name="group-status" value="public"<?php if ( 'public' == $bp->groups->new_group->status ) { ?> checked="checked"<?php } ?> />
     2695                    <label><input type="radio" name="group-status" value="public"<?php if ( 'public' == $bp->groups->current_group->status ) { ?> checked="checked"<?php } ?> />
    26842696                        <strong><?php _e( 'This is a public group', 'buddypress' ) ?></strong>
    26852697                        <ul>
     
    26902702                    </label>
    26912703                   
    2692                     <label><input type="radio" name="group-status" value="private"<?php if ( 'private' == $bp->groups->new_group->status ) { ?> checked="checked"<?php } ?> />
     2704                    <label><input type="radio" name="group-status" value="private"<?php if ( 'private' == $bp->groups->current_group->status ) { ?> checked="checked"<?php } ?> />
    26932705                        <strong><?php _e( 'This is a private group', 'buddypress' ) ?></strong>
    26942706                        <ul>
     
    26992711                    </label>
    27002712                   
    2701                     <label><input type="radio" name="group-status" value="hidden"<?php if ( 'hidden' == $bp->groups->new_group->status ) { ?> checked="checked"<?php } ?> />
     2713                    <label><input type="radio" name="group-status" value="hidden"<?php if ( 'hidden' == $bp->groups->current_group->status ) { ?> checked="checked"<?php } ?> />
    27022714                        <strong><?php _e('This is a hidden group', 'buddypress') ?></strong>
    27032715                        <ul>
  • trunk/bp-status/bp-status-filters.php

    r1567 r1621  
    11<?php
    22
    3 add_filter( 'bp_get_the_status', 'wp_filter_kses', 1 );
     3add_filter( 'bp_get_the_status', 'bp_status_filter_tags' );
     4add_filter( 'bp_get_the_status', 'force_balance_tags' );
    45add_filter( 'bp_get_the_status', 'wptexturize' );
    56add_filter( 'bp_get_the_status', 'convert_smilies' );
     
    89add_filter( 'bp_get_the_status', 'stripslashes_deep' );
    910
     11function bp_status_filter_tags( $status ) {
     12    return apply_filters( 'bp_status_filter_tags', strip_tags( $status, '<a>' ) );
     13}
     14
    1015?>
  • trunk/bp-wire.php

    r1599 r1621  
    9898 */
    9999
    100 function bp_wire_new_post( $item_id, $message, $component_name, $private_post = false, $table_name = null ) {
     100function bp_wire_new_post( $item_id, $message, $component_name, $deprecated = false, $table_name = null ) {
    101101    global $bp;
    102102   
     
    119119    if ( !$wire_post->save() )
    120120        return false;
    121    
    122     if ( !$private_post ) {
    123         // Record in the activity streams
    124         bp_wire_record_activity( array( 'item_id' => $wire_post->id, 'component_name' => $component_name, 'component_action' => 'new_wire_post', 'is_private' => 0 ) );
    125     }
    126121   
    127122    do_action( 'bp_wire_post_posted', $wire_post->id, $wire_post->item_id, $wire_post->user_id );
     
    151146        return false;
    152147
    153     // Delete activity stream items
    154     bp_wire_delete_activity( array( 'user_id' => $wire_post->user_id, 'item_id' => $wire_post->id, 'component_name' => $component_name, 'component_action' => 'new_wire_post' ) ); 
    155 
    156148    do_action( 'bp_wire_post_deleted', $wire_post->id, $wire_post->item_id, $wire_post->user_id );
    157149   
Note: See TracChangeset for help on using the changeset viewer.