BuddyPress - Version 2.3.0-beta1

Version Description

= 2.2.3.1 = See: https://codex.buddypress.org/releases/version-2-2-3-1/

= 2.2.3 = See: https://codex.buddypress.org/releases/version-2-2-3/

= 2.2.2.1 = See: https://codex.buddypress.org/releases/version-2-2-2-1/

= 2.2.2 = See: https://codex.buddypress.org/releases/version-2-2-2/

= 2.2.1 = See: https://codex.buddypress.org/releases/version-2-2-1/

= 2.2 = See: https://codex.buddypress.org/releases/version-2-2/

= 2.1 = See: https://codex.buddypress.org/releases/version-2-1/

= 2.0.3 = See: https://codex.buddypress.org/releases/version-2-0-3/

= 2.0.2 = See: https://codex.buddypress.org/releases/version-2-0-2/

= 2.0.1 = See: https://codex.buddypress.org/releases/version-2-0-1/

= 2.0 = See: https://codex.buddypress.org/releases/version-2-0/

= 1.9.2 = See: https://codex.buddypress.org/releases/version-1-9-2/

= 1.9.1 = See: https://codex.buddypress.org/releases/version-1-9-1/

= 1.9 = See: https://codex.buddypress.org/releases/version-1-9/

= 1.8.1 = See: https://codex.buddypress.org/releases/version-1-8-1/

= 1.8 = See: https://codex.buddypress.org/releases/version-1-8/

= 1.7.3 = See: https://codex.buddypress.org/releases/version-1-7-3/

= 1.7.2 = See: https://codex.buddypress.org/releases/version-1-7-2/

= 1.7.1 = See: https://codex.buddypress.org/releases/version-1-7-1/

= 1.7 = See: https://codex.buddypress.org/releases/version-1-7/

= 1.6.5 = See: https://codex.buddypress.org/releases/version-1-6-5/

= 1.6.4 = See: https://codex.buddypress.org/releases/version-1-6-4/

= 1.6.3 = See: https://codex.buddypress.org/releases/version-1-6-3/

= 1.6.2 = Compatibility with WordPress 3.5

= 1.6.1 = Fixes 4 bugs

= 1.6 = See: https://codex.buddypress.org/releases/version-1-6/

= 1.5 = See: https://codex.buddypress.org/releases/version-1-5/

= 1.2.9 = Compatibility with WordPress 3.2

= 1.2.8 = Compatibility with WordPress 3.1

= 1.2.7 = Fixes over 10 bugs.

Download this release

Release Info

Developer johnjamesjacoby
Plugin Icon 128x128 BuddyPress
Version 2.3.0-beta1
Comparing to
See all releases

Code changes from version 2.2.3.1 to 2.3.0-beta1

Files changed (73) hide show
  1. bp-activity/admin/js/admin.min.js +1 -1
  2. bp-activity/bp-activity-actions.php +41 -36
  3. bp-activity/bp-activity-admin.php +35 -32
  4. bp-activity/bp-activity-akismet.php +74 -64
  5. bp-activity/bp-activity-cache.php +6 -6
  6. bp-activity/bp-activity-classes.php +3 -2379
  7. bp-activity/bp-activity-cssjs.php +2 -2
  8. bp-activity/bp-activity-filters.php +50 -23
  9. bp-activity/bp-activity-functions.php +416 -216
  10. bp-activity/bp-activity-loader.php +32 -29
  11. bp-activity/bp-activity-notifications.php +69 -63
  12. bp-activity/bp-activity-screens.php +14 -13
  13. bp-activity/bp-activity-template.php +507 -341
  14. bp-activity/classes/class-bp-activity-activity.php +1800 -0
  15. bp-activity/classes/class-bp-activity-feed.php +446 -0
  16. bp-activity/classes/class-bp-activity-query.php +258 -0
  17. bp-activity/js/mentions.min.js +1 -1
  18. bp-blogs/bp-blogs-activity.php +6 -12
  19. bp-blogs/bp-blogs-classes.php +1 -564
  20. bp-blogs/bp-blogs-filters.php +6 -4
  21. bp-blogs/bp-blogs-functions.php +44 -22
  22. bp-blogs/bp-blogs-loader.php +26 -6
  23. bp-blogs/bp-blogs-template.php +31 -17
  24. bp-blogs/bp-blogs-widgets.php +45 -29
  25. bp-blogs/classes/class-bp-blogs-blog.php +608 -0
  26. bp-core/admin/{bp-core-actions.php → bp-core-admin-actions.php} +92 -29
  27. bp-core/admin/{bp-core-components.php → bp-core-admin-components.php} +29 -9
  28. bp-core/admin/{bp-core-functions.php → bp-core-admin-functions.php} +48 -27
  29. bp-core/admin/{bp-core-schema.php → bp-core-admin-schema.php} +19 -6
  30. bp-core/admin/{bp-core-settings.php → bp-core-admin-settings.php} +52 -25
  31. bp-core/admin/{bp-core-slugs.php → bp-core-admin-slugs.php} +36 -6
  32. bp-core/admin/{bp-core-tools.php → bp-core-admin-tools.php} +21 -3
  33. bp-core/bp-core-actions.php +1 -0
  34. bp-core/bp-core-admin.php +50 -49
  35. bp-core/bp-core-attachments.php +406 -0
  36. bp-core/bp-core-avatars.php +815 -181
  37. bp-core/bp-core-buddybar.php +43 -25
  38. bp-core/bp-core-cache.php +6 -0
  39. bp-core/bp-core-caps.php +64 -2
  40. bp-core/bp-core-catchuri.php +158 -33
  41. bp-core/bp-core-classes.php +14 -2965
  42. bp-core/bp-core-component.php +224 -47
  43. bp-core/bp-core-cssjs.php +91 -16
  44. bp-core/bp-core-dependency.php +266 -10
  45. bp-core/bp-core-filters.php +150 -6
  46. bp-core/bp-core-functions.php +423 -15
  47. bp-core/bp-core-loader.php +65 -9
  48. bp-core/bp-core-moderation.php +43 -2
  49. bp-core/bp-core-options.php +215 -6
  50. bp-core/bp-core-taxonomy.php +28 -0
  51. bp-core/bp-core-template-loader.php +90 -4
  52. bp-core/bp-core-template.php +493 -41
  53. bp-core/bp-core-theme-compatibility.php +78 -8
  54. bp-core/bp-core-update.php +90 -8
  55. bp-core/bp-core-widgets.php +45 -6
  56. bp-core/classes/class-bp-attachment-avatar.php +409 -0
  57. bp-core/classes/class-bp-attachment.php +513 -0
  58. bp-core/classes/class-bp-button.php +270 -0
  59. bp-core/classes/class-bp-core-notification.php +258 -0
  60. bp-core/classes/class-bp-core-user.php +958 -0
  61. bp-core/classes/class-bp-date-query.php +65 -0
  62. bp-core/classes/class-bp-embed.php +248 -0
  63. bp-core/classes/class-bp-media-extractor.php +901 -0
  64. bp-core/classes/class-bp-members-suggestions.php +135 -0
  65. bp-core/classes/class-bp-recursive-query.php +234 -0
  66. bp-core/classes/class-bp-suggestions.php +140 -0
  67. bp-core/classes/class-bp-user-query.php +777 -0
  68. bp-core/classes/class-bp-walker-nav-menu-checklist.php +117 -0
  69. bp-core/classes/class-bp-walker-nav-menu.php +214 -0
  70. bp-core/css/avatar-rtl.css +389 -0
  71. bp-core/css/avatar-rtl.min.css +1 -0
  72. bp-core/css/avatar.css +389 -0
  73. bp-core/css/avatar.min.css +1 -0
bp-activity/admin/js/admin.min.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! buddypress - v2.2.3.1 - 2015-04-21 1:15:07 PM UTC - https://wordpress.org/plugins/buddypress/ */
2
  !function(a){var b={init:function(){a(document).on("click",".row-actions a.reply",b.open),a(document).on("click","#bp-activities-container a.cancel",b.close),a(document).on("click","#bp-activities-container a.save",b.send),a(document).on("keyup","#bp-activities:visible",function(a){27===a.which&&b.close()})},open:function(){var b=a("#bp-activities-container").hide();return a(this).parents("tr").after(b),b.fadeIn("300"),a("#bp-activities").focus(),!1},close:function(){return a("#bp-activities-container").fadeOut("200",function(){a("#bp-activities").val("").blur(),a("#bp-replysubmit .error").html("").hide(),a("#bp-replysubmit .waiting").hide()}),!1},send:function(){a("#bp-replysubmit .error").hide(),a("#bp-replysubmit .waiting").show();var c={};return c["_ajax_nonce-bp-activity-admin-reply"]=a('#bp-activities-container input[name="_ajax_nonce-bp-activity-admin-reply"]').val(),c.action="bp-activity-admin-reply",c.content=a("#bp-activities").val(),c.parent_id=a("#bp-activities-container").prev().data("parent_id"),c.root_id=a("#bp-activities-container").prev().data("root_id"),a.ajax({data:c,type:"POST",url:ajaxurl,error:function(a){b.error(a)},success:function(a){b.show(a)}}),!1},error:function(b){var c=b.statusText;a("#bp-replysubmit .waiting").hide(),b.responseText&&(c=b.responseText.replace(/<.[^<>]*?>/g,"")),c&&a("#bp-replysubmit .error").html(c).show()},show:function(c){var d,e,f;return"string"==typeof c?(b.error({responseText:c}),!1):(f=wpAjax.parseAjaxResponse(c),f.errors?(b.error({responseText:wpAjax.broken}),!1):(f=f.responses[0],void a("#bp-activities-container").fadeOut("200",function(){a("#bp-activities").val("").blur(),a("#bp-replysubmit .error").html("").hide(),a("#bp-replysubmit .waiting").hide(),a("#bp-activities-container").before(f.data),e=a("#activity-"+f.id),d=e.closest(".widefat").css("backgroundColor"),e.animate({backgroundColor:"#CEB"},300).animate({backgroundColor:d},300)})))}};a(document).ready(function(){b.init(),a("#bp_activity_action h3, #bp_activity_content h3").unbind("click"),"undefined"!=typeof postboxes&&postboxes.add_postbox_toggles(bp_activity_admin_vars.page)})}(jQuery);
1
+ /*! buddypress - v2.3.0 - 2015-05-07 1:19:28 PM UTC - https://wordpress.org/plugins/buddypress/ */
2
  !function(a){var b={init:function(){a(document).on("click",".row-actions a.reply",b.open),a(document).on("click","#bp-activities-container a.cancel",b.close),a(document).on("click","#bp-activities-container a.save",b.send),a(document).on("keyup","#bp-activities:visible",function(a){27===a.which&&b.close()})},open:function(){var b=a("#bp-activities-container").hide();return a(this).parents("tr").after(b),b.fadeIn("300"),a("#bp-activities").focus(),!1},close:function(){return a("#bp-activities-container").fadeOut("200",function(){a("#bp-activities").val("").blur(),a("#bp-replysubmit .error").html("").hide(),a("#bp-replysubmit .waiting").hide()}),!1},send:function(){a("#bp-replysubmit .error").hide(),a("#bp-replysubmit .waiting").show();var c={};return c["_ajax_nonce-bp-activity-admin-reply"]=a('#bp-activities-container input[name="_ajax_nonce-bp-activity-admin-reply"]').val(),c.action="bp-activity-admin-reply",c.content=a("#bp-activities").val(),c.parent_id=a("#bp-activities-container").prev().data("parent_id"),c.root_id=a("#bp-activities-container").prev().data("root_id"),a.ajax({data:c,type:"POST",url:ajaxurl,error:function(a){b.error(a)},success:function(a){b.show(a)}}),!1},error:function(b){var c=b.statusText;a("#bp-replysubmit .waiting").hide(),b.responseText&&(c=b.responseText.replace(/<.[^<>]*?>/g,"")),c&&a("#bp-replysubmit .error").html(c).show()},show:function(c){var d,e,f;return"string"==typeof c?(b.error({responseText:c}),!1):(f=wpAjax.parseAjaxResponse(c),f.errors?(b.error({responseText:wpAjax.broken}),!1):(f=f.responses[0],void a("#bp-activities-container").fadeOut("200",function(){a("#bp-activities").val("").blur(),a("#bp-replysubmit .error").html("").hide(),a("#bp-replysubmit .waiting").hide(),a("#bp-activities-container").before(f.data),e=a("#activity-"+f.id),d=e.closest(".widefat").css("backgroundColor"),e.animate({backgroundColor:"#CEB"},300).animate({backgroundColor:d},300)})))}};a(document).ready(function(){b.init(),a("#bp_activity_action h3, #bp_activity_content h3").unbind("click"),"undefined"!=typeof postboxes&&postboxes.add_postbox_toggles(bp_activity_admin_vars.page)})}(jQuery);
bp-activity/bp-activity-actions.php CHANGED
@@ -33,9 +33,8 @@ add_action( 'bp_init', 'bp_register_activity_actions', 8 );
33
  /**
34
  * Catch and route requests for single activity item permalinks.
35
  *
36
- * @since BuddyPress (1.2)
37
  *
38
- * @global object $bp BuddyPress global settings
39
  * @uses bp_is_activity_component()
40
  * @uses bp_is_current_action()
41
  * @uses bp_action_variable()
@@ -121,7 +120,7 @@ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
121
  /**
122
  * Delete specific activity item and redirect to previous page.
123
  *
124
- * @since BuddyPress (1.1)
125
  *
126
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
127
  *
@@ -167,7 +166,7 @@ function bp_activity_action_delete_activity( $activity_id = 0 ) {
167
  * @since BuddyPress (1.5.0)
168
  *
169
  * @param int $activity_id The activity ID.
170
- * @param int $user_id The user associated with the activity.
171
  */
