Skip to:
Content

BuddyPress.org

Ticket #2002: 2002.003.diff

File 2002.003.diff, 10.5 KB (added by cnorris23, 14 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. */
     
    231231}
    232232add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
    233233
    234 /* AJAX delete an activity */
     234/**
     235 * bp_dtheme_delete_activity()
     236 *
     237 * Delete specific activity item via AJAX.
     238 *
     239 * @since 1.2
     240 *
     241 * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow action
     242 *      to be taken before the activity is deleted.
     243 * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow action
     244 *      to be taken after the activity is deleted.
     245 * @uses check_admin_referer()
     246 * @uses is_user_logged_in()
     247 * @uses is_super_admin()
     248 * @uses bp_loggedin_user_id()
     249 * @uses bp_activity_delete()
     250 *
     251 * @global object $bp BuddyPress global settings
     252 * @return bool False on failure. True if activity deleted.
     253 */
    235254function bp_dtheme_delete_activity() {
    236255        global $bp;
    237256
     
    249268        $activity = new BP_Activity_Activity( $_POST['id'] );
    250269
    251270        // Check access
    252         if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
     271        if ( !is_super_admin() && ( (int) $activity->user_id !== (int) bp_loggedin_user_id() ) )
    253272                return false;
    254273
    255274        // Call the action before the delete so plugins can still fetch information about it
     
    326345 * @since 1.3
    327346 */
    328347function bp_dtheme_get_single_activity_content() {
    329         $activity_array = bp_activity_get_specific( array( 
    330                 'activity_ids'          => $_POST['activity_id'], 
    331                 'display_comments'      => 'stream' 
     348        $activity_array = bp_activity_get_specific( array(
     349                'activity_ids'          => $_POST['activity_id'],
     350                'display_comments'      => 'stream'
    332351        ) );
    333        
     352
    334353        $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
    335        
     354
    336355        if ( !$activity )
    337356                exit(); // todo: error?
    338        
     357
    339358        // Activity content retrieved through AJAX should run through normal filters, but not be
    340359        // truncated
    341360        remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
    342361        $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
    343        
     362
    344363        echo $content;
    345        
     364
    346365        exit();
    347366}
    348367add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
     
    647666                        if ( !$ud )
    648667                                continue;
    649668
    650                         if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 
     669                        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    651670                                $username = $ud->user_login;
    652671                        else
    653672                                $username = $ud->user_nicename;
  • bp-activity/bp-activity-actions.php

     
    6363}
    6464add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
    6565
     66/**
     67 * bp_activity_action_delete_activity()
     68 *
     69 * Delete specific activity item and redirect to previous page ( if applicable ).
     70 *
     71 * @package BuddyPress Activity
     72 * @since 1.1
     73 *
     74 * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions
     75 *      to be taken before the activity is deleted.
     76 * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions
     77 *      to be taken after the activity is deleted.
     78 * @uses bp_is_activity_component()
     79 * @uses bp_is_current_action()
     80 * @uses check_admin_referer()
     81 * @uses wp_get_referer()
     82 * @uses bp_get_root_domain()
     83 * @uses bp_activity_delete()
     84 * @uses bp_core_add_message()
     85 * @uses bp_core_redirect()
     86 *
     87 * @global object $bp
     88 */
    6689function bp_activity_action_delete_activity() {
    6790        global $bp;
    6891
    6992        // Not viewing activity or action is not delete
    70         if ( ( $bp->activity->slug != bp_current_component() ) || !bp_is_current_action( 'delete' ) )
     93        if ( bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
    7194                return false;
    7295
    7396        // Not viewing a specific activity item
     
    82105        $activity    = new BP_Activity_Activity( $activity_id );
    83106
    84107        // Check access
    85         if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
     108        if ( !is_super_admin() && $activity->user_id != bp_loggedin_user_id() )
    86109                return false;
    87110
    88111        // Call the action before the delete so plugins can still fetch information about it
    89112        do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
    90113
     114        // Check for the redirect query arg, otherwise let WP handle things
     115        $bp_redirect_to = ( isset( $_GET['bp_redirect_to'] ) ) ? $_GET['bp_redirect_to'] : wp_get_referer();
     116
     117        // Always redirect somewhere
     118        if ( empty( $bp_redirect_to ) )
     119                $bp_redirect_to = bp_get_root_domain();
     120
    91121        // Delete the activity item and provide user feedback
    92122        if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
    93123                bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
     
    97127        do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
    98128
    99129        // Redirect
    100         bp_core_redirect( wp_get_referer() );
     130        bp_core_redirect( $bp_redirect_to );
    101131}
    102132add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
    103133
     
    218248
    219249function bp_activity_action_sitewide_feed() {
    220250        global $bp, $wp_query;
    221        
     251
    222252        if ( !bp_is_current_component( 'activity' ) || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp->groups->current_group ) )
    223253                return false;
    224254
  • 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 * @package BuddyPress Activity
     987 * @since 1.1
     988 *
     989 * @uses bp_get_activity_delete_link()
     990 */
    981991function bp_activity_delete_link() {
    982992        echo bp_get_activity_delete_link();
    983993}
     994
     995        /**
     996         * bp_get_activity_delete_link()
     997         *
     998         * Return the activity delete link.
     999         *
     1000         * @package BuddyPress Activity
     1001         * @since 1.1
     1002         *
     1003         * @uses apply_filters() Calls 'bp_get_activity_delete_link' hook to allow altering
     1004         *      of the activity delete link.
     1005         * @uses bp_is_activity_component()
     1006         * @uses bp_current_action()
     1007         * @uses wp_nonce_url()
     1008         * @uses add_query_arg()
     1009         * @uses wp_get_referer()
     1010         * @uses bp_get_root_domain()
     1011         * @uses bp_get_activity_root_slug()
     1012         *
     1013         * @global object $bp BuddyPress global settings
     1014         * @global object $activities_template BuddyPress Activities Template
     1015         * @return string $link Activity delete link. Contains $bp_redirect_to arg if on single activity page.
     1016         */
    9841017        function bp_get_activity_delete_link() {
    9851018                global $activities_template, $bp;
    9861019
    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>' );
     1020                // Determine if we're on a single activity page, and customize accordingly
     1021                if ( bp_is_activity_component() && is_numeric( bp_current_action() ) )
     1022                        $link = '<a href="' . wp_nonce_url( add_query_arg( array( 'bp_redirect_to' => wp_get_referer() ), bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ), 'bp_activity_delete_link' ) . '" class="item-button delete-single-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
     1023                else
     1024                        $link = '<a href="' . wp_nonce_url( ( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ), 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>' );
     1025
     1026                return apply_filters( 'bp_get_activity_delete_link', $link );
    9881027        }
    9891028
    9901029function bp_activity_latest_update( $user_id = 0 ) {