Skip to:
Content

BuddyPress.org

Ticket #2002: 2002.004.diff

File 2002.004.diff, 10.0 KB (added by DJPaul, 8 years ago)
  • bp-themes/bp-default/_inc/ajax.php

     
    5353        if ( !empty( $_POST['page'] ) && '-1' != $_POST['page'] )
    5454                $qs[] = 'page=' . $_POST['page'];
    5555
    56         $object_search_text = bp_get_search_default_text( $object ); 
    57         if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] ) 
     56        $object_search_text = bp_get_search_default_text( $object );
     57        if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
    5858                $qs[] = 'search_terms=' . $_POST['search_terms'];
    5959
    6060        /* Now pass the querystring to override default values. */
     
    246246        if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) )
    247247                return false;
    248248
    249         $activity = new BP_Activity_Activity( $_POST['id'] );
     249        $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    250250
    251251        // Check access
    252         if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
     252        if ( !is_super_admin() && ( $activity->user_id != bp_loggedin_user_id() ) )
    253253                return false;
    254254
    255255        // Call the action before the delete so plugins can still fetch information about it
    256         do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $activity->user_id );
     256        do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
    257257
    258         if ( !bp_activity_delete( array( 'id' => $_POST['id'], 'user_id' => $activity->user_id ) ) ) {
     258        if ( !bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
    259259                echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
    260260                return false;
    261261        }
    262262
    263         do_action( 'bp_activity_action_delete_activity', $_POST['id'], $activity->user_id );
     263        do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
    264264
    265265        return true;
    266266}
     
    326326 * @since 1.3
    327327 */
    328328function bp_dtheme_get_single_activity_content() {
    329         $activity_array = bp_activity_get_specific( array( 
    330                 'activity_ids'          => $_POST['activity_id'], 
    331                 'display_comments'      => 'stream' 
     329        $activity_array = bp_activity_get_specific( array(
     330                'activity_ids'          => $_POST['activity_id'],
     331                'display_comments'      => 'stream'
    332332        ) );
    333        
     333
    334334        $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
    335        
     335
    336336        if ( !$activity )
    337337                exit(); // todo: error?
    338        
     338
    339339        // Activity content retrieved through AJAX should run through normal filters, but not be
    340340        // truncated
    341341        remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
    342342        $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
    343        
     343
    344344        echo $content;
    345        
     345
    346346        exit();
    347347}
    348348add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
     
    647647                        if ( !$ud )
    648648                                continue;
    649649
    650                         if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 
     650                        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    651651                                $username = $ud->user_login;
    652652                        else
    653653                                $username = $ud->user_nicename;
  • bp-activity/bp-activity-actions.php

     
    6363}
    6464add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
    6565
    66 function bp_activity_action_delete_activity() {
     66/**
     67 * bp_activity_action_delete_activity()
     68 *
     69 * Delete specific activity item and redirect to previous page.
     70 *
     71 * @global object $bp
     72 * @since 1.1
     73 * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
     74 * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted.
     75 */
     76function bp_activity_action_delete_activity( $activity_id = 0 ) {
    6777        global $bp;
    6878
    6979        // Not viewing activity or action is not delete
    70         if ( ( $bp->activity->slug != bp_current_component() ) || !bp_is_current_action( 'delete' ) )
     80        if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
    7181                return false;
    7282
     83        if ( empty( $activity_id ) && !empty( $bp->action_variables[0] ) && is_numeric( $bp->action_variables[0] ) )
     84                $activity_id = (int) $bp->action_variables[0];
     85
    7386        // Not viewing a specific activity item
    74         if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
     87        if ( empty( $activity_id ) )
    7588                return false;
    7689
    7790        // Check the nonce
    7891        check_admin_referer( 'bp_activity_delete_link' );
    7992
    8093        // Load up the activity item
    81         $activity_id = $bp->action_variables[0];
    82         $activity    = new BP_Activity_Activity( $activity_id );
     94        $activity = new BP_Activity_Activity( $activity_id );
    8395
    8496        // Check access
    85         if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
     97        if ( empty( $activity->user_id ) || !is_super_admin() && $activity->user_id != bp_loggedin_user_id() )
    8698                return false;
    8799
    88100        // Call the action before the delete so plugins can still fetch information about it
     
    90102
    91103        // Delete the activity item and provide user feedback
    92104        if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
    93                 bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
     105                bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
    94106        else
    95107                bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
    96108
    97109        do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
    98110
    99         // Redirect
    100         bp_core_redirect( wp_get_referer() );
     111        // Check for the redirect query arg, otherwise let WP handle things
     112        if ( !empty( $_GET['redirect_to'] ) )
     113                bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
     114        else
     115                bp_core_redirect( wp_get_referer() );
    101116}
    102117add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
    103118
     
    218233
    219234function bp_activity_action_sitewide_feed() {
    220235        global $bp, $wp_query;
    221        
     236
    222237        if ( !bp_is_current_component( 'activity' ) || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp->groups->current_group ) )
    223238                return false;
    224239
  • bp-activity/bp-activity-template.php

     
    394394 */
    395395function bp_activity_has_more_items() {
    396396        global $activities_template;
    397        
    398         $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); 
     397
     398        $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
    399399        $has_more_items  = (int)$remaining_pages ? true : false;
    400        
     400
    401401        return apply_filters( 'bp_activity_has_more_items', $has_more_items );
    402402}
    403403
     
    504504}
    505505        function bp_get_activity_user_link() {
    506506                global $activities_template;
    507                
     507
    508508                if ( empty( $activities_template->activity->user_id ) )
    509509                        $link = $activities_template->activity->primary_link;
    510510                else
     
    722722
    723723        if ( $bp->loggedin_user->is_super_admin )
    724724                $can_delete = true;
    725        
     725
    726726        if ( $activities_template->activity->user_id == $bp->loggedin_user->id )
    727727                $can_delete = true;
    728                
     728
    729729        if ( $bp->is_item_admin && $bp->is_single_item )
    730730                $can_delete = true;
    731        
     731
    732732        return apply_filters( 'bp_activity_user_can_delete', $can_delete );
    733733}
    734734
     
    801801                        foreach ( (array)$comment->children as $comment_child ) {
    802802                                // Put the comment into the global so it's available to filters
    803803                                $activities_template->activity->current_comment = $comment_child;
    804                                
     804
    805805                                if ( empty( $comment_child->user_fullname ) )
    806806                                        $comment_child->user_fullname = $comment_child->display_name;
    807807
     
    853853
    854854                                $content .= bp_activity_recurse_comments( $comment_child );
    855855                                $content .= '</li>';
    856                                
     856
    857857                                // Unset in the global in case of the last iteration
    858858                                unset( $activities_template->activity->current_comment );
    859859                        }
     
    978978                return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
    979979        }
    980980
     981/**
     982 * bp_activity_delete_link()
     983 *
     984 * Display the activity delete link.
     985 *
     986 * @since 1.1
     987 * @uses bp_get_activity_delete_link()
     988 */
    981989function bp_activity_delete_link() {
    982990        echo bp_get_activity_delete_link();
    983991}
     992
     993        /**
     994         * bp_get_activity_delete_link()
     995         *
     996         * Return the activity delete link.
     997         *
     998         * @global object $activities_template BuddyPress Activities Template
     999         * @global object $bp BuddyPress global settings
     1000         * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
     1001         * @since 1.1
     1002         */
    9841003        function bp_get_activity_delete_link() {
    9851004                global $activities_template, $bp;
    9861005
    987                 return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( bp_get_root_domain() . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
     1006                $url = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
     1007
     1008                // Determine if we're on a single activity page, and customize accordingly
     1009                if ( bp_is_activity_component() && is_numeric( bp_current_action() ) )
     1010                        $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
     1011
     1012                $link = '<a href="' . wp_nonce_url( $url, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
     1013                return apply_filters( 'bp_get_activity_delete_link', $link );
    9881014        }
    9891015
    9901016function bp_activity_latest_update( $user_id = 0 ) {