Skip to:
Content

BuddyPress.org

Changeset 6003


Ignore:
Timestamp:
04/21/2012 05:26:22 PM (9 years ago)
Author:
djpaul
Message:

Resolve problems with load order when handling AJAX requests in BuddyPress. Fixes #2599 and #3985, props DJPaul and boonebgorges.

  • Reworks BP-Default's AJAX calls to use correct receiver in WordPress.
  • Hooks BP-Default's AJAX handlers to both 'wp_ajax_nopriv_' and 'wp_ajax'.
  • Updates associated parts in BP core to support this, and deprecates old handling.
  • Renames Activity spam/unspam AJAX actions (new to BP 1.6).
  • Adds full PHPDoc to ajax.php.
  • Code standards pass of ajax.php.
  • Remove unnecessary globals.
  • Backwards compatible with themes based on versions of BP-Default earlier 1.6.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-cssjs.php

    r5996 r6003  
    130130 * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
    131131 *
    132  * @package BuddyPress Core
     132 * @since 1.1
    133133 */
    134134function bp_core_add_ajax_url_js() {
    135135?>
    136136
    137     <script type="text/javascript">var ajaxurl = "<?php echo site_url( 'wp-load.php' ); ?>";</script>
     137    <script type="text/javascript">var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';</script>
    138138
    139139<?php
  • trunk/bp-core/bp-core-functions.php

    r5993 r6003  
    699699}
    700700add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );
    701 
    702 function bp_core_add_ajax_hook() {
    703     // Theme only, we already have the wp_ajax_ hook firing in wp-admin
    704     if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )
    705         do_action( 'wp_ajax_' . $_REQUEST['action'] );
    706 }
    707 add_action( 'bp_init', 'bp_core_add_ajax_hook', 20 );
    708701
    709702/**
  • trunk/bp-core/deprecated/1.6.php

    r5808 r6003  
    5454 */
    5555
    56 /*
     56/**
    5757 * @deprecated 1.6
    5858 * @deprecated No longer used; see bp_blogs_transition_activity_status()
     
    6666 */
    6767
    68 /*
     68/**
    6969 * @deprecated 1.6
    7070 * @deprecated No longer used; see BP_Admin::admin_menus()
     
    7474}
    7575
     76/**
     77 * @deprecated 1.6
     78 * @deprecated No longer used. We do ajax properly now.
     79 */
     80function bp_core_add_ajax_hook() {
     81    _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
     82}
    7683
    7784/**
     
    125132    return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] );
    126133}
     134
     135/**
     136 * Backward compatibility for AJAX callbacks that do not die() on their own
     137 *
     138 * In BuddyPress 1.6, BP was altered so that it uses admin-ajax.php (instead of wp-load.php) for
     139 * AJAX requests. admin-ajax.php dies with an output of '0' (to signify an error), so that if an
     140 * AJAX callback does not kill PHP execution, a '0' character will be erroneously appended to the
     141 * output. All bp-default AJAX callbacks (/bp-themes/bp-default/_inc/ajax.php) have been updated
     142 * for BP 1.6 so that they die() properly; any theme that dynamically includes this file will
     143 * inherit the fixes. However, any theme that contains a copy of BP's pre-1.5 ajax.php file will
     144 * continue to witness the 'trailing "0"' problem.
     145 *
     146 * This function provides a backward compatible workaround for these themes, by hooking to the
     147 * BP wp_ajax_ actions that were problematic prior to BP 1.6, and killing PHP execution with die().
     148 *
     149 * Note that this hack only runs if the function bp_dtheme_register_actions() is not found (this
     150 * function was introduced in BP 1.6 for related backward compatibility reasons).
     151 */
     152if ( !function_exists( 'bp_dtheme_register_actions' ) ) :
     153    function bp_die_legacy_ajax_callbacks() {
     154
     155        // This is a list of the BP wp_ajax_ hook suffixes whose associated functions did
     156        // not die properly before BP 1.6
     157        $actions = array(
     158            // Directory template loaders
     159            'members_filter',
     160            'groups_filter',
     161            'blogs_filter',
     162            'forums_filter',
     163            'messages_filter',
     164
     165            // Activity
     166            'activity_widget_filter',
     167            'activity_get_older_updates',
     168            'post_update',
     169            'new_activity_comment',
     170            'delete_activity',
     171            'delete_activity_comment',
     172            'spam_activity',
     173            'spam_activity_comment',
     174            'activity_mark_fav',
     175            'activity_mark_unfav',
     176
     177            // Groups
     178            'groups_invite_user',
     179            'joinleave_group',
     180
     181            // Members
     182            'addremove_friend',
     183            'accept_friendship',
     184            'reject_friendship',
     185
     186            // Messages
     187            'messages_close_notice',
     188            'messages_send_reply',
     189            'messages_markunread',
     190            'messages_markread',
     191            'messages_delete',
     192            'messages_autocomplete_results'
     193        );
     194
     195        // For each of the problematic hooks, exit at the very end of execution
     196        foreach( $actions as $action ) {
     197            add_action( 'wp_ajax_'        . $action, create_function( '', 'exit;' ), 9999 );
     198            add_action( 'wp_ajax_nopriv_' . $action, create_function( '', 'exit;' ), 9999 );
     199        }
     200    }
     201    add_action( 'after_setup_theme', 'bp_die_legacy_ajax_callbacks', 20 );
     202endif;
    127203?>
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r5931 r6003  
    11<?php
    2 
    3 /***
     2/**
    43 * AJAX Functions
    54 *
    6  * All of these functions enhance the responsiveness of the user interface in the default
    7  * theme by adding AJAX functionality.
    8  */
    9 
    10 /***
     5 * All of these functions enhance the responsiveness of the user interface in
     6 * the default theme by adding AJAX functionality.
     7 *
     8 * For more information on how the custom AJAX functions work, see
     9 * http://codex.wordpress.org/AJAX_in_Plugins.
     10 *
     11 * @package BuddyPress
     12 * @since 1.2
     13 * @subpackage BP-Default
     14 */
     15
     16// Exit if accessed directly
     17if ( ! defined( 'ABSPATH' ) ) exit;
     18
     19/**
     20 * Register AJAX handlers for BP Default theme functionality.
     21 *
     22 * This function is registered to the after_setup_theme hook with priority 20 as
     23 * this file is included in a function hooked to after_setup_theme at priority 10.
     24 *
     25 * @since BuddyPress (1.6)
     26 */
     27function bp_dtheme_register_actions() {
     28    $actions = array(
     29        // Directory filters
     30        'blogs_filter'    => 'bp_dtheme_object_template_loader',
     31        'forums_filter'   => 'bp_dtheme_object_template_loader',
     32        'groups_filter'   => 'bp_dtheme_object_template_loader',
     33        'members_filter'  => 'bp_dtheme_object_template_loader',
     34        'messages_filter' => 'bp_dtheme_messages_template_loader',
     35
     36        // Friends
     37        'accept_friendship' => 'bp_dtheme_ajax_accept_friendship',
     38        'addremove_friend'  => 'bp_dtheme_ajax_addremove_friend',
     39        'reject_friendship' => 'bp_dtheme_ajax_reject_friendship',
     40
     41        // Activity
     42        'activity_get_older_updates'  => 'bp_dtheme_activity_template_loader',
     43        'activity_mark_fav'           => 'bp_dtheme_mark_activity_favorite',
     44        'activity_mark_unfav'         => 'bp_dtheme_unmark_activity_favorite',
     45        'activity_widget_filter'      => 'bp_dtheme_activity_template_loader',
     46        'delete_activity'             => 'bp_dtheme_delete_activity',
     47        'delete_activity_comment'     => 'bp_dtheme_delete_activity_comment',
     48        'get_single_activity_content' => 'bp_dtheme_get_single_activity_content',
     49        'new_activity_comment'        => 'bp_dtheme_new_activity_comment',
     50        'post_update'                 => 'bp_dtheme_post_update',
     51        'bp_spam_activity'            => 'bp_dtheme_spam_activity',
     52        'bp_spam_activity_comment'    => 'bp_dtheme_spam_activity',
     53
     54        // Groups
     55        'groups_invite_user' => 'bp_dtheme_ajax_invite_user',
     56        'joinleave_group'    => 'bp_dtheme_ajax_joinleave_group',
     57
     58        // Messages
     59        'messages_autocomplete_results' => 'bp_dtheme_ajax_messages_autocomplete_results',
     60        'messages_close_notice'         => 'bp_dtheme_ajax_close_notice',
     61        'messages_delete'               => 'bp_dtheme_ajax_messages_delete',
     62        'messages_markread'             => 'bp_dtheme_ajax_message_markread',
     63        'messages_markunread'           => 'bp_dtheme_ajax_message_markunread',
     64        'messages_send_reply'           => 'bp_dtheme_ajax_messages_send_reply',
     65    );
     66
     67    /**
     68     * Register all of these AJAX handlers
     69     *
     70     * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
     71     * executes for users that aren't logged in. This is for backpat with BP <1.6.
     72     */
     73    foreach( $actions as $name => $function ) {
     74        add_action( 'wp_ajax_'        . $name, $function );
     75        add_action( 'wp_ajax_nopriv_' . $name, $function );
     76    }
     77}
     78add_action( 'after_setup_theme', 'bp_dtheme_register_actions', 20 );
     79
     80/**
    1181 * This function looks scarier than it actually is. :)
    1282 * Each object loop (activity/members/groups/blogs/forums) contains default parameters to
     
    1585 * to override the parameters sent. That way we can change the results returned without reloading the page.
    1686 * By using cookies we can also make sure that user settings are retained across page loads.
     87 *
     88 * @return string Query string for the activity/members/groups/blogs/forums loops
     89 * @since BuddyPress (1.2)
    1790 */
    1891function bp_dtheme_ajax_querystring( $query_string, $object ) {
    19     global $bp;
    20 
    2192    if ( empty( $object ) )
    22         return false;
    23 
    24     /* Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts */
    25     if ( !empty( $_POST['cookie'] ) )
     93        return '';
     94
     95    // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts
     96    if ( ! empty( $_POST['cookie'] ) )
    2697        $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) );
    2798    else
    2899        $_BP_COOKIE = &$_COOKIE;
    29100
    30     $qs = false;
    31 
    32     /***
     101    $qs = array();
     102
     103    /**
    33104     * Check if any cookie values are set. If there are then override the default params passed to the
    34105     * template loop
    35106     */
    36     if ( !empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
    37         $qs[] = 'type=' . $_BP_COOKIE['bp-' . $object . '-filter'];
    38         $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter']; // Activity stream filtering on action
    39     }
    40 
    41     if ( !empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
     107
     108    // Activity stream filtering on action
     109    if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
     110        $qs[] = 'type='   . $_BP_COOKIE['bp-' . $object . '-filter'];
     111        $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter'];
     112    }
     113
     114    if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
    42115        if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
    43116            $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    44117            $qs[] = 'user_id=' . $user_id;
    45118        }
    46         if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && !bp_displayed_user_id() && !$bp->is_single_item )
    47             $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope']; // Activity stream scope only on activity directory.
    48     }
    49 
    50     /* If page and search_terms have been passed via the AJAX post request, use those */
    51     if ( !empty( $_POST['page'] ) && '-1' != $_POST['page'] )
     119
     120        // Activity stream scope only on activity directory.
     121        if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() )
     122            $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope'];
     123    }
     124
     125    // If page and search_terms have been passed via the AJAX post request, use those.
     126    if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] )
    52127        $qs[] = 'page=' . $_POST['page'];
    53128
    54129    $object_search_text = bp_get_search_default_text( $object );
    55     if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
     130    if ( ! empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
    56131        $qs[] = 'search_terms=' . $_POST['search_terms'];
    57132
    58     /* Now pass the querystring to override default values. */
     133    // Now pass the querystring to override default values.
    59134    $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
    60135
     
    83158add_filter( 'bp_ajax_querystring', 'bp_dtheme_ajax_querystring', 10, 2 );
    84159
    85 /* This function will simply load the template loop for the current object. On an AJAX request */
     160/**
     161 * Load the template loop for the current object.
     162 *
     163 * @return string Prints template loop for the specified object
     164 * @since BuddyPress (1.2)
     165 */
    86166function bp_dtheme_object_template_loader() {
    87 
    88167    // Bail if not a POST action
    89168    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    96175     * of themselves rather than the directory version.
    97176     */
    98     if ( !bp_current_action() )
     177
     178    if ( ! bp_current_action() )
    99179        bp_update_is_directory( true, bp_current_component() );
    100180
     
    104184    // Locate the object template
    105185    locate_template( array( "$object/$object-loop.php" ), true );
    106 }
    107 add_action( 'wp_ajax_members_filter',  'bp_dtheme_object_template_loader'   );
    108 add_action( 'wp_ajax_groups_filter',   'bp_dtheme_object_template_loader'   );
    109 add_action( 'wp_ajax_blogs_filter',    'bp_dtheme_object_template_loader'   );
    110 add_action( 'wp_ajax_forums_filter',   'bp_dtheme_object_template_loader'   );
    111 add_action( 'wp_ajax_messages_filter', 'bp_dtheme_messages_template_loader' );
    112 
    113 /*
    114  * Load messages when searched on the private message page
    115  */
    116 
     186    exit;
     187}
     188
     189/**
     190 * Load messages template loop when searched on the private message page
     191 *
     192 * @return string Prints template loop for the Messages component
     193 * @since BuddyPress (1.6)
     194 */
    117195function bp_dtheme_messages_template_loader(){
    118     locate_template( array( 'members/single/messages/messages-loop.php' ), true );
    119 }
    120 
    121 // This function will load the activity loop template when activity is requested via AJAX
     196    locate_template( array( 'members/single/messages/messages-loop.php' ), true );
     197    exit;
     198}
     199
     200/**
     201 * Load the activity loop template when activity is requested via AJAX,
     202 *
     203 * @return string JSON object containing 'contents' (output of the template loop for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
     204 * @since BuddyPress (1.2)
     205 */
    122206function bp_dtheme_activity_template_loader() {
    123 
    124207    // Bail if not a POST action
    125208    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    127210
    128211    $scope = '';
    129     if ( !empty( $_POST['scope'] ) )
     212    if ( ! empty( $_POST['scope'] ) )
    130213        $scope = $_POST['scope'];
    131214
     
    150233    }
    151234
    152     /* Buffer the loop in the template to a var for JS to spit out. */
     235    // Buffer the loop in the template to a var for JS to spit out.
    153236    ob_start();
    154237    locate_template( array( 'activity/activity-loop.php' ), true );
     
    157240    ob_end_clean();
    158241
    159     echo json_encode( $result );
    160 }
    161 add_action( 'wp_ajax_activity_widget_filter', 'bp_dtheme_activity_template_loader' );
    162 add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_activity_template_loader' );
    163 
    164 /* AJAX update posting */
     242    exit( json_encode( $result ) );
     243}
     244
     245/**
     246 * Processes Activity updates received via a POST request.
     247 *
     248 * @return string HTML
     249 * @since BuddyPress (1.2)
     250 */
    165251function bp_dtheme_post_update() {
    166 
    167252    // Bail if not a POST action
    168253    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    172257    check_admin_referer( 'post_update', '_wpnonce_post_update' );
    173258
    174     if ( !is_user_logged_in() ) {
    175         echo '-1';
    176         return false;
    177     }
    178 
    179     if ( empty( $_POST['content'] ) ) {
    180         echo '-1<div id="message" class="error"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>';
    181         return false;
    182     }
     259    if ( ! is_user_logged_in() )
     260        exit( '-1' );
     261
     262    if ( empty( $_POST['content'] ) )
     263        exit( '-1<div id="message" class="error"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>' );
    183264
    184265    $activity_id = 0;
     
    187268
    188269    } elseif ( $_POST['object'] == 'groups' ) {
    189         if ( !empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )
     270        if ( ! empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )
    190271            $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) );
    191272
     
    194275    }
    195276
    196     if ( empty( $activity_id ) ) {
    197         echo '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
    198         return false;
    199     }
    200 
    201     if ( bp_has_activities ( 'include=' . $activity_id ) ) : ?>
    202         <?php while ( bp_activities() ) : bp_the_activity(); ?>
    203             <?php locate_template( array( 'activity/entry.php' ), true ); ?>
    204         <?php endwhile; ?>
    205      <?php endif;
    206 }
    207 add_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
    208 
    209 /* AJAX activity comment posting */
     277    if ( empty( $activity_id ) )
     278        exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>' );
     279
     280    if ( bp_has_activities ( 'include=' . $activity_id ) ) {
     281        while ( bp_activities() ) {
     282            bp_the_activity();
     283            locate_template( array( 'activity/entry.php' ), true );
     284        }
     285    }
     286
     287    exit;
     288}
     289
     290/**
     291 * Posts new Activity comments received via a POST request.
     292 *
     293 * @global BP_Activity_Template $activities_template
     294 * @return string HTML
     295 * @since BuddyPress (1.2)
     296 */
    210297function bp_dtheme_new_activity_comment() {
     298    global $activities_template;
    211299
    212300    // Bail if not a POST action
     
    217305    check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
    218306
    219     if ( !is_user_logged_in() ) {
    220         echo '-1';
    221         return false;
    222     }
    223 
    224     if ( empty( $_POST['content'] ) ) {
    225         echo '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>';
    226         return false;
    227     }
    228 
    229     if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || !is_numeric( $_POST['form_id'] ) || !is_numeric( $_POST['comment_id'] ) ) {
    230         echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
    231         return false;
    232     }
     307    if ( ! is_user_logged_in() )
     308        exit( '-1' );
     309
     310    if ( empty( $_POST['content'] ) )
     311        exit( '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
     312
     313    if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) )
     314        exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
    233315
    234316    $comment_id = bp_activity_new_comment( array(
    235317        'activity_id' => $_POST['form_id'],
    236318        'content'     => $_POST['content'],
    237         'parent_id'   => $_POST['comment_id']
     319        'parent_id'   => $_POST['comment_id'],
    238320    ) );
    239321
    240     if ( !$comment_id ) {
    241         echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
    242         return false;
    243     }
    244 
    245     global $activities_template;
     322    if ( ! $comment_id )
     323        exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
    246324
    247325    // Load the new activity item into the $activities_template global
     
    254332    $template = locate_template( 'activity/comment.php', false, false );
    255333
    256     // Backward compatibility. In older versions of BP, the markup was
    257     // generated in the PHP instead of a template. This ensures that
    258     // older themes (which are not children of bp-default and won't
    259     // have the new template) will still work.
     334    /**
     335     * Backward compatibility. In older versions of BP, the markup was
     336     * generated in the PHP instead of a template. This ensures that
     337     * older themes (which are not children of bp-default and won't
     338     * have the new template) will still work.
     339     */
    260340    if ( empty( $template ) )
    261341        $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
     
    264344
    265345    unset( $activities_template );
    266 }
    267 add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
    268 
    269 /* AJAX delete an activity */
     346    exit;
     347}
     348
     349/**
     350 * Deletes an Activity item received via a POST request.
     351 *
     352 * @return mixed String on error, void on success
     353 * @since BuddyPress (1.2)
     354 */
    270355function bp_dtheme_delete_activity() {
    271 
    272356    // Bail if not a POST action
    273357    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    277361    check_admin_referer( 'bp_activity_delete_link' );
    278362
    279     if ( !is_user_logged_in() ) {
    280         echo '-1';
    281         return false;
    282     }
    283 
    284     if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) ) {
    285         echo '-1';
    286         return false;
    287     }
     363    if ( ! is_user_logged_in() )
     364        exit( '-1' );
     365
     366    if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     367        exit( '-1' );
    288368
    289369    $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    290370
    291371    // Check access
    292     if ( empty( $activity->user_id ) || !bp_activity_user_can_delete( $activity ) ) {
    293         echo '-1';
    294         return false;
    295     }
     372    if ( empty( $activity->user_id ) || ! bp_activity_user_can_delete( $activity ) )
     373        exit( '-1' );
    296374
    297375    // Call the action before the delete so plugins can still fetch information about it
    298376    do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
    299377
    300     if ( !bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
    301         echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
    302         return false;
    303     }
     378    if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) )
     379        exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
    304380
    305381    do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
    306 
    307     return true;
    308 }
    309 add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' );
    310 
    311 /* AJAX delete an activity comment */
     382    exit;
     383}
     384
     385/**
     386 * Deletes an Activity comment received via a POST request
     387 *
     388 * @return mixed String on error, void on success
     389 * @since BuddyPress (1.2)
     390 */
    312391function bp_dtheme_delete_activity_comment() {
    313 
    314392    // Bail if not a POST action
    315393    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    319397    check_admin_referer( 'bp_activity_delete_link' );
    320398
    321     if ( !is_user_logged_in() ) {
    322         echo '-1';
    323         return false;
    324     }
     399    if ( ! is_user_logged_in() )
     400        exit( '-1' );
    325401
    326402    $comment = new BP_Activity_Activity( $_POST['id'] );
    327403
    328     /* Check access */
    329     if ( !bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
    330         return false;
    331 
    332     if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) )
    333         return false;
    334 
    335     /* Call the action before the delete so plugins can still fetch information about it */
     404    // Check access
     405    if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
     406        exit( '-1' );
     407
     408    if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     409        exit( '-1' );
     410
     411    // Call the action before the delete so plugins can still fetch information about it
    336412    do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id );
    337413
    338     if ( !bp_activity_delete_comment( $comment->item_id, $comment->id ) ) {
    339         echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
    340         return false;
    341     }
     414    if ( ! bp_activity_delete_comment( $comment->item_id, $comment->id ) )
     415        exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
    342416
    343417    do_action( 'bp_activity_action_delete_activity', $_POST['id'], $comment->user_id );
    344 
    345     return true;
    346 }
    347 add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
    348 
    349 /**
    350  * AJAX spam an activity item or an activity comment
    351  *
    352  * @global object $bp BuddyPress global settings
    353  * @since 1.6
     418    exit;
     419}
     420
     421/**
     422 * AJAX spam an activity item or comment
     423 *
     424 * @global BuddyPress $bp The one true BuddyPress instance
     425 * @return mixed String on error, void on success
     426 * @since BuddyPress (1.6)
    354427 */
    355428function bp_dtheme_spam_activity() {
     
    361434
    362435    // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
    363     if ( !is_user_logged_in() || !bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) ) {
    364         echo '-1';
    365         return false;
    366     }
     436    if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
     437        exit( '-1' );
    367438
    368439    // Check an item ID was passed
    369     if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) ) {
    370         echo '-1';
    371         return false;
    372     }
     440    if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     441        exit( '-1' );
    373442
    374443    // Is the current user allowed to spam items?
    375     if ( !bp_activity_user_can_mark_spam() )
    376         return false;
     444    if ( ! bp_activity_user_can_mark_spam() )
     445        exit( '-1' );
    377446
    378447    // Load up the activity item
    379448    $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    380     if ( empty( $activity->component ) ) {
    381         echo '-1';
    382         return false;
    383     }
     449    if ( empty( $activity->component ) )
     450        exit( '-1' );
    384451
    385452    // Check nonce
     
    394461
    395462    do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
    396     return true;
    397 }
    398 add_action( 'wp_ajax_spam_activity',         'bp_dtheme_spam_activity' );
    399 add_action( 'wp_ajax_spam_activity_comment', 'bp_dtheme_spam_activity' );
    400 
    401 /* AJAX mark an activity as a favorite */
     463    exit;
     464}
     465
     466/**
     467 * Mark an activity as a favourite via a POST request.
     468 *
     469 * @return string HTML
     470 * @since BuddyPress (1.2)
     471 */
    402472function bp_dtheme_mark_activity_favorite() {
    403 
    404473    // Bail if not a POST action
    405474    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    407476
    408477    bp_activity_add_user_favorite( $_POST['id'] );
    409     _e( 'Remove Favorite', 'buddypress' );
    410 }
    411 add_action( 'wp_ajax_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
    412 
    413 /* AJAX mark an activity as not a favorite */
     478    exit( __( 'Remove Favorite', 'buddypress' ) );
     479}
     480
     481/**
     482 * Un-favourite an activity via a POST request.
     483 *
     484 * @return string HTML
     485 * @since BuddyPress (1.2)
     486 */
    414487function bp_dtheme_unmark_activity_favorite() {
    415 
    416488    // Bail if not a POST action
    417489    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    419491
    420492    bp_activity_remove_user_favorite( $_POST['id'] );
    421     _e( 'Favorite', 'buddypress' );
    422 }
    423 add_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
    424 
    425 /**
    426  * AJAX handler for Read More link on long activity items
    427  *
    428  * @package BuddyPress
     493    exit( __( 'Favorite', 'buddypress' ) );
     494}
     495
     496/**
     497 * Fetches full an activity's full, non-excerpted content via a POST request.
     498 * Used for the 'Read More' link on long activity items.
     499 *
     500 * @return string HTML
    429501 * @since BuddyPress (1.5)
    430502 */
     
    439511    ) );
    440512
    441     $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
     513    $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
    442514
    443515    if ( empty( $activity ) )
    444         exit(); // todo: error?
     516        exit; // @todo: error?
    445517
    446518    do_action_ref_array( 'bp_dtheme_get_single_activity_content', array( &$activity ) );
     
    450522    $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
    451523
    452     echo $content;
    453     exit();
    454 }
    455 add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
    456 
    457 /* AJAX invite a friend to a group functionality */
     524    exit( $content );
     525}
     526
     527/**
     528 * Invites a friend to join a group via a POST request.
     529 *
     530 * @return unknown
     531 * @since BuddyPress (1.2)
     532 * @todo Audit return types
     533 */
    458534function bp_dtheme_ajax_invite_user() {
    459 
    460535    // Bail if not a POST action
    461536    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    464539    check_ajax_referer( 'groups_invite_uninvite_user' );
    465540
    466     if ( !$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id'] )
    467         return false;
    468 
    469     if ( !bp_groups_user_can_send_invites( $_POST['group_id'] ) )
    470         return false;
    471 
    472     if ( !friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) )
    473         return false;
     541    if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
     542        return;
     543
     544    if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
     545        return;
     546
     547    if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) )
     548        return;
    474549
    475550    if ( 'invite' == $_POST['friend_action'] ) {
    476 
    477         if ( !groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
    478             return false;
     551        if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
     552            return;
    479553
    480554        $user = new BP_Core_User( $_POST['friend_id'] );
     
    488562              </div>';
    489563        echo '</li>';
    490 
    491     } else if ( 'uninvite' == $_POST['friend_action'] ) {
    492 
    493         if ( !groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
    494             return false;
    495 
    496         return true;
     564        exit;
     565
     566    } elseif ( 'uninvite' == $_POST['friend_action'] ) {
     567        if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
     568            return;
     569
     570        exit;
    497571
    498572    } else {
    499         return false;
    500     }
    501 }
    502 add_action( 'wp_ajax_groups_invite_user', 'bp_dtheme_ajax_invite_user' );
    503 
    504 /* AJAX add/remove a user as a friend when clicking the button */
     573        return;
     574    }
     575}
     576
     577/**
     578 * Friend/un-friend a user via a POST request.
     579 *
     580 * @return string HTML
     581 * @since BuddyPress (1.2)
     582 */
    505583function bp_dtheme_ajax_addremove_friend() {
    506 
    507584    // Bail if not a POST action
    508585    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    510587
    511588    if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    512 
    513         check_ajax_referer('friends_remove_friend');
    514 
    515         if ( !friends_remove_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    516             echo __("Friendship could not be canceled.", 'buddypress');
    517         } else {
     589        check_ajax_referer( 'friends_remove_friend' );
     590
     591        if ( ! friends_remove_friend( bp_loggedin_user_id(), $_POST['fid'] ) )
     592            echo __( 'Friendship could not be canceled.', 'buddypress' );
     593        else
    518594            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    519         }
    520 
    521     } else if ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    522 
    523         check_ajax_referer('friends_add_friend');
    524 
    525         if ( !friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    526             echo __("Friendship could not be requested.", 'buddypress');
    527         } else {
    528             echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int)$_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
    529         }
    530     } else if( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
    531        
    532         check_ajax_referer('friends_withdraw_friendship');
    533        
    534         if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
     595
     596    } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
     597        check_ajax_referer( 'friends_add_friend' );
     598
     599        if ( ! friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) )
     600            echo __(' Friendship could not be requested.', 'buddypress' );
     601        else
     602            echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int) $_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
     603
     604    } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int) $_POST['fid'] ) ) {       
     605        check_ajax_referer( 'friends_withdraw_friendship' );
     606
     607        if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int) $_POST['fid'] ) )
    535608            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    536         } else {
     609        else
    537610            echo __("Friendship request could not be cancelled.", 'buddypress');
    538         }
     611
    539612    } else {
    540613        echo __( 'Request Pending', 'buddypress' );
    541614    }
    542615
    543     return false;
    544 }
    545 add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );
    546 
    547 /* AJAX accept a user as a friend when clicking the "accept" button */
     616    exit;
     617}
     618
     619/**
     620 * Accept a user friendship request via a POST request.
     621 *
     622 * @return mixed String on error, void on success
     623 * @since BuddyPress (1.2)
     624 */
    548625function bp_dtheme_ajax_accept_friendship() {
    549 
    550626    // Bail if not a POST action
    551627    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    554630    check_admin_referer( 'friends_accept_friendship' );
    555631
    556     if ( !friends_accept_friendship( $_POST['id'] ) )
     632    if ( ! friends_accept_friendship( $_POST['id'] ) )
    557633        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
    558634
    559     return true;
    560 }
    561 add_action( 'wp_ajax_accept_friendship', 'bp_dtheme_ajax_accept_friendship' );
    562 
    563 /* AJAX reject a user as a friend when clicking the "reject" button */
     635    exit;
     636}
     637
     638/**
     639 * Reject a user friendship request via a POST request.
     640 *
     641 * @return mixed String on error, void on success
     642 * @since BuddyPress (1.2)
     643 */
    564644function bp_dtheme_ajax_reject_friendship() {
    565645    // Bail if not a POST action
     
    569649    check_admin_referer( 'friends_reject_friendship' );
    570650
    571     if ( !friends_reject_friendship( $_POST['id'] ) )
     651    if ( ! friends_reject_friendship( $_POST['id'] ) )
    572652        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
    573653
    574     return true;
    575 }
    576 add_action( 'wp_ajax_reject_friendship', 'bp_dtheme_ajax_reject_friendship' );
    577 
    578 /* AJAX join or leave a group when clicking the "join/leave" button */
     654    exit;
     655}
     656
     657/**
     658 * Join or leave a group when clicking the "join/leave" button via a POST request.
     659 *
     660 * @return string HTML
     661 * @since BuddyPress (1.2)
     662 */
    579663function bp_dtheme_ajax_joinleave_group() {
    580 
    581664    // Bail if not a POST action
    582665    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    584667
    585668    if ( groups_is_user_banned( bp_loggedin_user_id(), $_POST['gid'] ) )
    586         return false;
    587 
    588     if ( !$group = groups_get_group( array( 'group_id' => $_POST['gid'] ) ) )
    589         return false;
    590 
    591     if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    592 
     669        return;
     670
     671    if ( ! $group = groups_get_group( array( 'group_id' => $_POST['gid'] ) ) )
     672        return;
     673
     674    if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    593675        if ( 'public' == $group->status ) {
    594 
    595676            check_ajax_referer( 'groups_join_group' );
    596677
    597             if ( !groups_join_group( $group->id ) ) {
     678            if ( ! groups_join_group( $group->id ) )
    598679                _e( 'Error joining group', 'buddypress' );
    599             } else {
     680            else
    600681                echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
    601             }
    602 
    603         } else if ( 'private' == $group->status ) {
    604 
     682
     683        } elseif ( 'private' == $group->status ) {
    605684            check_ajax_referer( 'groups_request_membership' );
    606685
    607             if ( !groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
     686            if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) )
    608687                _e( 'Error requesting membership', 'buddypress' );
    609             } else {
     688            else
    610689                echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
    611             }
    612690        }
    613691
    614692    } else {
    615 
    616693        check_ajax_referer( 'groups_leave_group' );
    617694
    618         if ( !groups_leave_group( $group->id ) ) {
     695        if ( ! groups_leave_group( $group->id ) )
    619696            _e( 'Error leaving group', 'buddypress' );
    620         } else {
    621             if ( 'public' == $group->status ) {
    622                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="join-group" rel="join" title="' . __( 'Join Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
    623             } else if ( 'private' == $group->status ) {
    624                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="request-membership" rel="join" title="' . __( 'Request Membership', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_send_membership_request' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
    625             }
    626         }
    627     }
    628 }
    629 add_action( 'wp_ajax_joinleave_group', 'bp_dtheme_ajax_joinleave_group' );
    630 
    631 /* AJAX close and keep closed site wide notices from an admin in the sidebar */
     697        elseif ( 'public' == $group->status )
     698            echo '<a id="group-' . esc_attr( $group->id ) . '" class="join-group" rel="join" title="' . __( 'Join Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
     699        elseif ( 'private' == $group->status )
     700            echo '<a id="group-' . esc_attr( $group->id ) . '" class="request-membership" rel="join" title="' . __( 'Request Membership', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_send_membership_request' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
     701    }
     702
     703    exit;
     704}
     705
     706/**
     707 * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
     708 *
     709 * @return mixed String on error, void on success
     710 * @since BuddyPress (1.2)
     711 */
    632712function bp_dtheme_ajax_close_notice() {
    633     global $userdata;
    634 
    635     // Bail if not a POST action
    636     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    637         return;
    638 
    639     if ( !isset( $_POST['notice_id'] ) ) {
    640         echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
     713    // Bail if not a POST action
     714    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     715        return;
     716
     717    if ( ! isset( $_POST['notice_id'] ) ) {
     718        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';
     719
    641720    } else {
    642         $notice_ids = bp_get_user_meta( $userdata->ID, 'closed_notices', true );
    643 
     721        $user_id      = get_current_user_id();
     722        $notice_ids   = bp_get_user_meta( $user_id, 'closed_notices', true );
    644723        $notice_ids[] = (int) $_POST['notice_id'];
    645724
    646         bp_update_user_meta( $userdata->ID, 'closed_notices', $notice_ids );
    647     }
    648 }
    649 add_action( 'wp_ajax_messages_close_notice', 'bp_dtheme_ajax_close_notice' );
    650 
    651 /* AJAX send a private message reply to a thread */
     725        bp_update_user_meta( $user_id, 'closed_notices', $notice_ids );
     726    }
     727
     728    exit;
     729}
     730
     731/**
     732 * Send a private message reply to a thread via a POST request.
     733 *
     734 * @return string HTML
     735 * @since BuddyPress (1.2)
     736 */
    652737function bp_dtheme_ajax_messages_send_reply() {
    653     global $bp;
    654 
    655738    // Bail if not a POST action
    656739    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    667750                <?php echo bp_loggedin_user_avatar( 'type=thumb&width=30&height=30' ); ?>
    668751
    669                 <strong><a href="<?php echo bp_loggedin_user_domain(); ?>"><?php echo $bp->loggedin_user->fullname ?></a> <span class="activity"><?php printf( __( 'Sent %s', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ); ?></span></strong>
     752                <strong><a href="<?php echo bp_loggedin_user_domain(); ?>"><?php bp_loggedin_user_fullname(); ?></a> <span class="activity"><?php printf( __( 'Sent %s', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ); ?></span></strong>
    670753
    671754                <?php do_action( 'bp_after_message_meta' ); ?>
     
    686769        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
    687770    }
    688 }
    689 add_action( 'wp_ajax_messages_send_reply', 'bp_dtheme_ajax_messages_send_reply' );
    690 
    691 /* AJAX mark a private message as unread in your inbox */
     771
     772    exit;
     773}
     774
     775/**
     776 * Mark a private message as unread in your inbox via a POST request.
     777 *
     778 * @return mixed String on error, void on success
     779 * @since BuddyPress (1.2)
     780 */
    692781function bp_dtheme_ajax_message_markunread() {
    693 
    694     // Bail if not a POST action
    695     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    696         return;
    697 
    698     if ( !isset($_POST['thread_ids']) ) {
    699         echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as unread.', 'buddypress' ) . '</p></div>';
     782    // Bail if not a POST action
     783    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     784        return;
     785
     786    if ( ! isset($_POST['thread_ids']) ) {
     787        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem marking messages as unread.', 'buddypress' ) . '</p></div>';
     788
    700789    } else {
    701790        $thread_ids = explode( ',', $_POST['thread_ids'] );
     
    705794        }
    706795    }
    707 }
    708 add_action( 'wp_ajax_messages_markunread', 'bp_dtheme_ajax_message_markunread' );
    709 
    710 /* AJAX mark a private message as read in your inbox */
     796
     797    exit;
     798}
     799
     800/**
     801 * Mark a private message as read in your inbox via a POST request.
     802 *
     803 * @return mixed String on error, void on success
     804 * @since BuddyPress (1.2)
     805 */
    711806function bp_dtheme_ajax_message_markread() {
    712 
    713     // Bail if not a POST action
    714     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    715         return;
    716 
    717     if ( !isset($_POST['thread_ids']) ) {
     807    // Bail if not a POST action
     808    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     809        return;
     810
     811    if ( ! isset($_POST['thread_ids']) ) {
    718812        echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as read.', 'buddypress' ) . '</p></div>';
     813
    719814    } else {
    720815        $thread_ids = explode( ',', $_POST['thread_ids'] );
     
    724819        }
    725820    }
    726 }
    727 add_action( 'wp_ajax_messages_markread', 'bp_dtheme_ajax_message_markread' );
    728 
    729 /* AJAX delete a private message or array of messages in your inbox */
     821
     822    exit;
     823}
     824
     825/**
     826 * Delete a private message(s) in your inbox via a POST request.
     827 *
     828 * @return string HTML
     829 * @since BuddyPress (1.2)
     830 */
    730831function bp_dtheme_ajax_messages_delete() {
    731 
    732     // Bail if not a POST action
    733     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    734         return;
    735 
    736     if ( !isset($_POST['thread_ids']) ) {
     832    // Bail if not a POST action
     833    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     834        return;
     835
     836    if ( ! isset($_POST['thread_ids']) ) {
    737837        echo "-1<div id='message' class='error'><p>" . __( 'There was a problem deleting messages.', 'buddypress' ) . '</p></div>';
     838
    738839    } else {
    739840        $thread_ids = explode( ',', $_POST['thread_ids'] );
     
    744845        _e( 'Messages deleted.', 'buddypress' );
    745846    }
    746 }
    747 add_action( 'wp_ajax_messages_delete', 'bp_dtheme_ajax_messages_delete' );
    748 
    749 /**
    750  * bp_dtheme_ajax_messages_autocomplete_results()
    751  *
    752  * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined
    753  *
    754  * @global object object $bp Global BuddyPress settings object
    755  * @return none
     847
     848    exit;
     849}
     850
     851/**
     852 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
     853 *
     854 * @global BuddyPress $bp The one true BuddyPress instance
     855 * @return string HTML
     856 * @since BuddyPress (1.2)
    756857 */
    757858function bp_dtheme_ajax_messages_autocomplete_results() {
     
    763864
    764865    $pag_page = 1;
    765 
    766     $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
     866    $limit    = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
    767867
    768868    // Get the user ids based on the search terms
    769     if ( !empty( $autocomplete_all ) ) {
     869    if ( ! empty( $autocomplete_all ) ) {
    770870        $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page );
    771871
    772         if ( !empty( $users['users'] ) ) {
     872        if ( ! empty( $users['users'] ) ) {
    773873            // Build an array with the correct format
    774874            $user_ids = array();
     
    780880            $user_ids = apply_filters( 'bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit );
    781881        }
     882
    782883    } else {
    783884        if ( bp_is_active( 'friends' ) ) {
     
    787888            $users = apply_filters( 'bp_friends_autocomplete_list', $users, $_GET['q'], $limit );
    788889
    789             if ( !empty( $users['friends'] ) )
     890            if ( ! empty( $users['friends'] ) )
    790891                $user_ids = apply_filters( 'bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit );
    791892        }
    792893    }
    793894
    794     if ( !empty( $user_ids ) ) {
     895    if ( ! empty( $user_ids ) ) {
    795896        foreach ( $user_ids as $user_id ) {
    796897            $ud = get_userdata( $user_id );
    797             if ( !$ud )
     898            if ( ! $ud )
    798899                continue;
    799900
     
    803904                $username = $ud->user_nicename;
    804905
    805             echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain( $user_id ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name ) ) . ' &nbsp;' . bp_core_get_user_displayname( $user_id ) . ' (' . $username . ')
    806             ';
     906            echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain( $user_id ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name ) ) . ' &nbsp;' . bp_core_get_user_displayname( $user_id ) . ' (' . $username . ')';
    807907        }
    808908    }
    809 }
    810 add_action( 'wp_ajax_messages_autocomplete_results', 'bp_dtheme_ajax_messages_autocomplete_results' );
    811 
     909
     910    exit;
     911}
    812912?>
  • trunk/bp-themes/bp-default/_inc/global.js

    r5998 r6003  
    273273
    274274            jq.post( ajaxurl, {
    275                 action: 'spam_activity',
     275                action: 'bp_spam_activity',
    276276                'cookie': encodeURIComponent( document.cookie ),
    277277                'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
     
    535535
    536536            jq.post( ajaxurl, {
    537                 action: 'spam_activity_comment',
     537                action: 'bp_spam_activity_comment',
    538538                'cookie': encodeURIComponent( document.cookie ),
    539539                '_wpnonce': link_href.split( '_wpnonce=' )[1],
Note: See TracChangeset for help on using the changeset viewer.