Skip to:
Content

BuddyPress.org

Changeset 2004 for trunk/bp-groups.php


Ignore:
Timestamp:
09/30/2009 04:42:06 PM (17 years ago)
Author:
apeatling
Message:

Group forum editing and activity recording fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups.php

    r1995 r2004  
    601601   
    602602    if ( $bp->is_single_item && $bp->groups->current_group->user_has_access ) {
     603       
     604        /* Fetch the details we need */
    603605        $topic_slug = $bp->action_variables[1];
    604606        $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug );
     
    637639                    bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
    638640           
    639                 do_action( 'groups_stick_topic', $topic_id );
     641                do_action( 'groups_stick_forum_topic', $topic_id );
    640642                bp_core_redirect( wp_get_referer() );
    641643            }
     
    651653                    bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
    652654           
    653                 do_action( 'groups_unstick_topic', $topic_id );
     655                do_action( 'groups_unstick_forum_topic', $topic_id );
    654656                bp_core_redirect( wp_get_referer() );
    655657            }
     
    665667                    bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
    666668           
    667                 do_action( 'groups_close_topic', $topic_id );
     669                do_action( 'groups_close_forum_topic', $topic_id );
    668670                bp_core_redirect( wp_get_referer() );
    669671            }
     
    679681                    bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
    680682           
    681                 do_action( 'groups_open_topic', $topic_id );
     683                do_action( 'groups_open_forum_topic', $topic_id );
    682684                bp_core_redirect( wp_get_referer() );
    683685            }
    684686
    685687            /* Delete a topic */
    686             else if ( 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     688            else if ( 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
     689                /* Fetch the topic */
     690                $topic = bp_forums_get_topic_details( $topic_id );
     691
     692                /* Check the logged in user can delete this topic */
     693                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$topic->topic_poster )
     694                    bp_core_redirect( wp_get_referer() );
     695               
    687696                /* Check the nonce */
    688697                check_admin_referer( 'bp_forums_delete_topic' );
     
    692701                else
    693702                    bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
    694 
     703               
     704                do_action( 'groups_delete_forum_topic', $topic_id );
    695705                bp_core_redirect( wp_get_referer() );
    696706            }
    697707           
    698708            /* Editing a topic */
    699             else if ( 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     709            else if ( 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
     710                /* Fetch the topic */
     711                $topic = bp_forums_get_topic_details( $topic_id );
     712
     713                /* Check the logged in user can edit this topic */
     714                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$topic->topic_poster )
     715                    bp_core_redirect( wp_get_referer() );
     716
    700717                if ( isset( $_POST['save_changes'] ) ) {
    701718                    /* Check the nonce */
     
    707724                        bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
    708725               
     726                    do_action( 'groups_edit_forum_topic', $topic_id );
    709727                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
    710728                }
    711 
    712                 /* Check that the user has access to edit this topic, if not, redirect. */
    713                 $topic = bp_forums_get_topic_details( $topic_id );
    714                 if ( ( !$bp->is_item_admin && !$bp->is_item_mod ) && $bp->loggedin_user->id != $topic->topic_poster )
    715                     bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
    716 
     729               
    717730                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
    718731            }
    719732           
    720733            /* Delete a post */
    721             else if ( 'delete' == $bp->action_variables[2] && $bp->action_variables[4] && ( $bp->is_item_admin || $bp->is_item_mod ) ) {
     734            else if ( 'delete' == $bp->action_variables[2] && $post_id = $bp->action_variables[4] ) {
     735                /* Fetch the post */
     736                $post = bp_forums_get_post( $post_id );
     737
     738                /* Check the logged in user can edit this topic */
     739                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id )
     740                    bp_core_redirect( wp_get_referer() );
     741
    722742                /* Check the nonce */
    723743                check_admin_referer( 'bp_forums_delete_post' );
     
    727747                else
    728748                    bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
    729 
     749               
     750                do_action( 'groups_delete_forum_post', $post_id );
    730751                bp_core_redirect( wp_get_referer() );
    731752            }
     
    733754            /* Editing a post */
    734755            else if ( 'edit' == $bp->action_variables[2] && $post_id = $bp->action_variables[4] ) {
     756                /* Fetch the post */
     757                $post = bp_forums_get_post( $bp->action_variables[4] );
     758
     759                /* Check the logged in user can edit this topic */
     760                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id )
     761                    bp_core_redirect( wp_get_referer() );
     762
    735763                if ( isset( $_POST['save_changes'] ) ) {
    736764                    /* Check the nonce */
     
    741769                    else
    742770                        bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
    743                
     771                   
     772                    do_action( 'groups_edit_forum_post', $post_id );
    744773                    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
    745774                }
    746775               
    747                 /* Check that the user has access to edit this post, if not, redirect. */
    748                 $post = bp_forums_get_post( $post_id );
    749                 if ( ( !$bp->is_item_admin && !$bp->is_item_mod ) && $bp->loggedin_user->id != $post->poster_id )
    750                     bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic_slug . '/' );
    751 
    752776                bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
    753777            }
     
    760784                    bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/forum/topic' ) );
    761785            }
     786           
    762787        } else {
    763788
     
    20982123            'component_action' => 'new_forum_post',
    20992124            'item_id' => $bp->groups->current_group->id,
    2100             'secondary_item_id' => $forum_post->id
     2125            'secondary_item_id' => $forum_post
    21012126        ) );
    21022127
     
    21432168    if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id ) ) ) {
    21442169        /* Update the activity stream item */
    2145         bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
     2170        if ( function_exists( 'bp_activity_delete_by_item_id' ) )
     2171            bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_forum_topic' ) );
    21462172       
    21472173        $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>' );
     
    21722198    $post = bp_forums_get_post( $post_id );
    21732199       
    2174     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 ) ) ) {
     2200    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, 'poster_id' => $post->poster_id ) ) ) {
    21752201        $topic = bp_forums_get_topic_details( $topic_id );
    21762202
    21772203        /* Update the activity stream item */
    2178         bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
    2179        
     2204        if ( function_exists( 'bp_activity_delete_by_item_id' ) )
     2205            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' ) );
     2206           
    21802207        $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>' );
    21812208        $activity_content .= '<blockquote>' . bp_create_excerpt( attribute_escape( $post_text ) ) . '</blockquote>';
     
    21862213            'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
    21872214            'component_action' => 'new_forum_post',
    2188             'item_id' => $bp->groups->current_group->id,
     2215            'item_id' => (int)$bp->groups->current_group->id,
     2216            'user_id' => (int)$post->poster_id,
    21892217            'secondary_item_id' => $post_id,
    21902218            'recorded_time' => strtotime( $post->post_time )
     
    22052233        /* Delete the activity stream item */
    22062234        if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    2207             bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_topic' ) );
    2208             bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => 'groups', 'component_action' => 'new_forum_post' ) );
     2235            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_forum_topic' ) );
     2236            bp_activity_delete_by_item_id( array( 'item_id' => $topic_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_forum_post' ) );
    22092237        }
    22102238
Note: See TracChangeset for help on using the changeset viewer.