Changeset 6003
- Timestamp:
- 04/21/2012 05:26:22 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-cssjs.php
r5996 r6003 130 130 * Adds AJAX target URL so themes can access the WordPress AJAX functionality. 131 131 * 132 * @ package BuddyPress Core132 * @since 1.1 133 133 */ 134 134 function bp_core_add_ajax_url_js() { 135 135 ?> 136 136 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> 138 138 139 139 <?php -
trunk/bp-core/bp-core-functions.php
r5993 r6003 699 699 } 700 700 add_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-admin704 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 );708 701 709 702 /** -
trunk/bp-core/deprecated/1.6.php
r5808 r6003 54 54 */ 55 55 56 /* 56 /** 57 57 * @deprecated 1.6 58 58 * @deprecated No longer used; see bp_blogs_transition_activity_status() … … 66 66 */ 67 67 68 /* 68 /** 69 69 * @deprecated 1.6 70 70 * @deprecated No longer used; see BP_Admin::admin_menus() … … 74 74 } 75 75 76 /** 77 * @deprecated 1.6 78 * @deprecated No longer used. We do ajax properly now. 79 */ 80 function bp_core_add_ajax_hook() { 81 _deprecated_function( __FUNCTION__, '1.6', 'No longer used' ); 82 } 76 83 77 84 /** … … 125 132 return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] ); 126 133 } 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 */ 152 if ( !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 ); 202 endif; 127 203 ?> -
trunk/bp-themes/bp-default/_inc/ajax.php
r5931 r6003 1 1 <?php 2 3 /*** 2 /** 4 3 * AJAX Functions 5 4 * 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 17 if ( ! 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 */ 27 function 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 } 78 add_action( 'after_setup_theme', 'bp_dtheme_register_actions', 20 ); 79 80 /** 11 81 * This function looks scarier than it actually is. :) 12 82 * Each object loop (activity/members/groups/blogs/forums) contains default parameters to … … 15 85 * to override the parameters sent. That way we can change the results returned without reloading the page. 16 86 * 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) 17 90 */ 18 91 function bp_dtheme_ajax_querystring( $query_string, $object ) { 19 global $bp;20 21 92 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'] ) ) 26 97 $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) ); 27 98 else 28 99 $_BP_COOKIE = &$_COOKIE; 29 100 30 $qs = false;31 32 /** *101 $qs = array(); 102 103 /** 33 104 * Check if any cookie values are set. If there are then override the default params passed to the 34 105 * template loop 35 106 */ 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'] ) ) { 42 115 if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) { 43 116 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 44 117 $qs[] = 'user_id=' . $user_id; 45 118 } 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'] ) 52 127 $qs[] = 'page=' . $_POST['page']; 53 128 54 129 $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'] ) 56 131 $qs[] = 'search_terms=' . $_POST['search_terms']; 57 132 58 / * Now pass the querystring to override default values. */133 // Now pass the querystring to override default values. 59 134 $query_string = empty( $qs ) ? '' : join( '&', (array) $qs ); 60 135 … … 83 158 add_filter( 'bp_ajax_querystring', 'bp_dtheme_ajax_querystring', 10, 2 ); 84 159 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 */ 86 166 function bp_dtheme_object_template_loader() { 87 88 167 // Bail if not a POST action 89 168 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 96 175 * of themselves rather than the directory version. 97 176 */ 98 if ( !bp_current_action() ) 177 178 if ( ! bp_current_action() ) 99 179 bp_update_is_directory( true, bp_current_component() ); 100 180 … … 104 184 // Locate the object template 105 185 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 */ 117 195 function 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 */ 122 206 function bp_dtheme_activity_template_loader() { 123 124 207 // Bail if not a POST action 125 208 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 127 210 128 211 $scope = ''; 129 if ( ! empty( $_POST['scope'] ) )212 if ( ! empty( $_POST['scope'] ) ) 130 213 $scope = $_POST['scope']; 131 214 … … 150 233 } 151 234 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. 153 236 ob_start(); 154 237 locate_template( array( 'activity/activity-loop.php' ), true ); … … 157 240 ob_end_clean(); 158 241 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 */ 165 251 function bp_dtheme_post_update() { 166 167 252 // Bail if not a POST action 168 253 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 172 257 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 173 258 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>' ); 183 264 184 265 $activity_id = 0; … … 187 268 188 269 } elseif ( $_POST['object'] == 'groups' ) { 189 if ( ! empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )270 if ( ! empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) ) 190 271 $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) ); 191 272 … … 194 275 } 195 276 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 */ 210 297 function bp_dtheme_new_activity_comment() { 298 global $activities_template; 211 299 212 300 // Bail if not a POST action … … 217 305 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 218 306 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>' ); 233 315 234 316 $comment_id = bp_activity_new_comment( array( 235 317 'activity_id' => $_POST['form_id'], 236 318 'content' => $_POST['content'], 237 'parent_id' => $_POST['comment_id'] 319 'parent_id' => $_POST['comment_id'], 238 320 ) ); 239 321 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>' ); 246 324 247 325 // Load the new activity item into the $activities_template global … … 254 332 $template = locate_template( 'activity/comment.php', false, false ); 255 333 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 */ 260 340 if ( empty( $template ) ) 261 341 $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php'; … … 264 344 265 345 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 */ 270 355 function bp_dtheme_delete_activity() { 271 272 356 // Bail if not a POST action 273 357 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 277 361 check_admin_referer( 'bp_activity_delete_link' ); 278 362 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' ); 288 368 289 369 $activity = new BP_Activity_Activity( (int) $_POST['id'] ); 290 370 291 371 // 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' ); 296 374 297 375 // Call the action before the delete so plugins can still fetch information about it 298 376 do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id ); 299 377 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>' ); 304 380 305 381 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 */ 312 391 function bp_dtheme_delete_activity_comment() { 313 314 392 // Bail if not a POST action 315 393 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 319 397 check_admin_referer( 'bp_activity_delete_link' ); 320 398 321 if ( !is_user_logged_in() ) { 322 echo '-1'; 323 return false; 324 } 399 if ( ! is_user_logged_in() ) 400 exit( '-1' ); 325 401 326 402 $comment = new BP_Activity_Activity( $_POST['id'] ); 327 403 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 336 412 do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id ); 337 413 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>' ); 342 416 343 417 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) 354 427 */ 355 428 function bp_dtheme_spam_activity() { … … 361 434 362 435 // 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' ); 367 438 368 439 // 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' ); 373 442 374 443 // 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' ); 377 446 378 447 // Load up the activity item 379 448 $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' ); 384 451 385 452 // Check nonce … … 394 461 395 462 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 */ 402 472 function bp_dtheme_mark_activity_favorite() { 403 404 473 // Bail if not a POST action 405 474 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 407 476 408 477 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 */ 414 487 function bp_dtheme_unmark_activity_favorite() { 415 416 488 // Bail if not a POST action 417 489 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 419 491 420 492 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 items427 * 428 * @ package BuddyPress493 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 429 501 * @since BuddyPress (1.5) 430 502 */ … … 439 511 ) ); 440 512 441 $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;513 $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false; 442 514 443 515 if ( empty( $activity ) ) 444 exit (); //todo: error?516 exit; // @todo: error? 445 517 446 518 do_action_ref_array( 'bp_dtheme_get_single_activity_content', array( &$activity ) ); … … 450 522 $content = apply_filters( 'bp_get_activity_content_body', $activity->content ); 451 523 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 */ 458 534 function bp_dtheme_ajax_invite_user() { 459 460 535 // Bail if not a POST action 461 536 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 464 539 check_ajax_referer( 'groups_invite_uninvite_user' ); 465 540 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; 474 549 475 550 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; 479 553 480 554 $user = new BP_Core_User( $_POST['friend_id'] ); … … 488 562 </div>'; 489 563 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; 497 571 498 572 } 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 */ 505 583 function bp_dtheme_ajax_addremove_friend() { 506 507 584 // Bail if not a POST action 508 585 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 510 587 511 588 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 518 594 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'] ) ) 535 608 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 537 610 echo __("Friendship request could not be cancelled.", 'buddypress'); 538 } 611 539 612 } else { 540 613 echo __( 'Request Pending', 'buddypress' ); 541 614 } 542 615 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 */ 548 625 function bp_dtheme_ajax_accept_friendship() { 549 550 626 // Bail if not a POST action 551 627 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 554 630 check_admin_referer( 'friends_accept_friendship' ); 555 631 556 if ( ! friends_accept_friendship( $_POST['id'] ) )632 if ( ! friends_accept_friendship( $_POST['id'] ) ) 557 633 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>'; 558 634 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 */ 564 644 function bp_dtheme_ajax_reject_friendship() { 565 645 // Bail if not a POST action … … 569 649 check_admin_referer( 'friends_reject_friendship' ); 570 650 571 if ( ! friends_reject_friendship( $_POST['id'] ) )651 if ( ! friends_reject_friendship( $_POST['id'] ) ) 572 652 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>'; 573 653 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 */ 579 663 function bp_dtheme_ajax_joinleave_group() { 580 581 664 // Bail if not a POST action 582 665 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 584 667 585 668 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 ) ) { 593 675 if ( 'public' == $group->status ) { 594 595 676 check_ajax_referer( 'groups_join_group' ); 596 677 597 if ( ! groups_join_group( $group->id ) ) {678 if ( ! groups_join_group( $group->id ) ) 598 679 _e( 'Error joining group', 'buddypress' ); 599 } else {680 else 600 681 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 ) { 605 684 check_ajax_referer( 'groups_request_membership' ); 606 685 607 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {686 if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) 608 687 _e( 'Error requesting membership', 'buddypress' ); 609 } else {688 else 610 689 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 }612 690 } 613 691 614 692 } else { 615 616 693 check_ajax_referer( 'groups_leave_group' ); 617 694 618 if ( ! groups_leave_group( $group->id ) ) {695 if ( ! groups_leave_group( $group->id ) ) 619 696 _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 */ 632 712 function 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 641 720 } 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 ); 644 723 $notice_ids[] = (int) $_POST['notice_id']; 645 724 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 */ 652 737 function bp_dtheme_ajax_messages_send_reply() { 653 global $bp;654 655 738 // Bail if not a POST action 656 739 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) … … 667 750 <?php echo bp_loggedin_user_avatar( 'type=thumb&width=30&height=30' ); ?> 668 751 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> 670 753 671 754 <?php do_action( 'bp_after_message_meta' ); ?> … … 686 769 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>'; 687 770 } 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 */ 692 781 function bp_dtheme_ajax_message_markunread() { 693 694 // Bail if not a POST action695 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 700 789 } else { 701 790 $thread_ids = explode( ',', $_POST['thread_ids'] ); … … 705 794 } 706 795 } 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 */ 711 806 function 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']) ) { 718 812 echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as read.', 'buddypress' ) . '</p></div>'; 813 719 814 } else { 720 815 $thread_ids = explode( ',', $_POST['thread_ids'] ); … … 724 819 } 725 820 } 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 */ 730 831 function 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']) ) { 737 837 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem deleting messages.', 'buddypress' ) . '</p></div>'; 838 738 839 } else { 739 840 $thread_ids = explode( ',', $_POST['thread_ids'] ); … … 744 845 _e( 'Messages deleted.', 'buddypress' ); 745 846 } 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 defined753 * 754 * @ global object object $bp Global BuddyPress settings object755 * @ return none847 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) 756 857 */ 757 858 function bp_dtheme_ajax_messages_autocomplete_results() { … … 763 864 764 865 $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 ); 767 867 768 868 // Get the user ids based on the search terms 769 if ( ! empty( $autocomplete_all ) ) {869 if ( ! empty( $autocomplete_all ) ) { 770 870 $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page ); 771 871 772 if ( ! empty( $users['users'] ) ) {872 if ( ! empty( $users['users'] ) ) { 773 873 // Build an array with the correct format 774 874 $user_ids = array(); … … 780 880 $user_ids = apply_filters( 'bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit ); 781 881 } 882 782 883 } else { 783 884 if ( bp_is_active( 'friends' ) ) { … … 787 888 $users = apply_filters( 'bp_friends_autocomplete_list', $users, $_GET['q'], $limit ); 788 889 789 if ( ! empty( $users['friends'] ) )890 if ( ! empty( $users['friends'] ) ) 790 891 $user_ids = apply_filters( 'bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit ); 791 892 } 792 893 } 793 894 794 if ( ! empty( $user_ids ) ) {895 if ( ! empty( $user_ids ) ) { 795 896 foreach ( $user_ids as $user_id ) { 796 897 $ud = get_userdata( $user_id ); 797 if ( ! $ud )898 if ( ! $ud ) 798 899 continue; 799 900 … … 803 904 $username = $ud->user_nicename; 804 905 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 ) ) . ' ' . 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 ) ) . ' ' . bp_core_get_user_displayname( $user_id ) . ' (' . $username . ')'; 807 907 } 808 908 } 809 } 810 add_action( 'wp_ajax_messages_autocomplete_results', 'bp_dtheme_ajax_messages_autocomplete_results' );811 909 910 exit; 911 } 812 912 ?> -
trunk/bp-themes/bp-default/_inc/global.js
r5998 r6003 273 273 274 274 jq.post( ajaxurl, { 275 action: ' spam_activity',275 action: 'bp_spam_activity', 276 276 'cookie': encodeURIComponent( document.cookie ), 277 277 'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ), … … 535 535 536 536 jq.post( ajaxurl, { 537 action: ' spam_activity_comment',537 action: 'bp_spam_activity_comment', 538 538 'cookie': encodeURIComponent( document.cookie ), 539 539 '_wpnonce': link_href.split( '_wpnonce=' )[1],
Note: See TracChangeset
for help on using the changeset viewer.