Skip to:
Content

BuddyPress.org

Changeset 1858 for trunk/bp-groups.php


Ignore:
Timestamp:
09/11/2009 11:59:16 PM (17 years ago)
Author:
apeatling
Message:

Added support for global group forum listings and fixed a few forum admin glitches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups.php

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