172
  do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
173
 
@@ -183,7 +182,7 @@ function bp_activity_action_delete_activity( $activity_id = 0 ) {
183
  * @since BuddyPress (1.1.0)
184
  *
185
  * @param int $activity_id The activity ID.
186
- * @param int $user_id The user associated with the activity.
187
  */
188
  do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
189
 
@@ -198,14 +197,14 @@ add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
198
  /**
199
  * Mark specific activity item as spam and redirect to previous page.
200
  *
201
- * @since BuddyPress (1.6)
202
  *
203
- * @global object $bp BuddyPress global settings
204
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
 
205
  * @return bool False on failure.
206
  */
207
  function bp_activity_action_spam_activity( $activity_id = 0 ) {
208
- global $bp;
209
 
210
  // Not viewing activity, or action is not spam, or Akismet isn't present
211
  if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
@@ -236,7 +235,7 @@ function bp_activity_action_spam_activity( $activity_id = 0 ) {
236
  * @since BuddyPress (1.6.0)
237
  *
238
  * @param int $activity_id Activity ID to be marked as spam.
239
- * @param object $activity Activity object for the ID to be marked as spam.
240
  */
241
  do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
242
 
@@ -253,7 +252,7 @@ function bp_activity_action_spam_activity( $activity_id = 0 ) {
253
  * @since BuddyPress (1.6.0)
254
  *
255
  * @param int $activity_id Activity ID that was marked as spam.
256
- * @param int $user_id User ID associated with activity.
257
  */
258
  do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
259
 
@@ -268,7 +267,7 @@ add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
268
  /**
269
  * Post user/group activity update.
270
  *
271
- * @since BuddyPress (1.2)
272
  *
273
  * @uses is_user_logged_in()
274
  * @uses bp_is_activity_component()
@@ -300,7 +299,7 @@ function bp_activity_action_post_update() {
300
  *
301
  * @since BuddyPress (1.2.0)
302
  *
303
- * @param string $whats-new Activity message being posted.
304
  */
305
  $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
306
 
@@ -311,7 +310,7 @@ function bp_activity_action_post_update() {
311
  *
312
  * @since BuddyPress (1.2.0)
313
  *
314
- * @param string $whats-new-post-object Item type to associate with.
315
  */
316
  $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
317
  }
@@ -323,7 +322,7 @@ function bp_activity_action_post_update() {
323
  *
324
  * @since BuddyPress (1.2.0)
325
  *
326
- * @param string $whats-new-post-in Chosen component to post activity to.
327
  */
328
  $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
329
  }
@@ -351,7 +350,7 @@ function bp_activity_action_post_update() {
351
  *
352
  * @since BuddyPress (1.2.0)
353
  *
354
- * @param string $object Activity item being associated to.
355
  * @param string $item_id Component ID being posted to.
356
  * @param string $content Activity content being posted.
357
  */
@@ -372,7 +371,7 @@ add_action( 'bp_actions', 'bp_activity_action_post_update' );
372
  /**
373
  * Post new activity comment.
374
  *
375
- * @since BuddyPress (1.2)
376
  *
377
  * @uses is_user_logged_in()
378
  * @uses bp_is_activity_component()
@@ -400,7 +399,7 @@ function bp_activity_action_post_comment() {
400
  *
401
  * @since BuddyPress (1.2.0)
402
  *
403
- * @param string $comment_form_id ID of the activity being replied to.
404
  */
405
  $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
406
 
@@ -409,7 +408,7 @@ function bp_activity_action_post_comment() {
409
  *
410
  * @since BuddyPress (1.2.0)
411
  *
412
- * @param string $ac_input_activity_id Comment content being posted.
413
  */
414
  $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
415
 
@@ -436,7 +435,7 @@ add_action( 'bp_actions', 'bp_activity_action_post_comment' );
436
  /**
437
  * Mark activity as favorite.
438
  *
439
- * @since BuddyPress (1.2)
440
  *
441
  * @uses is_user_logged_in()
442
  * @uses bp_is_activity_component()
@@ -470,7 +469,7 @@ add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );
470
  /**
471
  * Remove activity from favorites.
472
  *
473
- * @since BuddyPress (1.2)
474
  *
475
  * @uses is_user_logged_in()
476
  * @uses bp_is_activity_component()
@@ -504,9 +503,8 @@ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
504
  /**
505
  * Load the sitewide activity feed.
506
  *
507
- * @since BuddyPress (1.0)
508
  *
509
- * @global object $bp BuddyPress global settings
510
  * @uses bp_is_activity_component()
511
  * @uses bp_is_current_action()
512
  * @uses bp_is_user()
@@ -515,7 +513,7 @@ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
515
  * @return bool False on failure.
516
  */
517
  function bp_activity_action_sitewide_feed() {
518
- global $bp;
519
 
520
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
521
  return false;
@@ -537,7 +535,7 @@ add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
537
  /**
538
  * Load a user's personal activity feed.
539
  *
540
- * @since BuddyPress (1.0)
541
  *
542
  * @uses bp_is_user_activity()
543
  * @uses bp_is_current_action()
@@ -567,7 +565,7 @@ add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
567
  /**
568
  * Load a user's friends' activity feed.
569
  *
570
- * @since BuddyPress (1.0)
571
  *
572
  * @uses bp_is_active()
573
  * @uses bp_is_user_activity()
@@ -600,7 +598,7 @@ add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
600
  /**
601
  * Load the activity feed for a user's groups.
602
  *
603
- * @since BuddyPress (1.2)
604
  *
605
  * @uses bp_is_active()
606
  * @uses bp_is_user_activity()
@@ -641,7 +639,7 @@ add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
641
  /**
642
  * Load a user's @mentions feed.
643
  *
644
- * @since BuddyPress (1.2)
645
  *
646
  * @uses bp_is_user_activity()
647
  * @uses bp_is_current_action()
@@ -678,7 +676,7 @@ add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
678
  /**
679
  * Load a user's favorites feed.
680
  *
681
- * @since BuddyPress (1.2)
682
  *
683
  * @uses bp_is_user_activity()
684
  * @uses bp_is_current_action()
@@ -713,30 +711,37 @@ add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
713
  /**
714
  * Loads Akismet filtering for activity.
715
  *
716
- * @since BuddyPress (1.6)
717
- *
718
- * @global object $bp BuddyPress global settings
719
  */
720
  function bp_activity_setup_akismet() {
721
- global $bp;
722
 
723
  // Bail if Akismet is not active
724
- if ( ! defined( 'AKISMET_VERSION' ) )
 
 
 
 
 
725
  return;
 
726
 
727
  // Bail if no Akismet key is set
728
- if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) )
729
  return;
 
730
 
731
  /**
732
  * Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
733
  *
734
  * @since BuddyPress (1.6.0)
735
  *
736
- * @param bool bp_is_akismet_active Return value of bp_is_akismet_active boolean function.
737
  */
738
- if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) )
739
  return;
 
740
 
741
  // Instantiate Akismet for BuddyPress
742
  $bp->activity->akismet = new BP_Akismet();
33
  /**
34
  * Catch and route requests for single activity item permalinks.
35
  *
36
+ * @since BuddyPress (1.2.0)
37
  *
 
38
  * @uses bp_is_activity_component()
39
  * @uses bp_is_current_action()
40
  * @uses bp_action_variable()
120
  /**
121
  * Delete specific activity item and redirect to previous page.
122
  *
123
+ * @since BuddyPress (1.1.0)
124
  *
125
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
126
  *
166
  * @since BuddyPress (1.5.0)
167
  *
168
  * @param int $activity_id The activity ID.
169
+ * @param int $user_id The user associated with the activity.
170
  */
171
  do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
172
 
182
  * @since BuddyPress (1.1.0)
183
  *
184
  * @param int $activity_id The activity ID.
185
+ * @param int $user_id The user associated with the activity.
186
  */
187
  do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
188
 
197
  /**
198
  * Mark specific activity item as spam and redirect to previous page.
199
  *
200
+ * @since BuddyPress (1.6.0)
201
  *
 
202
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
203
+ *
204
  * @return bool False on failure.
205
  */
206
  function bp_activity_action_spam_activity( $activity_id = 0 ) {
207
+ $bp = buddypress();
208
 
209
  // Not viewing activity, or action is not spam, or Akismet isn't present
210
  if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
235
  * @since BuddyPress (1.6.0)
236
  *
237
  * @param int $activity_id Activity ID to be marked as spam.
238
+ * @param object $activity Activity object for the ID to be marked as spam.
239
  */
240
  do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
241
 
252
  * @since BuddyPress (1.6.0)
253
  *
254
  * @param int $activity_id Activity ID that was marked as spam.
255
+ * @param int $user_id User ID associated with activity.
256
  */
257
  do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
258
 
267
  /**
268
  * Post user/group activity update.
269
  *
270
+ * @since BuddyPress (1.2.0)
271
  *
272
  * @uses is_user_logged_in()
273
  * @uses bp_is_activity_component()
299
  *
300
  * @since BuddyPress (1.2.0)
301
  *
302
+ * @param string $value Activity message being posted.
303
  */
304
  $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
305
 
310
  *
311
  * @since BuddyPress (1.2.0)
312
  *
313
+ * @param string $value Item type to associate with.
314
  */
315
  $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
316
  }
322
  *
323
  * @since BuddyPress (1.2.0)
324
  *
325
+ * @param string $value Chosen component to post activity to.
326
  */
327
  $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
328
  }
350
  *
351
  * @since BuddyPress (1.2.0)
352
  *
353
+ * @param string $object Activity item being associated to.
354
  * @param string $item_id Component ID being posted to.
355
  * @param string $content Activity content being posted.
356
  */
371
  /**
372
  * Post new activity comment.
373
  *
374
+ * @since BuddyPress (1.2.0)
375
  *
376
  * @uses is_user_logged_in()
377
  * @uses bp_is_activity_component()
399
  *
400
  * @since BuddyPress (1.2.0)
401
  *
402
+ * @param string $value ID of the activity being replied to.
403
  */
404
  $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
405
 
408
  *
409
  * @since BuddyPress (1.2.0)
410
  *
411
+ * @param string $value Comment content being posted.
412
  */
413
  $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
414
 
435
  /**
436
  * Mark activity as favorite.
437
  *
438
+ * @since BuddyPress (1.2.0)
439
  *
440
  * @uses is_user_logged_in()
441
  * @uses bp_is_activity_component()
469
  /**
470
  * Remove activity from favorites.
471
  *
472
+ * @since BuddyPress (1.2.0)
473
  *
474
  * @uses is_user_logged_in()
475
  * @uses bp_is_activity_component()
503
  /**
504
  * Load the sitewide activity feed.
505
  *
506
+ * @since BuddyPress (1.0.0)
507
  *
 
508
  * @uses bp_is_activity_component()
509
  * @uses bp_is_current_action()
510
  * @uses bp_is_user()
513
  * @return bool False on failure.
514
  */
515
  function bp_activity_action_sitewide_feed() {
516
+ $bp = buddypress();
517
 
518
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
519
  return false;
535
  /**
536
  * Load a user's personal activity feed.
537
  *
538
+ * @since BuddyPress (1.0.0)
539
  *
540
  * @uses bp_is_user_activity()
541
  * @uses bp_is_current_action()
565
  /**
566
  * Load a user's friends' activity feed.
567
  *
568
+ * @since BuddyPress (1.0.0)
569
  *
570
  * @uses bp_is_active()
571
  * @uses bp_is_user_activity()
598
  /**
599
  * Load the activity feed for a user's groups.
600
  *
601
+ * @since BuddyPress (1.2.0)
602
  *
603
  * @uses bp_is_active()
604
  * @uses bp_is_user_activity()
639
  /**
640
  * Load a user's @mentions feed.
641
  *
642
+ * @since BuddyPress (1.2.0)
643
  *
644
  * @uses bp_is_user_activity()
645
  * @uses bp_is_current_action()
676
  /**
677
  * Load a user's favorites feed.
678
  *
679
+ * @since BuddyPress (1.2.0)
680
  *
681
  * @uses bp_is_user_activity()
682
  * @uses bp_is_current_action()
711
  /**
712
  * Loads Akismet filtering for activity.
713
  *
714
+ * @since BuddyPress (1.6.0)
715
+ * @since BuddyPress (2.3.0) We only support Akismet 3+.
 
716
  */
717
  function bp_activity_setup_akismet() {
718
+ $bp = buddypress();
719
 
720
  // Bail if Akismet is not active
721
+ if ( ! defined( 'AKISMET_VERSION' ) ) {
722
+ return;
723
+ }
724
+
725
+ // Bail if older version of Akismet
726
+ if ( ! class_exists( 'Akismet' ) ) {
727
  return;
728
+ }
729
 
730
  // Bail if no Akismet key is set
731
+ if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) ) {
732
  return;
733
+ }
734
 
735
  /**
736
  * Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
737
  *
738
  * @since BuddyPress (1.6.0)
739
  *
740
+ * @param bool $value Return value of bp_is_akismet_active boolean function.
741
  */
742
+ if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
743
  return;
744
+ }
745
 
746
  // Instantiate Akismet for BuddyPress
747
  $bp->activity->akismet = new BP_Akismet();
bp-activity/bp-activity-admin.php CHANGED
@@ -52,7 +52,8 @@ add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
52
  * @since BuddyPress (1.7.0)
53
  *
54
  * @param array $custom_menus The list of top-level BP menu items.
55
- * @return array $custom_menus List of top-level BP menu items, with Activity added
 
56
  */
57
  function bp_activity_admin_menu_order( $custom_menus = array() ) {
58
  array_push( $custom_menus, 'bp-activity' );
@@ -138,10 +139,10 @@ add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' );
138
  *
139
  * @since BuddyPress (1.6.0)
140
  *
141
- * @param string $value Will always be false unless another plugin filters it
142
- * first.
143
- * @param string $option Screen option name.
144
  * @param string $new_value Screen option form value.
 
145
  * @return string Option value. False to abandon update.
146
  */
147
  function bp_activity_admin_screen_options( $value, $option, $new_value ) {
@@ -161,7 +162,9 @@ function bp_activity_admin_screen_options( $value, $option, $new_value ) {
161
  *
162
  * @since BuddyPress (1.6.0)
163
  *
 
164
  * @param WP_Screen $screen Screen identifier.
 
165
  * @return array Hidden Meta Boxes.
166
  */
167
  function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
@@ -188,12 +191,12 @@ add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxe
188
  *
189
  * Does the following:
190
  * - Register contextual help and screen options for this admin page.
191
- * - Enqueues scripts and styles
192
- * - Catches POST and GET requests related to Activity
193
  *
194
  * @since BuddyPress (1.6.0)
195
  *
196
- * @global object $bp BuddyPress global settings.
197
  * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
198
  */
199
  function bp_activity_admin_load() {
@@ -242,8 +245,8 @@ function bp_activity_admin_load() {
242
  // Help panel - sidebar links
243
  get_current_screen()->set_help_sidebar(
244
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
245
- '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-activity/">Managing Activity</a>', 'buddypress' ) . '</p>' .
246
- '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
247
  );
248
 
249
  // Register metaboxes for the edit screen.
@@ -253,7 +256,7 @@ function bp_activity_admin_load() {
253
  add_meta_box( 'bp_activity_type', _x( 'Type', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core' );
254
  add_meta_box( 'bp_activity_userid', _x( 'Author ID', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core' );
255
 
256
- // Enqueue javascripts
257
  wp_enqueue_script( 'postbox' );
258
  wp_enqueue_script( 'dashboard' );
259
  wp_enqueue_script( 'comment' );
@@ -287,7 +290,7 @@ function bp_activity_admin_load() {
287
  // Help panel - sidebar links
288
  get_current_screen()->set_help_sidebar(
289
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
290
- '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
291
  );
292
  }
293
 
@@ -411,8 +414,8 @@ function bp_activity_admin_load() {
411
  *
412
  * @since BuddyPress (1.6.0)
413
  *
414
- * @param array Array holding spam, not spam, deleted counts, error IDs.
415
- * @param string $redirect_to URL to redirect to.
416
  * @param array $activity_ids Original array of activity IDs.
417
  */
418
  do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
@@ -639,7 +642,7 @@ function bp_activity_admin_edit() {
639
  *
640
  * @since BuddyPress (1.6.0)
641
  *
642
- * @param array Array holding single activity object.
643
  */
644
  do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>
645
 
@@ -816,16 +819,14 @@ function bp_activity_admin_get_activity_actions() {
816
  }
817
 
818
  /**
819
- * Activity type metabox for the Activity admin edit screen
820
  *
821
  * @since BuddyPress (1.6.0)
822
  *
823
- * @global object $bp BuddyPress global settings.
824
- *
825
  * @param object $item Activity item.
826
  */
827
  function bp_activity_admin_edit_metabox_type( $item ) {
828
- global $bp;
829
 
830
  $actions = array();
831
  $selected = $item->type;
@@ -890,9 +891,8 @@ function bp_activity_admin_edit_metabox_itemids( $item ) {
890
  *
891
  * @since BuddyPress (1.6.0)
892
  *
893
- * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list
894
- * table.
895
- * @global string $plugin_page The current plugin page.
896
  */
897
  function bp_activity_admin_index() {
898
  global $bp_activity_list_table, $plugin_page;
@@ -1004,7 +1004,7 @@ function bp_activity_admin_index() {
1004
  <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
1005
  <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
1006
 
1007
- <img class="waiting" style="display:none;" src="<?php echo esc_url( bp_get_admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1008
  <span class="error" style="display:none;"></span>
1009
  <br class="clear" />
1010
  </p>
@@ -1023,7 +1023,7 @@ function bp_activity_admin_index() {
1023
  /**
1024
  * List table class for the Activity component admin page.
1025
  *
1026
- * @since BuddyPress (1.6)
1027
  */
1028
  class BP_Activity_List_Table extends WP_List_Table {
1029
 
@@ -1054,7 +1054,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1054
  protected $activity_user_id = array();
1055
 
1056
  /**
1057
- * If users can comment on blog & forum activity items
1058
  *
1059
  * @since BuddyPress (2.2.2)
1060
  *
@@ -1276,11 +1276,11 @@ class BP_Activity_List_Table extends WP_List_Table {
1276
  * @since BuddyPress (1.6.0)
1277
  */
1278
  function get_views() {
1279
- $url_base = bp_get_admin_url( 'admin.php?page=bp-activity' ); ?>
1280
 
1281
  <ul class="subsubsub">
1282
  <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
1283
- <li class="spam"><a href="<?php echo esc_url( add_query_arg( 'activity_status', 'spam', $url_base ) ); ?>" class="<?php if ( 'spam' == $this->view ) echo 'current'; ?>"><?php printf( __( 'Spam <span class="count">(%s)</span>', 'buddypress' ), number_format_i18n( $this->spam_count ) ); ?></a></li>
1284
 
1285
  <?php
1286
 
@@ -1290,7 +1290,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1290
  * @since BuddyPress (1.6.0)
1291
  *
1292
  * @param string $url_base Current URL base for view.
1293
- * @param string $view Current view being displayed.
1294
  */
1295
  do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?>
1296
  </ul>
@@ -1493,7 +1493,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1493
 
1494
  // Rollover actions
1495
 
1496
- // Reply - javascript only; implemented by AJAX.
1497
  if ( 'spam' != $item_status ) {
1498
  if ( $this->can_comment( $item ) ) {
1499
  $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
@@ -1523,7 +1523,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1523
  * @since BuddyPress (1.6.0)
1524
  *
1525
  * @param array $actions Array of available actions user could use.
1526
- * @param array $item Current item being added to page.
1527
  */
1528
  $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
1529
 
@@ -1575,8 +1575,8 @@ class BP_Activity_List_Table extends WP_List_Table {
1575
  *
1576
  * @since BuddyPress (1.6.0)
1577
  *
1578
- * @param array Array of default activity types.
1579
- * @param array $item Current item being displayed.
1580
  */
1581
  if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {
1582
  $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;
@@ -1607,6 +1607,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1607
  * @since BuddyPress (1.6.0)
1608
  *
1609
  * @param int $activity_id Activity ID to retrieve User ID for.
 
1610
  * @return int User ID of the activity item in question.
1611
  */
1612
  protected function get_activity_user_id( $activity_id ) {
@@ -1640,13 +1641,14 @@ class BP_Activity_List_Table extends WP_List_Table {
1640
  * Checks if an activity item can be replied to.
1641
  *
1642
  * This method merges functionality from {@link bp_activity_can_comment()} and
1643
- * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity
1644
  * list table doesn't use a BuddyPress activity loop, which prevents those
1645
  * functions from working as intended.
1646
  *
1647
  * @since BuddyPress (2.0.0)
1648
  *
1649
  * @param array $item An array version of the BP_Activity_Activity object.
 
1650
  * @return bool
1651
  */
1652
  protected function can_comment( $item ) {
@@ -1711,6 +1713,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1711
  * @since BuddyPress (1.6.0)
1712
  *
1713
  * @param array $tree Source array.
 
1714
  * @return array Flattened array.
1715
  */
1716
  public static function flatten_activity_array( $tree ){
52
  * @since BuddyPress (1.7.0)
53
  *
54
  * @param array $custom_menus The list of top-level BP menu items.
55
+ *
56
+ * @return array $custom_menus List of top-level BP menu items, with Activity added.
57
  */
58
  function bp_activity_admin_menu_order( $custom_menus = array() ) {
59
  array_push( $custom_menus, 'bp-activity' );
139
  *
140
  * @since BuddyPress (1.6.0)
141
  *
142
+ * @param string $value Will always be false unless another plugin filters it first.
143
+ * @param string $option Screen option name.
 
144
  * @param string $new_value Screen option form value.
145
+ *
146
  * @return string Option value. False to abandon update.
147
  */
148
  function bp_activity_admin_screen_options( $value, $option, $new_value ) {
162
  *
163
  * @since BuddyPress (1.6.0)
164
  *
165
+ * @param array $hidden Array of items to hide.
166
  * @param WP_Screen $screen Screen identifier.
167
+ *
168
  * @return array Hidden Meta Boxes.
169
  */
170
  function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
191
  *
192
  * Does the following:
193
  * - Register contextual help and screen options for this admin page.
194
+ * - Enqueues scripts and styles.
195
+ * - Catches POST and GET requests related to Activity.
196
  *
197
  * @since BuddyPress (1.6.0)
198
  *
199
+ * @global object $bp BuddyPress global settings.
200
  * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
201
  */
202
  function bp_activity_admin_load() {
245
  // Help panel - sidebar links
246
  get_current_screen()->set_help_sidebar(
247
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
248
+ '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress' ) . '</p>' .
249
+ '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
250
  );
251
 
252
  // Register metaboxes for the edit screen.
256
  add_meta_box( 'bp_activity_type', _x( 'Type', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core' );
257
  add_meta_box( 'bp_activity_userid', _x( 'Author ID', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core' );
258
 
259
+ // Enqueue JavaScript files
260
  wp_enqueue_script( 'postbox' );
261
  wp_enqueue_script( 'dashboard' );
262
  wp_enqueue_script( 'comment' );
290
  // Help panel - sidebar links
291
  get_current_screen()->set_help_sidebar(
292
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
293
+ '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
294
  );
295
  }
296
 
414
  *
415
  * @since BuddyPress (1.6.0)
416
  *
417
+ * @param array $value Array holding spam, not spam, deleted counts, error IDs.
418
+ * @param string $redirect_to URL to redirect to.
419
  * @param array $activity_ids Original array of activity IDs.
420
  */
421
  do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
642
  *
643
  * @since BuddyPress (1.6.0)
644
  *
645
+ * @param array $value Array holding single activity object that was passed by reference.
646
  */
647
  do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>
648
 
819
  }
820
 
821
  /**
822
+ * Activity type metabox for the Activity admin edit screen.
823
  *
824
  * @since BuddyPress (1.6.0)
825
  *
 
 
826
  * @param object $item Activity item.
827
  */
828
  function bp_activity_admin_edit_metabox_type( $item ) {
829
+ $bp = buddypress();
830
 
831
  $actions = array();
832
  $selected = $item->type;
891
  *
892
  * @since BuddyPress (1.6.0)
893
  *
894
+ * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
895
+ * @global string $plugin_page The current plugin page.
 
896
  */
897
  function bp_activity_admin_index() {
898
  global $bp_activity_list_table, $plugin_page;
1004
  <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
1005
  <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
1006
 
1007
+ <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1008
  <span class="error" style="display:none;"></span>
1009
  <br class="clear" />
1010
  </p>
1023
  /**
1024
  * List table class for the Activity component admin page.
1025
  *
1026
+ * @since BuddyPress (1.6.0)
1027
  */
1028
  class BP_Activity_List_Table extends WP_List_Table {
1029
 
1054
  protected $activity_user_id = array();
1055
 
1056
  /**
1057
+ * If users can comment on blog & forum activity items.
1058
  *
1059
  * @since BuddyPress (2.2.2)
1060
  *
1276
  * @since BuddyPress (1.6.0)
1277
  */
1278
  function get_views() {
1279
+ $url_base = add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ); ?>
1280
 
1281
  <ul class="subsubsub">
1282
  <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
1283
+ <li class="spam"><a href="<?php echo esc_url( add_query_arg( array( 'activity_status' => 'spam' ), $url_base ) ); ?>" class="<?php if ( 'spam' == $this->view ) echo 'current'; ?>"><?php printf( __( 'Spam <span class="count">(%s)</span>', 'buddypress' ), number_format_i18n( $this->spam_count ) ); ?></a></li>
1284
 
1285
  <?php
1286
 
1290
  * @since BuddyPress (1.6.0)
1291
  *
1292
  * @param string $url_base Current URL base for view.
1293
+ * @param string $view Current view being displayed.
1294
  */
1295
  do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?>
1296
  </ul>
1493
 
1494
  // Rollover actions
1495
 
1496
+ // Reply - JavaScript only; implemented by AJAX.
1497
  if ( 'spam' != $item_status ) {
1498
  if ( $this->can_comment( $item ) ) {
1499
  $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
1523
  * @since BuddyPress (1.6.0)
1524
  *
1525
  * @param array $actions Array of available actions user could use.
1526
+ * @param array $item Current item being added to page.
1527
  */
1528
  $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
1529
 
1575
  *
1576
  * @since BuddyPress (1.6.0)
1577
  *
1578
+ * @param array $value Array of default activity types.
1579
+ * @param array $item Current item being displayed.
1580
  */
1581
  if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {
1582
  $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;
1607
  * @since BuddyPress (1.6.0)
1608
  *
1609
  * @param int $activity_id Activity ID to retrieve User ID for.
1610
+ *
1611
  * @return int User ID of the activity item in question.
1612
  */
1613
  protected function get_activity_user_id( $activity_id ) {
1641
  * Checks if an activity item can be replied to.
1642
  *
1643
  * This method merges functionality from {@link bp_activity_can_comment()} and
1644
+ * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity
1645
  * list table doesn't use a BuddyPress activity loop, which prevents those
1646
  * functions from working as intended.
1647
  *
1648
  * @since BuddyPress (2.0.0)
1649
  *
1650
  * @param array $item An array version of the BP_Activity_Activity object.
1651
+ *
1652
  * @return bool
1653
  */
1654
  protected function can_comment( $item ) {
1713
  * @since BuddyPress (1.6.0)
1714
  *
1715
  * @param array $tree Source array.
1716
+ *
1717
  * @return array Flattened array.
1718
  */
1719
  public static function flatten_activity_array( $tree ){
bp-activity/bp-activity-akismet.php CHANGED
@@ -3,7 +3,7 @@
3
  * Akismet support for BuddyPress' Activity Stream.
4
  *
5
  * @package BuddyPress
6
- * @since BuddyPress (1.6)
7
  * @subpackage Activity
8
  */
9
 
@@ -13,7 +13,8 @@ defined( 'ABSPATH' ) || exit;
13
  /**
14
  * Akismet support for the Activity component.
15
  *
16
- * @since BuddyPress (1.6)
 
17
  */
18
  class BP_Akismet {
19
  /**
@@ -21,14 +22,14 @@ class BP_Akismet {
21
  *
22
  * @access protected
23
  * @var BP_Activity_Activity
24
- * @since BuddyPress (1.6)
25
  */
26
  protected $last_activity = null;
27
 
28
  /**
29
  * Constructor.
30
  *
31
- * @since BuddyPress (1.6)
32
  */
33
  public function __construct() {
34
  $this->setup_actions();
@@ -37,7 +38,7 @@ class BP_Akismet {
37
  /**
38
  * Hook Akismet into the activity stream.
39
  *
40
- * @since BuddyPress (1.6)
41
  */
42
  protected function setup_actions() {
43
  // Add nonces to activity stream lists
@@ -69,10 +70,11 @@ class BP_Akismet {
69
  * This function lifted with love from the Akismet WordPress plugin's
70
  * akismet_comment_row_action() function. Thanks!
71
  *
72
- * @since BuddyPress (1.6)
73
  *
74
- * @param array $actions The hover links.
75
  * @param array $activity The activity for the current row being processed.
 
76
  * @return array The hover links.
77
  */
78
  function comment_row_action( $actions, $activity ) {
@@ -129,9 +131,9 @@ class BP_Akismet {
129
  * the reply form of each activity item. The nonces are, in turn, used
130
  * by Akismet to help detect spam activity.
131
  *
132
- * @since BuddyPress (1.6)
133
  *
134
- * @see http://plugins.trac.wordpress.org/ticket/1232
135
  */
136
  public function add_activity_stream_nonce() {
137
  $form_id = '_bp_as_nonce';
@@ -158,13 +160,13 @@ class BP_Akismet {
158
  * This can't be done in BP_Akismet::check_activity() due to the
159
  * default AJAX implementation; see bp_dtheme_post_update().
160
  *
161
- * @since BuddyPress (1.6)
162
  *
163
  * @see bp_dtheme_post_update()
164
  *
165
- * @param string $content Activity update text.
166
- * @param int $user_id User ID.
167
- * @param int $activity_id Activity ID.
168
  */
169
  public function check_member_activity_update( $content, $user_id, $activity_id ) {
170
  // By default, only handle activity updates and activity comments.
@@ -184,7 +186,7 @@ class BP_Akismet {
184
  *
185
  * This function is intended to be used inside the activity stream loop.
186
  *
187
- * @since BuddyPress (1.6)
188
  */
189
  public function add_activity_spam_button() {
190
  if ( !bp_activity_user_can_mark_spam() )
@@ -212,7 +214,7 @@ class BP_Akismet {
212
  *
213
  * This function is intended to be used inside the activity stream loop.
214
  *
215
- * @since BuddyPress (1.6)
216
  */
217
  public function add_activity_comment_spam_button() {
218
  if ( !bp_activity_user_can_mark_spam() )
@@ -239,7 +241,7 @@ class BP_Akismet {
239
  /**
240
  * Get a filterable list of activity types that Akismet should automatically check for spam.
241
  *
242
- * @since BuddyPress (1.6)
243
  *
244
  * @static
245
  *
@@ -260,10 +262,12 @@ class BP_Akismet {
260
  /**
261
  * Mark activity item as spam.
262
  *
263
- * @since BuddyPress (1.6)
264
  *
265
- * @param BP_Activity_Activity $activity
266
- * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as spam) or "by_akismet" (automatically spammed).
 
 
267
  */
268
  public function mark_as_spam( $activity, $source ) {
269
  // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update()
@@ -275,7 +279,10 @@ class BP_Akismet {
275
  * @since BuddyPress (1.6.0)
276
  *
277
  * @param BP_Activity_Activity $activity Activity object being marked as spam.
278
- * @param string $source Source of the whom marked as spam. Either "by_a_person" (e.g. a person has manually marked the activity as spam) or "by_akismet".
 
 
 
279
  */
280
  do_action( 'bp_activity_akismet_mark_as_spam', $activity, $source );
281
  }
@@ -283,10 +290,12 @@ class BP_Akismet {
283
  /**
284
  * Mark activity item as ham.
285
  *
286
- * @since BuddyPress (1.6)
287
  *
288
- * @param BP_Activity_Activity $activity
289
- * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as ham) or "by_akismet" (automatically hammed).
 
 
290
  */
291
  public function mark_as_ham( $activity, $source ) {
292
  // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
@@ -299,7 +308,10 @@ class BP_Akismet {
299
  * @since BuddyPress (1.6.0)
300
  *
301
  * @param BP_Activity_Activity $activity Activity object being marked as ham.
302
- * @param string $source Source of the whom marked as ham. Either "by_a_person" (e.g. a person has manually marked the activity as ham) or "by_akismet" (automatically hammed).
 
 
 
303
  */
304
  do_action( 'bp_activity_akismet_mark_as_ham', $activity, $source );
305
  }
@@ -307,12 +319,14 @@ class BP_Akismet {
307
  /**
308
  * Build a data package for the Akismet service to inspect.
309
  *
310
- * @since BuddyPress (1.6)
311
  *
312
  * @see http://akismet.com/development/api/#comment-check
313
  * @static
314
  *
315
  * @param BP_Activity_Activity $activity Activity item data.
 
 
316
  */
317
  public static function build_akismet_data_package( $activity ) {
318
  $userdata = get_userdata( $activity->user_id );
@@ -326,7 +340,7 @@ class BP_Akismet {
326
  $activity_data['comment_type'] = $activity->type;
327
  $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity );
328
  $activity_data['user_ID'] = $userdata->ID;
329
- $activity_data['user_role'] = akismet_get_user_roles( $userdata->ID );
330
 
331
  /**
332
  * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
@@ -347,8 +361,8 @@ class BP_Akismet {
347
  *
348
  * @since BuddyPress (1.6.0)
349
  *
350
- * @param array $activity_data Array of activity data for Akismet to inspect.
351
- * @param BP_Activity_Activity $activity Activity item data.
352
  */
353
  return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity );
354
  }
@@ -356,7 +370,7 @@ class BP_Akismet {
356
  /**
357
  * Check if the activity item is spam or ham.
358
  *
359
- * @since BuddyPress (1.6)
360
  *
361
  * @see http://akismet.com/development/api/
362
  * @todo Spam counter?
@@ -391,8 +405,9 @@ class BP_Akismet {
391
  *
392
  * @since BuddyPress (1.6.0)
393
  *
394
- * @param BP_Activity_Activity $activity The activity item proven to be spam.
395
- * @param array $activity_data Array of activity data for item including Akismet check results data.
 
396
  */
397
  do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
398
 
@@ -407,7 +422,7 @@ class BP_Akismet {
407
  /**
408
  * Update activity meta after a manual spam change (user-initiated).
409
  *
410
- * @since BuddyPress (1.6)
411
  *
412
  * @param BP_Activity_Activity $activity The activity to check.
413
  */
@@ -424,7 +439,7 @@ class BP_Akismet {
424
  /**
425
  * Update activity meta after a manual ham change (user-initiated).
426
  *
427
- * @since BuddyPress (1.6)
428
  *
429
  * @param BP_Activity_Activity $activity The activity to check.
430
  */
@@ -441,7 +456,7 @@ class BP_Akismet {
441
  /**
442
  * Update activity meta after an automatic spam check (not user-initiated).
443
  *
444
- * @since BuddyPress (1.6)
445
  *
446
  * @param BP_Activity_Activity $activity The activity to check.
447
  */
@@ -479,23 +494,15 @@ class BP_Akismet {
479
  *
480
  * Props to WordPress core Akismet plugin for a lot of this.
481
  *
482
- * @since BuddyPress (1.6)
483
  *
484
- * @global string $akismet_api_host
485
- * @global string $akismet_api_port
 
486
  *
487
- * @param array $activity_data Packet of information to submit to Akismet.
488
- * @param string $check "check" or "submit".
489
- * @param string $spam "spam" or "ham".
490
  * @return array $activity_data Activity data, with Akismet data added.
491
  */
492
  public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
493
- global $akismet_api_host, $akismet_api_port;
494
-
495
- // Check that host and port are set, if not, set them
496
- if ( function_exists( 'akismet_init' ) && ( empty( $akismet_api_host ) || empty( $akismet_api_port ) ) )
497
- akismet_init();
498
-
499
  $query_string = $path = '';
500
 
501
  $activity_data['blog'] = bp_get_option( 'home' );
@@ -505,7 +512,7 @@ class BP_Akismet {
505
  $activity_data['user_agent'] = bp_core_current_user_ua();
506
  $activity_data['user_ip'] = bp_core_current_user_ip();
507
 
508
- if ( akismet_test_mode() )
509
  $activity_data['is_test'] = 'true';
510
 
511
  // Loop through _POST args and rekey strings
@@ -533,13 +540,13 @@ class BP_Akismet {
533
  $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
534
 
535
  if ( 'check' == $check )
536
- $path = '/1.1/comment-check';
537
  elseif ( 'submit' == $check )
538
- $path = '/1.1/submit-' . $spam;
539
 
540
  // Send to Akismet
541
  add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
542
- $response = akismet_http_post( $query_string, $akismet_api_host, $path, $akismet_api_port );
543
  remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
544
 
545
  // Get the response
@@ -558,9 +565,10 @@ class BP_Akismet {
558
  /**
559
  * Filters user agent when sending to Akismet to add BuddyPress info.
560
  *
561
- * @since BuddyPress (1.6)
562
  *
563
  * @param string $user_agent User agent string, as generated by Akismet.
 
564
  * @return string $user_agent Modified user agent string.
565
  */
566
  public function buddypress_ua( $user_agent ) {
@@ -571,7 +579,7 @@ class BP_Akismet {
571
  /**
572
  * Adds a "History" meta box to the activity edit screen.
573
  *
574
- * @since BuddyPress (1.6)
575
  *
576
  * @param string $screen_action The type of screen that has been requested.
577
  */
@@ -587,9 +595,9 @@ class BP_Akismet {
587
  /**
588
  * History meta box for the Activity admin edit screen.
589
  *
590
- * @since BuddyPress (1.6)
591
  *
592
- * @see http://buddypress.trac.wordpress.org/ticket/3907
593
  * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
594
  *
595
  * @param object $item Activity item.
@@ -608,17 +616,17 @@ class BP_Akismet {
608
  /**
609
  * Update an activity item's Akismet history.
610
  *
611
- * @since BuddyPress (1.6)
612
  *
613
- * @param int $activity_id Activity item ID.
614
- * @param string $message Human-readable description of what's changed.
615
- * @param string $event The type of check we were carrying out.
616
  */
617
  public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) {
618
  $event = array(
619
  'event' => $event,
620
  'message' => $message,
621
- 'time' => akismet_microtime(),
622
  'user' => bp_loggedin_user_id(),
623
  );
624
 
@@ -629,9 +637,10 @@ class BP_Akismet {
629
  /**
630
  * Get an activity item's Akismet history.
631
  *
632
- * @since BuddyPress (1.6)
633
  *
634
  * @param int $activity_id Activity item ID.
 
635
  * @return array The activity item's Akismet history.
636
  */
637
  public function get_activity_history( $activity_id = 0 ) {
@@ -647,18 +656,19 @@ class BP_Akismet {
647
  }
648
 
649
  /**
650
- * Delete old spam activity meta data
651
  *
652
  * This is done as a clean-up mechanism, as _bp_akismet_submission meta can
653
  * grow to be quite large.
654
  *
655
- * @since BuddyPress (1.6)
656
  *
657
- * @global object $bp BuddyPress global settings.
658
  * @global wpdb $wpdb WordPress database object.
659
  */
660
  function bp_activity_akismet_delete_old_metadata() {
661
- global $bp, $wpdb;
 
 
662
 
663
  /**
664
  * Filters the threshold for how many days old Akismet metadata needs to be before being automatically deleted.
3
  * Akismet support for BuddyPress' Activity Stream.
4
  *
5
  * @package BuddyPress
6
+ * @since BuddyPress (1.6.0)
7
  * @subpackage Activity
8
  */
9
 
13
  /**
14
  * Akismet support for the Activity component.
15
  *
16
+ * @since BuddyPress (1.6.0)
17
+ * @since BuddyPress (2.3.0) We only support Akismet 3+.
18
  */
19
  class BP_Akismet {
20
  /**
22
  *
23
  * @access protected
24
  * @var BP_Activity_Activity
25
+ * @since BuddyPress (1.6.0)
26
  */
27
  protected $last_activity = null;
28
 
29
  /**
30
  * Constructor.
31
  *
32
+ * @since BuddyPress (1.6.0)
33
  */
34
  public function __construct() {
35
  $this->setup_actions();
38
  /**
39
  * Hook Akismet into the activity stream.
40
  *
41
+ * @since BuddyPress (1.6.0)
42
  */
43
  protected function setup_actions() {
44
  // Add nonces to activity stream lists
70
  * This function lifted with love from the Akismet WordPress plugin's
71
  * akismet_comment_row_action() function. Thanks!
72
  *
73
+ * @since BuddyPress (1.6.0)
74
  *
75
+ * @param array $actions The hover links.
76
  * @param array $activity The activity for the current row being processed.
77
+ *
78
  * @return array The hover links.
79
  */
80
  function comment_row_action( $actions, $activity ) {
131
  * the reply form of each activity item. The nonces are, in turn, used
132
  * by Akismet to help detect spam activity.
133
  *
134
+ * @since BuddyPress (1.6.0)
135
  *
136
+ * @see https://plugins.trac.wordpress.org/ticket/1232
137
  */
138
  public function add_activity_stream_nonce() {
139
  $form_id = '_bp_as_nonce';
160
  * This can't be done in BP_Akismet::check_activity() due to the
161
  * default AJAX implementation; see bp_dtheme_post_update().
162
  *
163
+ * @since BuddyPress (1.6.0)
164
  *
165
  * @see bp_dtheme_post_update()
166
  *
167
+ * @param string $content Activity update text.
168
+ * @param int $user_id User ID.
169
+ * @param int $activity_id Activity ID.
170
  */
171
  public function check_member_activity_update( $content, $user_id, $activity_id ) {
172
  // By default, only handle activity updates and activity comments.
186
  *
187
  * This function is intended to be used inside the activity stream loop.
188
  *
189
+ * @since BuddyPress (1.6.0)
190
  */
191
  public function add_activity_spam_button() {
192
  if ( !bp_activity_user_can_mark_spam() )
214
  *
215
  * This function is intended to be used inside the activity stream loop.
216
  *
217
+ * @since BuddyPress (1.6.0)
218
  */
219
  public function add_activity_comment_spam_button() {
220
  if ( !bp_activity_user_can_mark_spam() )
241
  /**
242
  * Get a filterable list of activity types that Akismet should automatically check for spam.
243
  *
244
+ * @since BuddyPress (1.6.0)
245
  *
246
  * @static
247
  *
262
  /**
263
  * Mark activity item as spam.
264
  *
265
+ * @since BuddyPress (1.6.0)
266
  *
267
+ * @param BP_Activity_Activity $activity Activity item being spammed.
268
+ * @param string $source Either "by_a_person" (e.g. a person has
269
+ * manually marked the activity as spam) or
270
+ * "by_akismet" (automatically spammed).
271
  */
272
  public function mark_as_spam( $activity, $source ) {
273
  // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update()
279
  * @since BuddyPress (1.6.0)
280
  *
281
  * @param BP_Activity_Activity $activity Activity object being marked as spam.
282
+ * @param string $source Source of the whom marked as spam.
283
+ * Either "by_a_person" (e.g. a person has
284
+ * manually marked the activity as spam)
285
+ * or "by_akismet".
286
  */
287
  do_action( 'bp_activity_akismet_mark_as_spam', $activity, $source );
288
  }
290
  /**
291
  * Mark activity item as ham.
292
  *
293
+ * @since BuddyPress (1.6.0)
294
  *
295
+ * @param BP_Activity_Activity $activity Activity item being hammed.
296
+ * @param string $source Either "by_a_person" (e.g. a person has
297
+ * manually marked the activity as ham) or
298
+ * "by_akismet" (automatically hammed).
299
  */
300
  public function mark_as_ham( $activity, $source ) {
301
  // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
308
  * @since BuddyPress (1.6.0)
309
  *
310
  * @param BP_Activity_Activity $activity Activity object being marked as ham.
311
+ * @param string $source Source of the whom marked as ham.
312
+ * Either "by_a_person" (e.g. a person has
313
+ * manually marked the activity as ham) or
314
+ * "by_akismet" (automatically hammed).
315
  */
316
  do_action( 'bp_activity_akismet_mark_as_ham', $activity, $source );
317
  }
319
  /**
320
  * Build a data package for the Akismet service to inspect.
321
  *
322
+ * @since BuddyPress (1.6.0)
323
  *
324
  * @see http://akismet.com/development/api/#comment-check
325
  * @static
326
  *
327
  * @param BP_Activity_Activity $activity Activity item data.
328
+ *
329
+ * @return array
330
  */
331
  public static function build_akismet_data_package( $activity ) {
332
  $userdata = get_userdata( $activity->user_id );
340
  $activity_data['comment_type'] = $activity->type;
341
  $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity );
342
  $activity_data['user_ID'] = $userdata->ID;
343
+ $activity_data['user_role'] = Akismet::get_user_roles( $userdata->ID );
344
 
345
  /**
346
  * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
361
  *
362
  * @since BuddyPress (1.6.0)
363
  *
364
+ * @param array $activity_data Array of activity data for Akismet to inspect.
365
+ * @param BP_Activity_Activity $activity Activity item data.
366
  */
367
  return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity );
368
  }
370
  /**
371
  * Check if the activity item is spam or ham.
372
  *
373
+ * @since BuddyPress (1.6.0)
374
  *
375
  * @see http://akismet.com/development/api/
376
  * @todo Spam counter?
405
  *
406
  * @since BuddyPress (1.6.0)
407
  *
408
+ * @param BP_Activity_Activity $activity The activity item proven to be spam.
409
+ * @param array $activity_data Array of activity data for item including
410
+ * Akismet check results data.
411
  */
412
  do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
413
 
422
  /**
423
  * Update activity meta after a manual spam change (user-initiated).
424
  *
425
+ * @since BuddyPress (1.6.0)
426
  *
427
  * @param BP_Activity_Activity $activity The activity to check.
428
  */
439
  /**
440
  * Update activity meta after a manual ham change (user-initiated).
441
  *
442
+ * @since BuddyPress (1.6.0)
443
  *
444
  * @param BP_Activity_Activity $activity The activity to check.
445
  */
456
  /**
457
  * Update activity meta after an automatic spam check (not user-initiated).
458
  *
459
+ * @since BuddyPress (1.6.0)
460
  *
461
  * @param BP_Activity_Activity $activity The activity to check.
462
  */
494
  *
495
  * Props to WordPress core Akismet plugin for a lot of this.
496
  *
497
+ * @since BuddyPress (1.6.0)
498
  *
499
+ * @param array $activity_data Packet of information to submit to Akismet.
500
+ * @param string $check "check" or "submit".
501
+ * @param string $spam "spam" or "ham".
502
  *
 
 
 
503
  * @return array $activity_data Activity data, with Akismet data added.
504
  */
505
  public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
 
 
 
 
 
 
506
  $query_string = $path = '';
507
 
508
  $activity_data['blog'] = bp_get_option( 'home' );
512
  $activity_data['user_agent'] = bp_core_current_user_ua();
513
  $activity_data['user_ip'] = bp_core_current_user_ip();
514
 
515
+ if ( Akismet::is_test_mode() )
516
  $activity_data['is_test'] = 'true';
517
 
518
  // Loop through _POST args and rekey strings
540
  $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
541
 
542
  if ( 'check' == $check )
543
+ $path = 'comment-check';
544
  elseif ( 'submit' == $check )
545
+ $path = 'submit-' . $spam;
546
 
547
  // Send to Akismet
548
  add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
549
+ $response = Akismet::http_post( $query_string, $path );
550
  remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
551
 
552
  // Get the response
565
  /**
566
  * Filters user agent when sending to Akismet to add BuddyPress info.
567
  *
568
+ * @since BuddyPress (1.6.0)
569
  *
570
  * @param string $user_agent User agent string, as generated by Akismet.
571
+ *
572
  * @return string $user_agent Modified user agent string.
573
  */
574
  public function buddypress_ua( $user_agent ) {
579
  /**
580
  * Adds a "History" meta box to the activity edit screen.
581
  *
582
+ * @since BuddyPress (1.6.0)
583
  *
584
  * @param string $screen_action The type of screen that has been requested.
585
  */
595
  /**
596
  * History meta box for the Activity admin edit screen.
597
  *
598
+ * @since BuddyPress (1.6.0)
599
  *
600
+ * @see https://buddypress.trac.wordpress.org/ticket/3907
601
  * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
602
  *
603
  * @param object $item Activity item.
616
  /**
617
  * Update an activity item's Akismet history.
618
  *
619
+ * @since BuddyPress (1.6.0)
620
  *
621
+ * @param int $activity_id Activity item ID.
622
+ * @param string $message Human-readable description of what's changed.
623
+ * @param string $event The type of check we were carrying out.
624
  */
625
  public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) {
626
  $event = array(
627
  'event' => $event,
628
  'message' => $message,
629
+ 'time' => Akismet::_get_microtime(),
630
  'user' => bp_loggedin_user_id(),
631
  );
632
 
637
  /**
638
  * Get an activity item's Akismet history.
639
  *
640
+ * @since BuddyPress (1.6.0)
641
  *
642
  * @param int $activity_id Activity item ID.
643
+ *
644
  * @return array The activity item's Akismet history.
645
  */
646
  public function get_activity_history( $activity_id = 0 ) {
656
  }
657
 
658
  /**
659
+ * Delete old spam activity meta data.
660
  *
661
  * This is done as a clean-up mechanism, as _bp_akismet_submission meta can
662
  * grow to be quite large.
663
  *
664
+ * @since BuddyPress (1.6.0)
665
  *
 
666
  * @global wpdb $wpdb WordPress database object.
667
  */
668
  function bp_activity_akismet_delete_old_metadata() {
669
+ global $wpdb;
670
+
671
+ $bp = buddypress();
672
 
673
  /**
674
  * Filters the threshold for how many days old Akismet metadata needs to be before being automatically deleted.
bp-activity/bp-activity-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * Functions related to the BuddyPress Activity component and the WP Cache.
5
  *
6
- * @since BuddyPress (1.6)
7
  */
8
 
9
  // Exit if accessed directly
@@ -16,11 +16,11 @@ defined( 'ABSPATH' ) || exit;
16
  * in $activity_ids and adds it to the WP cache. This improves efficiency when
17
  * using querying activitymeta inline.
18
  *
19
- * @param int|str|array $activity_ids Accepts a single activity ID, or a comma-
20
- * separated list or array of activity ids
21
  */
22
  function bp_activity_update_meta_cache( $activity_ids = false ) {
23
- global $bp;
24
 
25
  $cache_args = array(
26
  'object_ids' => $activity_ids,
@@ -37,7 +37,7 @@ function bp_activity_update_meta_cache( $activity_ids = false ) {
37
  /**
38
  * Clear a cached activity item when that item is updated.
39
  *
40
- * @since 2.0
41
  *
42
  * @param BP_Activity_Activity $activity
43
  */
@@ -50,7 +50,7 @@ add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' );
50
  /**
51
  * Clear cached data for deleted activity items.
52
  *
53
- * @since 2.0
54
  *
55
  * @param array $deleted_ids IDs of deleted activity items.
56
  */
3
  /**
4
  * Functions related to the BuddyPress Activity component and the WP Cache.
5
  *
6
+ * @since BuddyPress (1.6.0)
7
  */
8
 
9
  // Exit if accessed directly
16
  * in $activity_ids and adds it to the WP cache. This improves efficiency when
17
  * using querying activitymeta inline.
18
  *
19
+ * @param int|string|array|bool $activity_ids Accepts a single activity ID, or a comma-
20
+ * separated list or array of activity ids
21
  */
22
  function bp_activity_update_meta_cache( $activity_ids = false ) {
23
+ $bp = buddypress();
24
 
25
  $cache_args = array(
26
  'object_ids' => $activity_ids,
37
  /**
38
  * Clear a cached activity item when that item is updated.
39
  *
40
+ * @since BuddyPress (2.0.0)
41
  *
42
  * @param BP_Activity_Activity $activity
43
  */
50
  /**
51
  * Clear cached data for deleted activity items.
52
  *
53
+ * @since BuddyPress (2.0.0)
54
  *
55
  * @param array $deleted_ids IDs of deleted activity items.
56
  */
bp-activity/bp-activity-classes.php CHANGED
@@ -9,2382 +9,6 @@
9
  // Exit if accessed directly
10
  defined( 'ABSPATH' ) || exit;
11
 
12
- /**
13
- * Database interaction class for the BuddyPress activity component.
14
- *
15
- * Instance methods are available for creating/editing an activity,
16
- * static methods for querying activities.
17
- *
18
- * @since BuddyPress (1.0)
19
- */
20
- class BP_Activity_Activity {
21
-
22
- /** Properties ************************************************************/
23
-
24
- /**
25
- * ID of the activity item.
26
- *
27
- * @var int
28
- */
29
- var $id;
30
-
31
- /**
32
- * ID of the associated item.
33
- *
34
- * @var int
35
- */
36
- var $item_id;
37
-
38
- /**
39
- * ID of the associated secondary item.
40
- *
41
- * @var int
42
- */
43
- var $secondary_item_id;
44
-
45
- /**
46
- * ID of user associated with the activity item.
47
- *
48
- * @var int
49
- */
50
- var $user_id;
51
-
52
- /**
53
- * The primary URL for the activity in RSS feeds.
54
- *
55
- * @var string
56
- */
57
- var $primary_link;
58
-
59
- /**
60
- * BuddyPress component the activity item relates to.
61
- *
62
- * @var string
63
- */
64
- var $component;
65
-
66
- /**
67
- * Activity type, eg 'new_blog_post'.
68
- *
69
- * @var string
70
- */
71
- var $type;
72
-
73
- /**
74
- * Description of the activity, eg 'Alex updated his profile.'
75
- *
76
- * @var string
77
- */
78
- var $action;
79
-
80
- /**
81
- * The content of the activity item.
82
- *
83
- * @var string
84
- */
85
- var $content;
86
-
87
- /**
88
- * The date the activity item was recorded, in 'Y-m-d h:i:s' format.
89
- *
90
- * @var string
91
- */
92
- var $date_recorded;
93
-
94
- /**
95
- * Whether the item should be hidden in sitewide streams.
96
- *
97
- * @var int
98
- */
99
- var $hide_sitewide = false;
100
-
101
- /**
102
- * Node boundary start for activity or activity comment.
103
- *
104
- * @var int
105
- */
106
- var $mptt_left;
107
-
108
- /**
109
- * Node boundary end for activity or activity comment.
110
- *
111
- * @var int
112
- */
113
- var $mptt_right;
114
-
115
- /**
116
- * Whether this item is marked as spam.
117
- *
118
- * @var int
119
- */
120
- var $is_spam;
121
-
122
- /**
123
- * Constructor method.
124
- *
125
- * @param int $id Optional. The ID of a specific activity item.
126
- */
127
- public function __construct( $id = false ) {
128
- if ( !empty( $id ) ) {
129
- $this->id = $id;
130
- $this->populate();
131
- }
132
- }
133
-
134
- /**
135
- * Populate the object with data about the specific activity item.
136
- */
137
- public function populate() {
138
- global $wpdb;
139
-
140
- $row = wp_cache_get( $this->id, 'bp_activity' );
141
-
142
- if ( false === $row ) {
143
- $bp = buddypress();
144
- $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
145
-
146
- wp_cache_set( $this->id, $row, 'bp_activity' );
147
- }
148
-
149
- if ( ! empty( $row ) ) {
150
- $this->id = (int) $row->id;
151
- $this->item_id = (int) $row->item_id;
152
- $this->secondary_item_id = (int) $row->secondary_item_id;
153
- $this->user_id = (int) $row->user_id;
154
- $this->primary_link = $row->primary_link;
155
- $this->component = $row->component;
156
- $this->type = $row->type;
157
- $this->action = $row->action;
158
- $this->content = $row->content;
159
- $this->date_recorded = $row->date_recorded;
160
- $this->hide_sitewide = $row->hide_sitewide;
161
- $this->mptt_left = (int) $row->mptt_left;
162
- $this->mptt_right = (int) $row->mptt_right;
163
- $this->is_spam = $row->is_spam;
164
- }
165
-
166
- // Generate dynamic 'action' when possible
167
- $action = bp_activity_generate_action_string( $this );
168
- if ( false !== $action ) {
169
- $this->action = $action;
170
-
171
- // If no callback is available, use the literal string from
172
- // the database row
173
- } elseif ( ! empty( $row->action ) ) {
174
- $this->action = $row->action;
175
-
176
- // Provide a fallback to avoid PHP notices
177
- } else {
178
- $this->action = '';
179
- }
180
- }
181
-
182
- /**
183
- * Save the activity item to the database.
184
- *
185
- * @return bool True on success.
186
- */
187
- public function save() {
188
- global $wpdb;
189
-
190
- $bp = buddypress();
191
-
192
- $this->id = apply_filters_ref_array( 'bp_activity_id_before_save', array( $this->id, &$this ) );
193
- $this->item_id = apply_filters_ref_array( 'bp_activity_item_id_before_save', array( $this->item_id, &$this ) );
194
- $this->secondary_item_id = apply_filters_ref_array( 'bp_activity_secondary_item_id_before_save', array( $this->secondary_item_id, &$this ) );
195
- $this->user_id = apply_filters_ref_array( 'bp_activity_user_id_before_save', array( $this->user_id, &$this ) );
196
- $this->primary_link = apply_filters_ref_array( 'bp_activity_primary_link_before_save', array( $this->primary_link, &$this ) );
197
- $this->component = apply_filters_ref_array( 'bp_activity_component_before_save', array( $this->component, &$this ) );
198
- $this->type = apply_filters_ref_array( 'bp_activity_type_before_save', array( $this->type, &$this ) );
199
- $this->action = apply_filters_ref_array( 'bp_activity_action_before_save', array( $this->action, &$this ) );
200
- $this->content = apply_filters_ref_array( 'bp_activity_content_before_save', array( $this->content, &$this ) );
201
- $this->date_recorded = apply_filters_ref_array( 'bp_activity_date_recorded_before_save', array( $this->date_recorded, &$this ) );
202
- $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide, &$this ) );
203
- $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) );
204
- $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) );
205
- $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam, &$this ) );
206
-
207
- /**
208
- * Fires before the current activity item gets saved.
209
- *
210
- * Please use this hook to filter the properties above. Each part will be passed in.
211
- *
212
- * @since BuddyPress (1.0.0)
213
- *
214
- * @param BP_Activity_Activity Current instance of the activity item being saved.
215
- */
216
- do_action_ref_array( 'bp_activity_before_save', array( &$this ) );
217
-
218
- if ( empty( $this->component ) || empty( $this->type ) ) {
219
- return false;
220
- }
221
-
222
- if ( empty( $this->primary_link ) ) {
223
- $this->primary_link = bp_loggedin_user_domain();
224
- }
225
-
226
- // If we have an existing ID, update the activity item, otherwise insert it.
227
- if ( ! empty( $this->id ) ) {
228
- $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %d, secondary_item_id = %d, hide_sitewide = %d, is_spam = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam, $this->id );
229
- } else {
230
- $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide, is_spam ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %d, %d, %d, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->is_spam );
231
- }
232
-
233
- if ( false === $wpdb->query( $q ) ) {
234
- return false;
235
- }
236
-
237
- // If this is a new activity item, set the $id property
238
- if ( empty( $this->id ) ) {
239
- $this->id = $wpdb->insert_id;
240
-
241
- // If an existing activity item, prevent any changes to the content generating new @mention notifications.
242
- } else {
243
- add_filter( 'bp_activity_at_name_do_notifications', '__return_false' );
244
- }
245
-
246
- /**
247
- * Fires after an activity item has been saved to the database.
248
- *
249
- * @since BuddyPress (1.0.0)
250
- *
251
- * @param BP_Activity_Activity Reference to current instance of activity being saved.
252
- */
253
- do_action_ref_array( 'bp_activity_after_save', array( &$this ) );
254
-
255
- return true;
256
- }
257
-
258
- /** Static Methods ***************************************************/
259
-
260
- /**
261
- * Get activity items, as specified by parameters
262
- *
263
- * @see BP_Activity_Activity::get_filter_sql() for a description of the
264
- * 'filter' parameter.
265
- * @see WP_Meta_Query::queries for a description of the 'meta_query'
266
- * parameter format.
267
- *
268
- * @param array $args {
269
- * An array of arguments. All items are optional.
270
- *
271
- * @type int $page Which page of results to fetch. Using page=1 without per_page will result
272
- * in no pagination. Default: 1.
273
- * @type int|bool $per_page Number of results per page. Default: 25.
274
- * @type int|bool $max Maximum number of results to return. Default: false (unlimited).
275
- * @type string $sort ASC or DESC. Default: 'DESC'.
276
- * @type array $exclude Array of activity IDs to exclude. Default: false.
277
- * @type array $in Array of ids to limit query by (IN). Default: false.
278
- * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries.
279
- * @type array $date_query Array of date_query conditions. See first parameter of
280
- * WP_Date_Query::__construct().
281
- * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct().
282
- * @type string|array $scope Pre-determined set of activity arguments.
283
- * @type array $filter See BP_Activity_Activity::get_filter_sql().
284
- * @type string $search_terms Limit results by a search term. Default: false.
285
- * @type bool $display_comments Whether to include activity comments. Default: false.
286
- * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false.
287
- * @type string $spam Spam status. Default: 'ham_only'.
288
- * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true.
289
- * @type string|bool $count_total If true, an additional DB query is run to count the total activity items
290
- * for the query. Default: false.
291
- * }
292
- * @return array The array returned has two keys:
293
- * - 'total' is the count of located activities
294
- * - 'activities' is an array of the located activities
295
- */
296
- public static function get( $args = array() ) {
297
- global $wpdb;
298
-
299
- // Backward compatibility with old method of passing arguments
300
- if ( !is_array( $args ) || func_num_args() > 1 ) {
301
- _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
302
-
303
- $old_args_keys = array(
304
- 0 => 'max',
305
- 1 => 'page',
306
- 2 => 'per_page',
307
- 3 => 'sort',
308
- 4 => 'search_terms',
309
- 5 => 'filter',
310
- 6 => 'display_comments',
311
- 7 => 'show_hidden',
312
- 8 => 'exclude',
313
- 9 => 'in',
314
- 10 => 'spam'
315
- );
316
-
317
- $func_args = func_get_args();
318
- $args = bp_core_parse_args_array( $old_args_keys, $func_args );
319
- }
320
-
321
- $bp = buddypress();
322
- $r = wp_parse_args( $args, array(
323
- 'page' => 1, // The current page
324
- 'per_page' => 25, // Activity items per page
325
- 'max' => false, // Max number of items to return
326
- 'sort' => 'DESC', // ASC or DESC
327
- 'exclude' => false, // Array of ids to exclude
328
- 'in' => false, // Array of ids to limit query by (IN)
329
- 'meta_query' => false, // Filter by activitymeta
330
- 'date_query' => false, // Filter by date
331
- 'filter_query' => false, // Advanced filtering - see BP_Activity_Query
332
- 'filter' => false, // See self::get_filter_sql()
333
- 'scope' => false, // Preset activity arguments
334
- 'search_terms' => false, // Terms to search by
335
- 'display_comments' => false, // Whether to include activity comments
336
- 'show_hidden' => false, // Show items marked hide_sitewide
337
- 'spam' => 'ham_only', // Spam status
338
- 'update_meta_cache' => true,
339
- 'count_total' => false,
340
- ) );
341
-
342
- // Select conditions
343
- $select_sql = "SELECT DISTINCT a.id";
344
-
345
- $from_sql = " FROM {$bp->activity->table_name} a";
346
-
347
- $join_sql = '';
348
-
349
- // Where conditions
350
- $where_conditions = array();
351
-
352
- // Excluded types
353
- $excluded_types = array();
354
-
355
- // Scope takes precedence
356
- if ( ! empty( $r['scope'] ) ) {
357
- $scope_query = self::get_scope_query_sql( $r['scope'], $r );
358
-
359
- // Add our SQL conditions if matches were found
360
- if ( ! empty( $scope_query['sql'] ) ) {
361
- $where_conditions['scope_query_sql'] = $scope_query['sql'];
362
- }
363
-
364
- // override some arguments if needed
365
- if ( ! empty( $scope_query['override'] ) ) {
366
- $r = self::array_replace_recursive( $r, $scope_query['override'] );
367
- }
368
-
369
- // Advanced filtering
370
- } elseif ( ! empty( $r['filter_query'] ) ) {
371
- $filter_query = new BP_Activity_Query( $r['filter_query'] );
372
- $sql = $filter_query->get_sql();
373
- if ( ! empty( $sql ) ) {
374
- $where_conditions['filter_query_sql'] = $sql;
375
- }
376
- }
377
-
378
- // Regular filtering
379
- if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) {
380
- $where_conditions['filter_sql'] = $filter_sql;
381
- }
382
-
383
- // Spam
384
- if ( 'ham_only' == $r['spam'] ) {
385
- $where_conditions['spam_sql'] = 'a.is_spam = 0';
386
- } elseif ( 'spam_only' == $r['spam'] ) {
387
- $where_conditions['spam_sql'] = 'a.is_spam = 1';
388
- }
389
-
390
- // Searching
391
- if ( $r['search_terms'] ) {
392
- $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%';
393
- $where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like );
394
- }
395
-
396
- // Sorting
397
- $sort = $r['sort'];
398
- if ( $sort != 'ASC' && $sort != 'DESC' ) {
399
- $sort = 'DESC';
400
- }
401
-
402
- // Hide Hidden Items?
403
- if ( ! $r['show_hidden'] ) {
404
- $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
405
- }
406
-
407
- // Exclude specified items
408
- if ( ! empty( $r['exclude'] ) ) {
409
- $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) );
410
- $where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
411
- }
412
-
413
- // The specific ids to which you want to limit the query
414
- if ( ! empty( $r['in'] ) ) {
415
- $in = implode( ',', wp_parse_id_list( $r['in'] ) );
416
- $where_conditions['in'] = "a.id IN ({$in})";
417
- }
418
-
419
- // Process meta_query into SQL
420
- $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
421
-
422
- if ( ! empty( $meta_query_sql['join'] ) ) {
423
- $join_sql .= $meta_query_sql['join'];
424
- }
425
-
426
- if ( ! empty( $meta_query_sql['where'] ) ) {
427
- $where_conditions[] = $meta_query_sql['where'];
428
- }
429
-
430
- // Process date_query into SQL
431
- $date_query_sql = self::get_date_query_sql( $r['date_query'] );
432
-
433
- if ( ! empty( $date_query_sql ) ) {
434
- $where_conditions['date'] = $date_query_sql;
435
- }
436
-
437
- // Alter the query based on whether we want to show activity item
438
- // comments in the stream like normal comments or threaded below
439
- // the activity.
440
- if ( false === $r['display_comments'] || 'threaded' === $r['display_comments'] ) {
441
- $excluded_types[] = 'activity_comment';
442
- }
443
-
444
- // Exclude 'last_activity' items unless the 'action' filter has
445
- // been explicitly set
446
- if ( empty( $r['filter']['object'] ) ) {
447
- $excluded_types[] = 'last_activity';
448
- }
449
-
450
- // Build the excluded type sql part
451
- if ( ! empty( $excluded_types ) ) {
452
- $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
453
- $where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})";
454
- }
455
-
456
- /**
457
- * Filters the MySQL WHERE conditions for the Activity items get method.
458
- *
459
- * @since BuddyPress (1.9.0)
460
- *
461
- * @param array $where_conditions Current conditions for MySQL WHERE statement.
462
- * @param array $r Parsed arguments passed into method.
463
- * @param string $select_sql Current SELECT MySQL statement at point of execution.
464
- * @param string $from_sql Current FROM MySQL statement at point of execution.
465
- * @param string $join_sql Current INNER JOIN MySQL statement at point of execution.
466
- */
467
- $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql );
468
-
469
- // Join the where conditions together
470
- $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
471
-
472
- /**
473
- * Filters the preferred order of indexes for activity item.
474
- *
475
- * @since BuddyPress (1.6.0)
476
- *
477
- * @param array Array of indexes in preferred order.
478
- */
479
- $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) );
480
-
481
- foreach( $indexes as $key => $index ) {
482
- if ( false !== strpos( $where_sql, $index ) ) {
483
- $the_index = $index;
484
- break; // Take the first one we find
485
- }
486
- }
487
-
488
- if ( !empty( $the_index ) ) {
489
- $index_hint_sql = "USE INDEX ({$the_index})";
490
- } else {
491
- $index_hint_sql = '';
492
- }
493
-
494
- // Sanitize page and per_page parameters
495
- $page = absint( $r['page'] );
496
- $per_page = absint( $r['per_page'] );
497
-
498
- $retval = array(
499
- 'activities' => null,
500
- 'total' => null,
501
- 'has_more_items' => null,
502
- );
503
-
504
- /**
505
- * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+.
506
- *
507
- * It is not recommended to use the legacy structure, but allowed to if needed.
508
- *
509
- * @since BuddyPress (2.0.0)
510
- *
511
- * @param bool Whether to use legacy structure or not.
512
- * @param BP_Activity_Activity Current method being called.
513
- * @param array $r Parsed arguments passed into method.
514
- */
515
- if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
516
-
517
- // Legacy queries joined against the user table
518
- $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
519
- $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
520
-
521
- if ( ! empty( $page ) && ! empty( $per_page ) ) {
522
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
523
-
524
- /** this filter is documented in bp-activity/bp-activity-classes.php */
525
- $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
526
- } else {
527
- $pag_sql = '';
528
-
529
- /**
530
- * Filters the legacy MySQL query statement so plugins can alter before results are fetched.
531
- *
532
- * @since BuddyPress (1.5.0)
533
- *
534
- * @param string Concatenated MySQL statement pieces to be query results with for legacy query.
535
- * @param string $select_sql Final SELECT MySQL statement portion for legacy query.
536
- * @param string $from_sql Final FROM MySQL statement portion for legacy query.
537
- * @param string $where_sql Final WHERE MySQL statement portion for legacy query.
538
- * @param string $sort Final sort direction for legacy query.
539
- */
540
- $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
541
- }
542
-
543
- } else {
544
- // Query first for activity IDs
545
- $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
546
-
547
- if ( ! empty( $per_page ) && ! empty( $page ) ) {
548
- // We query for $per_page + 1 items in order to
549
- // populate the has_more_items flag
550
- $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );
551
- }
552
-
553
- /**
554
- * Filters the paged activities MySQL statement.
555
- *
556
- * @since BuddyPress (2.0.0)
557
- *
558
- * @param string $activity_ids_sql MySQL statement used to query for Activity IDs.
559
- * @param array $r Array of arguments passed into method.
560
- */
561
- $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
562
-
563
- $activity_ids = $wpdb->get_col( $activity_ids_sql );
564
-
565
- $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page;
566
-
567
- // If we've fetched more than the $per_page value, we
568
- // can discard the extra now
569
- if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) {
570
- array_pop( $activity_ids );
571
- }
572
-
573
- $activities = self::get_activity_data( $activity_ids );
574
- }
575
-
576
- // Get the fullnames of users so we don't have to query in the loop
577
- $activities = self::append_user_fullnames( $activities );
578
-
579
- // Get activity meta
580
- $activity_ids = array();
581
- foreach ( (array) $activities as $activity ) {
582
- $activity_ids[] = $activity->id;
583
- }
584
-
585
- if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) {
586
- bp_activity_update_meta_cache( $activity_ids );
587
- }
588
-
589
- if ( $activities && $r['display_comments'] ) {
590
- $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] );
591
- }
592
-
593
- // Pre-fetch data associated with activity users and other objects
594
- BP_Activity_Activity::prefetch_object_data( $activities );
595
-
596
- // Generate action strings
597
- $activities = BP_Activity_Activity::generate_action_strings( $activities );
598
-
599
- $retval['activities'] = $activities;
600
-
601
- // If $max is set, only return up to the max results
602
- if ( ! empty( $r['count_total'] ) ) {
603
-
604
- /**
605
- * Filters the total activities MySQL statement.
606
- *
607
- * @since BuddyPress (1.5.0)
608
- *
609
- * @param string MySQL statement used to query for total activities.
610
- * @param string $where_sql MySQL WHERE statement portion.
611
- * @param string $sort sort direction for query.
612
- */
613
- $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
614
- $total_activities = $wpdb->get_var( $total_activities_sql );
615
-
616
- if ( !empty( $r['max'] ) ) {
617
- if ( (int) $total_activities > (int) $r['max'] ) {
618
- $total_activities = $r['max'];
619
- }
620
- }
621
-
622
- $retval['total'] = $total_activities;
623
- }
624
-
625
- return $retval;
626
- }
627
-
628
- /**
629
- * Convert activity IDs to activity objects, as expected in template loop.
630
- *
631
- * @since 2.0
632
- *
633
- * @param array $activity_ids Array of activity IDs.
634
- * @return array
635
- */
636
- protected static function get_activity_data( $activity_ids = array() ) {
637
- global $wpdb;
638
-
639
- // Bail if no activity ID's passed
640
- if ( empty( $activity_ids ) ) {
641
- return array();
642
- }
643
-
644
- // Get BuddyPress
645
- $bp = buddypress();
646
-
647
- $activities = array();
648
- $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' );
649
-
650
- // Prime caches as necessary
651
- if ( ! empty( $uncached_ids ) ) {
652
- // Format the activity ID's for use in the query below
653
- $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
654
-
655
- // Fetch data from activity table, preserving order
656
- $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})");
657
-
658
- // Put that data into the placeholders created earlier,
659
- // and add it to the cache
660
- foreach ( (array) $queried_adata as $adata ) {
661
- wp_cache_set( $adata->id, $adata, 'bp_activity' );
662
- }
663
- }
664
-
665
- // Now fetch data from the cache
666
- foreach ( $activity_ids as $activity_id ) {
667
- $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
668
- }
669
-
670
- // Then fetch user data
671
- $user_query = new BP_User_Query( array(
672
- 'user_ids' => wp_list_pluck( $activities, 'user_id' ),
673
- 'populate_extras' => false,
674
- ) );
675
-
676
- // Associated located user data with activity items
677
- foreach ( $activities as $a_index => $a_item ) {
678
- $a_user_id = intval( $a_item->user_id );
679
- $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : '';
680
-
681
- if ( !empty( $a_user ) ) {
682
- $activities[ $a_index ]->user_email = $a_user->user_email;
683
- $activities[ $a_index ]->user_nicename = $a_user->user_nicename;
684
- $activities[ $a_index ]->user_login = $a_user->user_login;
685
- $activities[ $a_index ]->display_name = $a_user->display_name;
686
- }
687
- }
688
-
689
- return $activities;
690
- }
691
-
692
- /**
693
- * Append xProfile fullnames to an activity array.
694
- *
695
- * @since BuddyPress (2.0.0)
696
- *
697
- * @param array $activities Activities array.
698
- * @return array
699
- */
700
- protected static function append_user_fullnames( $activities ) {
701
-
702
- if ( bp_is_active( 'xprofile' ) && ! empty( $activities ) ) {
703
- $activity_user_ids = wp_list_pluck( $activities, 'user_id' );
704
-
705
- if ( ! empty( $activity_user_ids ) ) {
706
- $fullnames = bp_core_get_user_displaynames( $activity_user_ids );
707
- if ( ! empty( $fullnames ) ) {
708
- foreach ( (array) $activities as $i => $activity ) {
709
- if ( ! empty( $fullnames[ $activity->user_id ] ) ) {
710
- $activities[ $i ]->user_fullname = $fullnames[ $activity->user_id ];
711
- }
712
- }
713
- }
714
- }
715
- }
716
-
717
- return $activities;
718
- }
719
-
720
- /**
721
- * Pre-fetch data for objects associated with activity items.
722
- *
723
- * Activity items are associated with users, and often with other
724
- * BuddyPress data objects. Here, we pre-fetch data about these
725
- * associated objects, so that inline lookups - done primarily when
726
- * building action strings - do not result in excess database queries.
727
- *
728
- * The only object data required for activity component activity types
729
- * (activity_update and activity_comment) is related to users, and that
730
- * info is fetched separately in BP_Activity_Activity::get_activity_data().
731
- * So this method contains nothing but a filter that allows other
732
- * components, such as bp-friends and bp-groups, to hook in and prime
733
- * their own caches at the beginning of an activity loop.
734
- *
735
- * @since BuddyPress (2.0.0)
736
- *
737
- * @param array $activities Array of activities.
738
- */
739
- protected static function prefetch_object_data( $activities ) {
740
-
741
- /**
742
- * Filters inside prefetch_object_data method to aid in pre-fetching object data associated with activity item.
743
- *
744
- * @since BuddyPress (2.0.0)
745
- *
746
- * @param array $activities Array of activities.
747
- */
748
- return apply_filters( 'bp_activity_prefetch_object_data', $activities );
749
- }
750
-
751
- /**
752
- * Generate action strings for the activities located in BP_Activity_Activity::get().
753
- *
754
- * If no string can be dynamically generated for a given item
755
- * (typically because the activity type has not been properly
756
- * registered), the static 'action' value pulled from the database will
757
- * be left in place.
758
- *
759
- * @since BuddyPress (2.0.0)
760
- *
761
- * @param array $activities Array of activities.
762
- * @return array
763
- */
764
- protected static function generate_action_strings( $activities ) {
765
- foreach ( $activities as $key => $activity ) {
766
- $generated_action = bp_activity_generate_action_string( $activity );
767
- if ( false !== $generated_action ) {
768
- $activity->action = $generated_action;
769
- }
770
-
771
- $activities[ $key ] = $activity;
772
- }
773
-
774
- return $activities;
775
- }
776
-
777
- /**
778
- * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().
779
- *
780
- * We use WP_Meta_Query to do the heavy lifting of parsing the
781
- * meta_query array and creating the necessary SQL clauses. However,
782
- * since BP_Activity_Activity::get() builds its SQL differently than
783
- * WP_Query, we have to alter the return value (stripping the leading
784
- * AND keyword from the 'where' clause).
785
- *
786
- * @since BuddyPress (1.8)
787
- *
788
- * @param array $meta_query An array of meta_query filters. See the
789
- * documentation for WP_Meta_Query for details.
790
- * @return array $sql_array 'join' and 'where' clauses.
791
- */
792
- public static function get_meta_query_sql( $meta_query = array() ) {
793
- global $wpdb;
794
-
795
- $sql_array = array(
796
- 'join' => '',
797
- 'where' => '',
798
- );
799
-
800
- if ( ! empty( $meta_query ) ) {
801
- $activity_meta_query = new WP_Meta_Query( $meta_query );
802
-
803
- // WP_Meta_Query expects the table name at
804
- // $wpdb->activitymeta
805
- $wpdb->activitymeta = buddypress()->activity->table_name_meta;
806
-
807
- $meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' );
808
-
809
- // Strip the leading AND - BP handles it in get()
810
- $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
811
- $sql_array['join'] = $meta_sql['join'];
812
- }
813
-
814
- return $sql_array;
815
- }
816
-
817
- /**
818
- * Get the SQL for the 'date_query' param in BP_Activity_Activity::get().
819
- *
820
- * We use BP_Date_Query, which extends WP_Date_Query, to do the heavy lifting
821
- * of parsing the date_query array and creating the necessary SQL clauses.
822
- * However, since BP_Activity_Activity::get() builds its SQL differently than
823
- * WP_Query, we have to alter the return value (stripping the leading AND
824
- * keyword from the query).
825
- *
826
- * @since BuddyPress (2.1.0)
827
- *
828
- * @param array $date_query An array of date_query parameters. See the
829
- * documentation for the first parameter of WP_Date_Query.
830
- * @return string
831
- */
832
- public static function get_date_query_sql( $date_query = array() ) {
833
- $sql = '';
834
-
835
- // Date query
836
- if ( ! empty( $date_query ) && is_array( $date_query ) && class_exists( 'BP_Date_Query' ) ) {
837
- $date_query = new BP_Date_Query( $date_query, 'date_recorded' );
838
- $sql = preg_replace( '/^\sAND/', '', $date_query->get_sql() );
839
- }
840
-
841
- return $sql;
842
- }
843
-
844
- /**
845
- * Get the SQL for the 'scope' param in BP_Activity_Activity::get().
846
- *
847
- * A scope is a predetermined set of activity arguments. This method is used
848
- * to grab these activity arguments and override any existing args if needed.
849
- *
850
- * Can handle multiple scopes.
851
- *
852
- * @since BuddyPress (2.2.0)
853
- *
854
- * @param mixed $scope The activity scope. Accepts string or array of scopes
855
- * @param array $r Current activity arguments. Same as those of BP_Activity_Activity::get(),
856
- * but merged with defaults.
857
- * @return array 'sql' WHERE SQL string and 'override' activity args
858
- */
859
- public static function get_scope_query_sql( $scope = false, $r = array() ) {
860
-
861
- // Define arrays for future use
862
- $query_args = array();
863
- $override = array();
864
- $retval = array();
865
-
866
- // Check for array of scopes
867
- if ( is_array( $scope ) ) {
868
- $scopes = $scope;
869
-
870
- // Explode a comma separated string of scopes
871
- } elseif ( is_string( $scope ) ) {
872
- $scopes = explode( ',', $scope );
873
- }
874
-
875
- // Bail if no scope passed
876
- if ( empty( $scopes ) ) {
877
- return false;
878
- }
879
-
880
- // Helper to easily grab the 'user_id'
881
- if ( ! empty( $r['filter']['user_id'] ) ) {
882
- $r['user_id'] = $r['filter']['user_id'];
883
- }
884
-
885
- // parse each scope; yes! we handle multiples!
886
- foreach ( $scopes as $scope ) {
887
- $scope_args = array();
888
-
889
- /**
890
- * Plugins can hook here to set their activity arguments for custom scopes.
891
- *
892
- * This is a dynamic filter based on the activity scope. eg:
893
- * - 'bp_activity_set_groups_scope_args'
894
- * - 'bp_activity_set_friends_scope_args'
895
- *
896
- * To see how this filter is used, plugin devs should check out:
897
- * - bp_groups_filter_activity_scope() - used for 'groups' scope
898
- * - bp_friends_filter_activity_scope() - used for 'friends' scope
899
- *
900
- * @since BuddyPress (2.2.0)
901
- *
902
- * @param array {
903
- * Activity query clauses.
904
- *
905
- * @type array {
906
- * Activity arguments for your custom scope.
907
- * See {@link BP_Activity_Query::_construct()} for more details.
908
- * }
909
- * @type array $override Optional. Override existing activity arguments passed by $r.
910
- * }
911
- * @param array $r Current activity arguments passed in BP_Activity_Activity::get()
912
- */
913
- $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r );
914
-
915
- if ( ! empty( $scope_args ) ) {
916
- // merge override properties from other scopes
917
- // this might be a problem...
918
- if ( ! empty( $scope_args['override'] ) ) {
919
- $override = array_merge( $override, $scope_args['override'] );
920
- unset( $scope_args['override'] );
921
- }
922
-
923
- // save scope args
924
- if ( ! empty( $scope_args ) ) {
925
- $query_args[] = $scope_args;
926
- }
927
- }
928
- }
929
-
930
- if ( ! empty( $query_args ) ) {
931
- // set relation to OR
932
- $query_args['relation'] = 'OR';
933
-
934
- $query = new BP_Activity_Query( $query_args );
935
- $sql = $query->get_sql();
936
- if ( ! empty( $sql ) ) {
937
- $retval['sql'] = $sql;
938
- }
939
- }
940
-
941
- if ( ! empty( $override ) ) {
942
- $retval['override'] = $override;
943
- }
944
-
945
- return $retval;
946
- }
947
-
948
- /**
949
- * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
950
- *
951
- * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.
952
- *
953
- * @since BuddyPress (1.2)
954
- *
955
- * @deprecated 1.5
956
- * @deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead.
957
- *
958
- * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve
959
- * @param int $max Maximum number of results to return. (Optional; default is no maximum)
960
- * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1)
961
- * @param int $per_page Specifies how many results per page. Used in pagination. (Optional; default is 25)
962
- * @param string MySQL column sort; ASC or DESC. (Optional; default is DESC)
963
- * @param bool $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false)
964
- * @return array
965
- */
966
- public static function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
967
- _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get() with the "in" parameter instead.' );
968
- return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
969
- }
970
-
971
- /**
972
- * Get the first activity ID that matches a set of criteria.
973
- *
974
- * @param int $user_id User ID to filter by
975
- * @param string $component Component to filter by
976
- * @param string $type Activity type to filter by
977
- * @param int $item_id Associated item to filter by
978
- * @param int $secondary_item_id Secondary associated item to filter by
979
- * @param string $action Action to filter by
980
- * @param string $content Content to filter by
981
- * @param string $date_recorded Date to filter by
982
- *
983
- * @todo Should parameters be optional?
984
- *
985
- * @return int|bool Activity ID on success, false if none is found.
986
- */
987
- public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
988
- global $wpdb;
989
-
990
- $bp = buddypress();
991
-
992
- $where_args = false;
993
-
994
- if ( ! empty( $user_id ) ) {
995
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
996
- }
997
-
998
- if ( ! empty( $component ) ) {
999
- $where_args[] = $wpdb->prepare( "component = %s", $component );
1000
- }
1001
-
1002
- if ( ! empty( $type ) ) {
1003
- $where_args[] = $wpdb->prepare( "type = %s", $type );
1004
- }
1005
-
1006
- if ( ! empty( $item_id ) ) {
1007
- $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
1008
- }
1009
-
1010
- if ( ! empty( $secondary_item_id ) ) {
1011
- $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
1012
- }
1013
-
1014
- if ( ! empty( $action ) ) {
1015
- $where_args[] = $wpdb->prepare( "action = %s", $action );
1016
- }
1017
-
1018
- if ( ! empty( $content ) ) {
1019
- $where_args[] = $wpdb->prepare( "content = %s", $content );
1020
- }
1021
-
1022
- if ( ! empty( $date_recorded ) ) {
1023
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
1024
- }
1025
-
1026
- if ( ! empty( $where_args ) ) {
1027
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
1028
- return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
1029
- }
1030
-
1031
- return false;
1032
- }
1033
-
1034
- /**
1035
- * Delete activity items from the database.
1036
- *
1037
- * To delete a specific activity item, pass an 'id' parameter.
1038
- * Otherwise use the filters.
1039
- *
1040
- * @since BuddyPress (1.2)
1041
- *
1042
- * @param array $args {
1043
- * @int $id Optional. The ID of a specific item to delete.
1044
- * @string $action Optional. The action to filter by.
1045
- * @string $content Optional. The content to filter by.
1046
- * @string $component Optional. The component name to filter by.
1047
- * @string $type Optional. The activity type to filter by.
1048
- * @string $primary_link Optional. The primary URL to filter by.
1049
- * @int $user_id Optional. The user ID to filter by.
1050
- * @int $item_id Optional. The associated item ID to filter by.
1051
- * @int $secondary_item_id Optional. The secondary associated item ID to filter by.
1052
- * @string $date_recorded Optional. The date to filter by.
1053
- * @int $hide_sitewide Optional. Default: false.
1054
- * }
1055
- * @return array|bool An array of deleted activity IDs on success, false on failure.
1056
- */
1057
- public static function delete( $args = array() ) {
1058
- global $wpdb;
1059
-
1060
- $bp = buddypress();
1061
-
1062
- $defaults = array(
1063
- 'id' => false,
1064
- 'action' => false,
1065
- 'content' => false,
1066
- 'component' => false,
1067
- 'type' => false,
1068
- 'primary_link' => false,
1069
- 'user_id' => false,
1070
- 'item_id' => false,
1071
- 'secondary_item_id' => false,
1072
- 'date_recorded' => false,
1073
- 'hide_sitewide' => false
1074
- );
1075
- $params = wp_parse_args( $args, $defaults );
1076
- extract( $params );
1077
-
1078
- $where_args = false;
1079
-
1080
- if ( !empty( $id ) )
1081
- $where_args[] = $wpdb->prepare( "id = %d", $id );
1082
-
1083
- if ( !empty( $user_id ) )
1084
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
1085
-
1086
- if ( !empty( $action ) )
1087
- $where_args[] = $wpdb->prepare( "action = %s", $action );
1088
-
1089
- if ( !empty( $content ) )
1090
- $where_args[] = $wpdb->prepare( "content = %s", $content );
1091
-
1092
- if ( !empty( $component ) )
1093
- $where_args[] = $wpdb->prepare( "component = %s", $component );
1094
-
1095
- if ( !empty( $type ) )
1096
- $where_args[] = $wpdb->prepare( "type = %s", $type );
1097
-
1098
- if ( !empty( $primary_link ) )
1099
- $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
1100
-
1101
- if ( !empty( $item_id ) )
1102
- $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
1103
-
1104
- if ( !empty( $secondary_item_id ) )
1105
- $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
1106
-
1107
- if ( !empty( $date_recorded ) )
1108
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
1109
-
1110
- if ( !empty( $hide_sitewide ) )
1111
- $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
1112
-
1113
- if ( !empty( $where_args ) )
1114
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
1115
- else
1116
- return false;
1117
-
1118
- // Fetch the activity IDs so we can delete any comments for this activity item
1119
- $activity_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
1120
-
1121
- if ( ! $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) {
1122
- return false;
1123
- }
1124
-
1125
- // Handle accompanying activity comments and meta deletion
1126
- if ( $activity_ids ) {
1127
- $activity_ids_comma = implode( ',', wp_parse_id_list( $activity_ids ) );
1128
- $activity_comments_where_sql = "WHERE type = 'activity_comment' AND item_id IN ({$activity_ids_comma})";
1129
-
1130
- // Fetch the activity comment IDs for our deleted activity items
1131
- $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$activity_comments_where_sql}" );
1132
-
1133
- // We have activity comments!
1134
- if ( ! empty( $activity_comment_ids ) ) {
1135
- // Delete activity comments
1136
- $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$activity_comments_where_sql}" );
1137
-
1138
- // Merge activity IDs with activity comment IDs
1139
- $activity_ids = array_merge( $activity_ids, $activity_comment_ids );
1140
- }
1141
-
1142
- // Delete all activity meta entries for activity items and activity comments
1143
- BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
1144
- }
1145
-
1146
- return $activity_ids;
1147
- }
1148
-
1149
- /**
1150
- * Delete the comments associated with a set of activity items.
1151
- *
1152
- * @since BuddyPress (1.2)
1153
- *
1154
- * @todo Mark as deprecated? Method is no longer used internally.
1155
- *
1156
- * @param array $activity_ids Activity IDs whose comments should be deleted.
1157
- * @param bool $delete_meta Should we delete the activity meta items for these comments?
1158
- * @return bool True on success.
1159
- */
1160
- public static function delete_activity_item_comments( $activity_ids = array(), $delete_meta = true ) {
1161
- global $wpdb;
1162
-
1163
- $bp = buddypress();
1164
-
1165
- $delete_meta = (bool) $delete_meta;
1166
- $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );
1167
-
1168
- if ( $delete_meta ) {
1169
- // Fetch the activity comment IDs for our deleted activity items
1170
- $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
1171
-
1172
- if ( ! empty( $activity_comment_ids ) ) {
1173
- self::delete_activity_meta_entries( $activity_comment_ids );
1174
- }
1175
- }
1176
-
1177
- return $wpdb->query( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
1178
- }
1179
-
1180
- /**
1181
- * Delete the meta entries associated with a set of activity items.
1182
- *
1183
- * @since BuddyPress (1.2)
1184
- *
1185
- * @param array $activity_ids Activity IDs whose meta should be deleted.
1186
- * @return bool True on success.
1187
- */
1188
- public static function delete_activity_meta_entries( $activity_ids = array() ) {
1189
- $activity_ids = wp_parse_id_list( $activity_ids );
1190
-
1191
- foreach ( $activity_ids as $activity_id ) {
1192
- bp_activity_delete_meta( $activity_id );
1193
- }
1194
-
1195
- return true;
1196
- }
1197
-
1198
- /**
1199
- * Append activity comments to their associated activity items.
1200
- *
1201
- * @since BuddyPress (1.2)
1202
- *
1203
- * @global wpdb $wpdb WordPress database object
1204
- *
1205
- * @param array $activities Activities to fetch comments for.
1206
- * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'.
1207
- * @return array The updated activities with nested comments.
1208
- */
1209
- public static function append_comments( $activities, $spam = 'ham_only' ) {
1210
- $activity_comments = array();
1211
-
1212
- // Now fetch the activity comments and parse them into the correct position in the activities array.
1213
- foreach ( (array) $activities as $activity ) {
1214
- $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;
1215
- $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id );
1216
- }
1217
-
1218
- // Merge the comments with the activity items
1219
- foreach ( (array) $activities as $key => $activity ) {
1220
- if ( isset( $activity_comments[$activity->id] ) ) {
1221
- $activities[$key]->children = $activity_comments[$activity->id];
1222
- }
1223
- }
1224
-
1225
- return $activities;
1226
- }
1227
-
1228
- /**
1229
- * Get activity comments that are associated with a specific activity ID.
1230
- *
1231
- * @since BuddyPress (1.2)
1232
- *
1233
- * @global wpdb $wpdb WordPress database object.
1234
- *
1235
- * @param int $activity_id Activity ID to fetch comments for.
1236
- * @param int $left Left-most node boundary.
1237
- * @param into $right Right-most node boundary.
1238